/**
  * {@inheritdoc}
  */
 public function prepareRules(IFilter $objFilter, $arrFilterUrl)
 {
     $objMetaModel = $this->getMetaModel();
     $objAttribute = $objMetaModel->getAttributeById($this->get('attr_id'));
     $strParam = $this->getParamName();
     if ($objAttribute && $strParam) {
         $arrFilterValue = $arrFilterUrl[$strParam];
         if ($arrFilterValue && is_array($arrFilterValue)) {
             if (count($arrFilterValue) > 1) {
                 $objParentRule = new ConditionOr();
                 foreach ($arrFilterValue as $strValue) {
                     $objSubFilter = new Filter($objMetaModel);
                     $objSubFilter->addFilterRule(new SearchAttribute($objAttribute, $strValue));
                     $objParentRule->addChild($objSubFilter);
                 }
                 $objFilter->addFilterRule($objParentRule);
                 return;
             } else {
                 $objFilter->addFilterRule(new SearchAttribute($objAttribute, $arrFilterValue));
                 return;
             }
         }
     }
 }
Beispiel #2
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));
 }