root/trunk/lib/model/ApplicationPeer.php

Revision 62, 4.4 kB (checked in by nperriault, 4 months ago)

[1.1] added es translation + advance in forms migration

Line 
1 <?php
2 /**
3  * Subclass for performing query and update operations on the 'applications' table.
4  *
5  * @package lib.model
6  */
7 class ApplicationPeer extends BaseApplicationPeer
8 {
9
10   /**
11    * Applications countries
12    * @var array
13    */
14   protected static $countries = null;
15
16   /**
17    * Selects and returns apps and related members whenever then do not exist in
18    * database anymore
19    *
20    * @param  Criteria $c
21    * @param  mixed    $con
22    * @return array
23    */
24   public static function doSelectLeftJoinsfGuardUser(Criteria $c, $con = null)
25   {
26     $c = clone $c;
27     if ($c->getDbName() == Propel::getDefaultDB())
28     {
29       $c->setDbName(self::DATABASE_NAME);
30     }
31     ApplicationPeer::addSelectColumns($c);
32     $startcol = (ApplicationPeer::NUM_COLUMNS - ApplicationPeer::NUM_LAZY_LOAD_COLUMNS) + 1;
33     sfGuardUserPeer::addSelectColumns($c);
34     $c->addJoin(ApplicationPeer::SUBMITTER_ID, sfGuardUserPeer::ID, Criteria::LEFT_JOIN);
35     $rs = BasePeer::doSelect($c, $con);
36     $results = array();
37     while($rs->next())
38     {
39       $omClass = ApplicationPeer::getOMClass();
40       $cls = Propel::import($omClass);
41       $obj1 = new $cls();
42       $obj1->hydrate($rs);
43       $omClass = sfGuardUserPeer::getOMClass();
44       $cls = Propel::import($omClass);
45       $obj2 = new $cls();
46       $obj2->hydrate($rs, $startcol);
47       $newObject = true;
48       foreach($results as $temp_obj1)
49       {
50         $temp_obj2 = $temp_obj1->getsfGuardUser();
51         if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey())
52         {
53           $newObject = false;
54           $temp_obj2->addApplication($obj1);
55           break;
56         }
57       }
58       if ($newObject)
59       {
60         $obj2->initApplications();
61         $obj2->addApplication($obj1);
62       }
63       $results[] = $obj1;
64     }
65     return $results;
66   }
67  
68   /**
69    * Get recent applications
70    *
71    * @param int      $number  (default 10)
72    * @param Criteria $c
73    * @return array
74    */
75   public static function getRecent($number = 10, Criteria $c = null)
76   {
77     if (!$c instanceof Critreria)
78     {
79       $c = new Criteria;
80     }
81     $c->addDescendingOrderByColumn(self::CREATED_AT);
82     $c->setLimit($number);
83     return self::doSelect($c);
84   }
85
86   /**
87    * Retrieves an Application by its slug
88    *
89    * @param string $slug
90    * @param string $peer_method
91    * @return Application
92    */
93   public static function retrieveBySlug($slug, $peer_method = null)
94   {
95     $c = new Criteria();
96     $c->add(self::SLUG, $slug);
97     if ($peer_method)
98     {
99       if (!is_callable(sprintf('%s::%s', __CLASS__, $peer_method)))
100       {
101         throw new PropelException(sprintf('Peer method "%s" does not exist',
102                                           $peer_method));
103       }
104       $c->setLimit(1);
105       $objects = call_user_func(array(__CLASS__, $peer_method), $c);
106       if (!is_null($objects) && isset($objects[0]))
107       {
108         return $objects[0];
109       }
110       else
111       {
112         return null;
113       }
114     }
115     else
116     {
117       return self::doSelectOne($c);
118     }
119   }
120
121   /**
122    * Retrieves all application countries
123    *
124    * @param boolean $reload
125    * @return array
126    */
127   public static function retrieveCountries($reload = false)
128   {
129     if (is_null(self::$countries) or $reload)
130     {
131       sfLoader::loadHelpers('I18N');
132       $countries = array();
133       $c = new Criteria();
134       $c->clearSelectColumns();
135       $c->addSelectColumn(self::COUNTRY);
136       $c->add(self::COUNTRY, null, Criteria::ISNOTNULL);
137       $c->addGroupByColumn(self::COUNTRY);
138       $c->addAscendingOrderByColumn(self::COUNTRY);
139       $rs = self::doSelectRS($c);
140       while ($rs->next())
141       {
142         if ($rs->getString(1) != '')
143         {
144           $countries[$rs->getString(1)] = format_country($rs->getString(1));
145         }
146       }
147       asort($countries);
148       self::$countries = $countries;
149     }
150     return self::$countries;
151   }
152
153   /**
154    * Retrieves all countries and application counts
155    *
156    * @return array
157    */
158   public static function retrieveCountriesWithCount()
159   {
160     $c = new Criteria();
161     $c->clearSelectColumns();
162     $c->addSelectColumn(self::COUNTRY);
163     $c->add(self::COUNTRY, null, Criteria::ISNOTNULL);
164     $c->addAsColumn('nb', 'COUNT('.self::ID.')');
165     $c->addGroupByColumn(self::COUNTRY);
166     $c->addAscendingOrderByColumn(self::COUNTRY);
167     $rs = self::doSelectRS($c);
168     while ($rs->next())
169     {
170       if ($rs->getString(1) != '')
171       {
172         $countries[$rs->getString(1)] = $rs->getInt(2);
173       }
174     }
175     arsort($countries);
176     return $countries;
177   }
178
179 }
180
Note: See TracBrowser for help on using the browser.