root/trunk/lib/model/PluginsfGuardUserPeer.php

Revision 23, 3.4 kB (checked in by nperriault, 10 months ago)

Restored correct sfGuard overridden models class and file names.

Line 
1 <?php
2 /*
3  * This file is part of the symfony package.
4  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
5  *
6  * For the full copyright and license information, please view the LICENSE
7  * file that was distributed with this source code.
8  */
9
10 /**
11  *
12  * @package    symfony
13  * @subpackage plugin
14  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
15  * @version    SVN: $Id: sfGuardUserPeer.php 3810 2007-04-17 19:37:51Z davedash $
16  */
17 class PluginsfGuardUserPeer extends BasesfGuardUserPeer
18 {
19
20   /**
21    * Users countries
22    * @var array
23    */
24   protected static $countries = null;
25
26   /**
27    * Get recent users
28    *
29    * @param int      $number  (default 10)
30    * @param Criteria $c
31    * @return array
32    */
33   public static function getRecent($number = 10, Criteria $c = null)
34   {
35     if (!$c instanceof Critreria)
36     {
37       $c = new Criteria;
38     }
39
40     $c->add(self::IS_ACTIVE, true);
41     $c->addDescendingOrderByColumn(self::CREATED_AT);
42     $c->setLimit($number);
43     return self::doSelect($c);
44   }
45
46   public static function retrieveByEmail($email)
47   {
48     $c = new Criteria;
49     $c->add(self::EMAIL, $email);
50     return self::doSelectOne($c);
51   }
52
53   public static function retrieveByUsername($username, $isActive = true, $peer_method = null)
54   {
55     $c = new Criteria();
56     $c->add(self::USERNAME, $username);
57     $c->add(self::IS_ACTIVE, $isActive);
58     if ($peer_method)
59     {
60       if (!is_callable(sprintf('%s::%s', __CLASS__, $peer_method)))
61       {
62         throw new PropelException(sprintf('Peer method "%s" does not exist',
63                                           $peer_method));
64       }
65       $c->setLimit(1);
66       $objects = call_user_func(array(__CLASS__, $peer_method), $c);
67       if (!is_null($objects) && isset($objects[0]))
68       {
69         return $objects[0];
70       }
71       else
72       {
73         return null;
74       }
75     }
76     else
77     {
78       return self::doSelectOne($c);
79     }
80   }
81
82   /**
83    * Retrieves people countries
84    *
85    * @param  boolean $reload
86    * @return array
87    */
88   public static function retrieveCountries($reload = false)
89   {
90     if (is_null(self::$countries) or $reload)
91     {
92       sfLoader::loadHelpers('I18N');
93       $countries = array();
94       $c = new Criteria();
95       $c->clearSelectColumns();
96       $c->addSelectColumn(self::COUNTRY);
97       $c->add(self::IS_ACTIVE, true);
98       $c->addGroupByColumn(self::COUNTRY);
99       $c->addAscendingOrderByColumn(self::COUNTRY);
100       $rs = self::doSelectRS($c);
101       while ($rs->next())
102       {
103         if ($rs->getString(1) != '')
104         {
105           $countries[$rs->getString(1)] = format_country($rs->getString(1));
106         }
107       }
108       asort($countries);
109       self::$countries = $countries;
110     }
111     return self::$countries;
112   }
113
114   /**
115    * Retrieves people cities for a given country
116    *
117    * @param  string $country_code
118    * @return array
119    */
120   public static function retrieveCountryCities($country_code)
121   {
122     $cities = array();
123     $c = new Criteria();
124     $c->clearSelectColumns();
125     $c->addSelectColumn(self::CITY);
126     $c->add(self::COUNTRY, $country_code);
127     $c->add(self::IS_ACTIVE, true);
128     $c->addGroupByColumn(self::CITY);
129     $c->addAscendingOrderByColumn(self::CITY);
130     $rs = self::doSelectRS($c);
131     while ($rs->next())
132     {
133       if ($rs->getString(1) != '')
134       {
135         $cities[$rs->getString(1)] = $rs->getString(1);
136       }
137     }
138     asort($cities);
139     return $cities;
140   }
141
142 }
143
Note: See TracBrowser for help on using the browser.