Exemplo n.º 1
0
 public function __construct(DataObjectCollection $collection, $use_session = TRUE, $use_system_company = TRUE, $search_id = '')
 {
     $tablename = $collection->getViewName();
     $this->tablename = $tablename;
     $this->use_session = $use_session;
     $this->search_id = $search_id;
     $this->constraints = new ConstraintChain();
     $this->use_system_company = $use_system_company;
     $this->setOrderby($collection->orderby, $collection->direction);
     if (strpos($tablename, ' ')) {
         $this->tablename = substr($tablename, strrpos($tablename, ' ') + 1);
     }
     $cache_id = array('searches', EGS_USERNAME, $this->tablename . '_' . $this->search_id);
     $cache = Cache::Instance();
     $cached_search = $cache->get($cache_id, 1800);
     if ($this->use_session && $cached_search !== FALSE) {
         foreach ($cached_search as $key => $val) {
             if ($key == 'constraints' || $key == 'fields') {
                 $this->{$key} = unserialize($val);
             } else {
                 $this->{$key} = $val;
             }
         }
         debug('SearchHandler::__construct ' . $tablename . ' ' . print_r($this, TRUE));
         //			echo 'SearchHandler::__construct<pre>'.print_r($this, true).'</pre>';
     } elseif ($this->use_system_company) {
         //if usercompanyid is a field, then it's always a constraint
         // TODO: Need to revisit this;
         //       gets added in DataObject(?)/DataObjectCollection(?)
         //       if the search is access controlled
         $model = $collection->getModel();
         if ($model->isField('usercompanyid')) {
             $this->constraints = new ConstraintChain();
             $this->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
         }
     }
     $this->collection = $collection;
 }