Example #1
0
 /**
  * Create a Search Query
  * 
  * @param Request $request
  * @param Config $config
  */
 public function __construct(Request $request = null, Config $config = null)
 {
     // registry
     $this->registry = Registry::getInstance();
     if ($config != null) {
         // config
         $this->config = $config;
         // defaults set in config(s)
         $this->max = $this->registry->getConfig("RECORDS_PER_PAGE", false, $this->max);
         $this->max = $this->config->getConfig("RECORDS_PER_PAGE", false, $this->max);
         $this->max_allowed = $this->registry->getConfig("MAX_RECORDS_PER_PAGE", false, $this->max_allowed);
         $this->max_allowed = $this->config->getConfig("MAX_RECORDS_PER_PAGE", false, $this->max_allowed);
         $this->sort = $this->registry->getConfig("SORT_ORDER", false, $this->sort);
         $this->sort = $this->config->getConfig("SORT_ORDER", false, $this->sort);
     }
     // xerxes request
     if ($request != null) {
         // make these available
         $this->request = $request;
         // populate it with the 'search' related params out of the url
         foreach ($this->extractSearchGroupings() as $term) {
             $this->addTerm($term["id"], $term["boolean"], $term["field"], $term["relation"], $term["query"]);
         }
         // also limits
         foreach ($this->extractLimitGroupings() as $limit) {
             $this->addLimit($limit["boolean"], $limit["field"], $limit["relation"], $limit["value"]);
         }
         // start, max, sort
         $this->start = $this->request->getParam('start', 1);
         $this->max = $this->request->getParam('max', $this->max);
         $this->sort = $this->request->getParam('sort', $this->sort);
         // store the original (public) sort as the sort_id,
         // we'll take sort as the (internal) sort
         $this->sort_id = $this->sort;
         // swap for internal
         if ($this->config != null) {
             $this->sort = $this->config->swapForInternalSort($this->sort);
         }
         // make sure records per page does not exceed upper bound
         if ($this->max > $this->max_allowed) {
             $this->max = $this->max_allowed;
         }
     }
 }