Esempio n. 1
0
 /**
  * get search params for given request params
  * @param  array &$rp
  * @return array
  */
 protected function getSearchParams(&$rp)
 {
     $rez = array();
     // creating search object
     $so = new \CB\Objects\Object();
     if (!empty($rp['search']['template_id'])) {
         // searching from a search form
         $so->setData($rp['search']);
     } else {
         // should/will be reviewed for saved searches
         $searchId = $this->lastNode->id;
         if (!empty($rp['search']['id']) && is_numeric($rp['search']['id'])) {
             $searchId = $rp['search']['id'];
         }
         // executing a saved search
         $so->load($searchId);
     }
     $t = $so->getTemplate();
     $td = $t->getData();
     // if we have a router defined in config of the search template then try to prepare search params wit it
     // otherwise use default search method
     // if (empty($td['cfg']['router'])) {
     $rez = $t->getData()['cfg'];
     @($rez['template_id'] = $so->getData()['template_id']);
     if (empty($rez['fq'])) {
         $rez['fq'] = array();
     }
     $ld = $so->getLinearData();
     foreach ($ld as $v) {
         $condition = $this->adjustCondition($t->getField($v['name']), $v);
         if (!empty($condition)) {
             $rez['fq'][] = $condition;
         }
     }
     // } else {
     if (!empty($td['cfg']['router'])) {
         $a = explode('.', $td['cfg']['router']);
         $class = str_replace('_', '\\', $a[0]);
         $class = new $class();
         $rez = $class->{$a[1]}($rp, $rez);
     }
     return $rez;
 }