Inheritance: extends MetaModels\Filter\FilterRule
Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function prepareRules(IFilter $objFilter, $arrFilterUrl)
 {
     $objSubFilter = new Filter($this->getMetaModel());
     foreach ($this->arrChildren as $objChildSetting) {
         $objChildSetting->prepareRules($objSubFilter, $arrFilterUrl);
     }
     $objFilterRule = new FilterRuleAnd();
     $objFilterRule->addChild($objSubFilter);
     $objFilter->addFilterRule($objFilterRule);
 }
Beispiel #2
0
 /**
  * Do a complex search with each word. Search for all words or for any word.
  *
  * @param string   $strTextSearch The mode any or all.
  *
  * @param IFilter  $objFilter     The filter to append the rules to.
  *
  * @param string[] $arrFilterUrl  The parameters to evaluate.
  *
  * @return void
  */
 private function doComplexSearch($strTextSearch, $objFilter, $arrFilterUrl)
 {
     $objMetaModel = $this->getMetaModel();
     $objAttribute = $objMetaModel->getAttributeById($this->get('attr_id'));
     $strParamName = $this->getParamName();
     $strParamValue = $arrFilterUrl[$strParamName];
     $parentFilter = null;
     $words = array();
     // Type of search.
     switch ($strTextSearch) {
         case 'any':
             $words = $this->getWords($strParamValue);
             $parentFilter = new ConditionOr();
             break;
         case 'all':
             $words = $this->getWords($strParamValue);
             $parentFilter = new ConditionAnd();
             break;
         default:
             // Do nothing. Because the parent function saved us. The value have to be any or all.
             break;
     }
     if ($objAttribute && $strParamName && $strParamValue && $parentFilter) {
         foreach ($words as $word) {
             $subFilter = $objMetaModel->getEmptyFilter();
             $subFilter->addFilterRule(new SearchAttribute($objAttribute, '%' . $word . '%'));
             $parentFilter->addChild($subFilter);
         }
         $objFilter->addFilterRule($parentFilter);
         return;
     }
     $objFilter->addFilterRule(new StaticIdList(null));
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function prepareRules(IFilter $objFilter, $arrFilterUrl)
 {
     $objMetaModel = $this->getMetaModel();
     $objAttribute = $objMetaModel->getAttributeById($this->get('attr_id'));
     $strParamName = $this->getParamName();
     $arrParamValue = $this->buildParamValue($arrFilterUrl, $strParamName);
     $arrOptions = $this->getParameterFilterOptions($objAttribute, null);
     $arrParamValue = $this->filterParamValue($arrParamValue, $arrOptions);
     if ($objAttribute && $strParamName && is_array($arrParamValue) && $arrOptions) {
         // Determine which parenting rule to use, AND or OR.
         if ($this->get('useor')) {
             $objParentRule = new ConditionOr();
         } else {
             $objParentRule = new ConditionAnd();
         }
         // We allow the current and the fallback language to be searched by default.
         $arrValidLanguages = array($this->getMetaModel()->getActiveLanguage(), $this->getMetaModel()->getFallbackLanguage());
         foreach ($arrParamValue as $strParamValue) {
             // Restrict to valid options for obvious reasons.
             if (array_key_exists($strParamValue, $arrOptions)) {
                 $objSubFilter = new Filter($objMetaModel);
                 $objSubFilter->addFilterRule(new SearchAttribute($objAttribute, $strParamValue, $arrValidLanguages));
                 $objParentRule->addChild($objSubFilter);
             }
         }
         $objFilter->addFilterRule($objParentRule);
         return;
     }
     // If no setting has been defined, we appear transparently as "not defined" and return all items.
     $objFilter->addFilterRule(new StaticIdList(null));
 }
Beispiel #4
0
 /**
  * Method to optimize as many system column lookup filters as possible into a combined filter rule.
  *
  * @param ConditionAnd|ConditionOr $filterRule The filter to which the optimized rule shall be added to.
  *
  * @param array                    $children   The children to parse.
  *
  * @param string                   $operation  The operation to parse (AND or OR).
  *
  * @return array
  */
 protected function optimizedFilter($filterRule, $children, $operation)
 {
     $procedure = new FilterBuilderSql($this->getMetaModel()->getTableName(), $operation, $this->getDatabase());
     $skipped = $this->buildNativeSqlProcedure($procedure, $children);
     if (!$procedure->isEmpty()) {
         $filterRule->addChild($this->getMetaModel()->getEmptyFilter()->addFilterRule($procedure->build()));
     }
     return $skipped;
 }