Advertisement
Guest User

SearchCriteriaExample

a guest
Oct 4th, 2010
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. class Location_RecordSearchCriteria extends SearchCriteria {
  2.     const NONE = -1;
  3.    
  4.     function __construct() {
  5.         parent::__construct(
  6.             array('Id', 'Country', 'State', 'City'),
  7.             array('Id', 'Rand'));
  8.         $this->setState(self::NONE);
  9.         $this->setCity(self::NONE);
  10.         $this->orderById();
  11.     }
  12. }
  13.  
  14.  
  15. // ------------------------------
  16.     protected function prepareFilters(array& $where, array& $binds,
  17.         SearchCriteria $criteria)
  18.     {
  19.         if ( sizeof($list = $criteria->getId()) > 0 ) {
  20.             $where[] = 'id IN (?' . str_repeat(',?', sizeof($list) - 1) . ')';
  21.             $binds = array_merge($binds, $list);
  22.         }
  23.         if ( sizeof($list = $criteria->getCountry()) > 0 ) {
  24.             for ( $i = 0; $i < sizeof($list); $i ++ ) {
  25.                 if ( is_object($list[$i]) ) {
  26.                     $list[$i] = $list[$i]->getId();
  27.                 }
  28.             }
  29.             $where[] = 'country IN (?' .str_repeat(',?',sizeof($list)-1).')';
  30.             $binds = array_merge($binds, $list);
  31.         }
  32.         if ( is_object($criteria->get1State())
  33.             || $criteria->get1State() != Location_RecordSearchCriteria::NONE )
  34.         {
  35.             $this->complexListFilter($where, $binds, 'state',
  36.                 $criteria->getState());
  37.         }
  38.         if ( is_object($criteria->get1City())
  39.             || $criteria->get1City() != Location_RecordSearchCriteria::NONE )
  40.         {
  41.             $this->complexListFilter($where,$binds,'city',$criteria->getCity());
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement