root/trunk/lib/model/CompanyPeer.php

Revision 2, 2.0 kB (checked in by nperriault, 10 months ago)

First commit of the extracted code from production, I hope no passwd has been forgotten :-)

Line 
1 <?php
2 /**
3  * Subclass for performing query and update operations on the 'company' table.
4  *
5  * @package lib.model
6  */
7 class CompanyPeer extends BaseCompanyPeer
8 {
9
10   protected static $countries = null;
11  
12   /**
13    * Get recent companies
14    *
15    * @param int      $number  (default 10)
16    * @param Criteria $c
17    * @return array
18    */
19   public static function getRecent($number = 10, Criteria $c = null)
20   {
21     if (!$c instanceof Critreria)
22     {
23       $c = new Criteria;
24     }
25     $c->add(self::IS_ACTIVE, true);
26     $c->addDescendingOrderByColumn(self::CREATED_AT);
27     $c->setLimit($number);
28     return self::doSelect($c);
29   }
30  
31   public static function retrieveBySlug($slug, $peer_method = null)
32   {
33     $c = new Criteria();
34     $c->add(self::SLUG, $slug);
35     if ($peer_method)
36     {
37       if (!is_callable(sprintf('%s::%s', __CLASS__, $peer_method)))
38       {
39         throw new PropelException(sprintf('Peer method "%s" does not exist',
40                                           $peer_method));
41       }
42       $c->setLimit(1);
43       $objects = call_user_func(array(__CLASS__, $peer_method), $c);
44       if (!is_null($objects) && isset($objects[0]))
45       {
46         return $objects[0];
47       }
48       else
49       {
50         return null;
51       }
52     }
53     else
54     {
55       return self::doSelectOne($c);
56     }
57   }
58
59   public static function retrieveCountries($reload = false)
60   {
61     if (is_null(self::$countries) or $reload)
62     {
63       sfLoader::loadHelpers('I18N');
64       $countries = array();
65       $c = new Criteria();
66       $c->clearSelectColumns();
67       $c->addSelectColumn(self::COUNTRY);
68       $c->add(self::COUNTRY, null, Criteria::ISNOTNULL);
69       $c->addGroupByColumn(self::COUNTRY);
70       $c->addAscendingOrderByColumn(self::COUNTRY);
71       $rs = self::doSelectRS($c);
72       while ($rs->next())
73       {
74         if ($rs->getString(1) != '')
75         {
76           $countries[$rs->getString(1)] = format_country($rs->getString(1));
77         }
78       }
79       asort($countries);
80       self::$countries = $countries;
81     }
82     return self::$countries;
83   }
84
85 }
86
Note: See TracBrowser for help on using the browser.