Exemplo n.º 1
0
 /**
  * instantiate an metamodel attribute.
  * Note that you should not use this directly but use the factory classes to instantiate attributes.
  *
  * @param IMetaModel $objMetaModel the IMetaModel instance this attribute belongs to.
  *
  * @param array $arrData the information array, for attribute information, refer to documentation of table tl_metamodel_attribute
  *                       and documentation of the certain attribute classes for information what values are understood.
  */
 public function __construct(IMetaModel $objMetaModel, $arrData = array())
 {
     // meta information
     foreach ($this->getAttributeSettingNames() as $strSettingName) {
         if (isset($arrData[$strSettingName])) {
             $this->set($strSettingName, $arrData[$strSettingName]);
         }
     }
     $this->strMetaModel = $objMetaModel->getTableName();
 }
 /**
  * translates an generated alias {@see TableMetaModelFilterSetting::getAttributeNames()}
  * to the corresponding attribute id.
  *
  * @param string        $strValue the id to translate.
  *
  * @param DataContainer $objDC    the data container calling.
  *
  * @return int
  */
 public function nameToAttrId($strValue, $objDC)
 {
     $this->objectsFromUrl($objDC);
     if (!$this->objMetaModel) {
         return 0;
     }
     $strName = str_replace($this->objMetaModel->getTableName() . '_', '', $strValue);
     $objAttribute = $this->objMetaModel->getAttribute($strName);
     if (!$objAttribute) {
         return 0;
     }
     return $objAttribute->get('id');
 }
 /**
  * Combine a filter in standard filter array notation.
  * Supported operations are:
  * operation      needed arguments     argument type.
  * AND
  *                'childs'             array
  * OR
  *                'childs'             array
  * =
  *                'property'           string (the name of a property)
  *                'value'              literal
  * >
  *                'property'           string (the name of a property)
  *                'value'              literal
  * <
  *                'property'           string (the name of a property)
  *                'value'              literal
  * IN
  *                'property'           string (the name of a property)
  *                'values'             array of literal
  *
  * @param array            $arrFilter The filter to be combined into the passed filter object.
  *
  * @param IMetaModelFilter $objFilter The filter object where the rules shall get appended to.
  *
  * @return void.
  *
  * @throws Exception When an improper filter condition is encountered, an exception is thrown.
  */
 protected function calculateSubfilter($arrFilter, IMetaModelFilter $objFilter)
 {
     if (!is_array($arrFilter)) {
         throw new Exception('Error Processing subfilter: ' . var_export($arrFilter, true), 1);
     }
     $objAttribute = null;
     if ($arrFilter['property']) {
         $objAttribute = $this->objMetaModel->getAttribute($arrFilter['property']);
     }
     switch ($arrFilter['operation']) {
         case 'AND':
         case 'OR':
             if ($arrFilter['operation'] == 'AND') {
                 $objFilterRule = new MetaModelFilterRuleAND();
             } else {
                 $objFilterRule = new MetaModelFilterRuleOR();
             }
             $objFilter->addFilterRule($objFilterRule);
             $objSubFilter = new MetaModelFilter($this->objMetaModel);
             $objFilterRule->addChild($objSubFilter);
             foreach ($arrFilter['childs'] as $arrChild) {
                 $this->calculateSubfilter($arrChild, $objSubFilter);
             }
             break;
         case '=':
         case '>':
         case '<':
             $objFilterRule = null;
             if ($objAttribute) {
                 switch ($arrFilter['operation']) {
                     case '=':
                         $objFilterRule = new MetaModelFilterRuleSearchAttribute($objAttribute, $arrFilter['value'], $this->objMetaModel->getAvailableLanguages());
                         break;
                     case '>':
                         $objFilterRule = new MetaModelFilterRuleFilterAttributeGreaterThan($objAttribute, $arrFilter['value']);
                         break;
                     case '<':
                         $objFilterRule = new MetaModelFilterRuleFilterAttributeLessThan($objAttribute, $arrFilter['value']);
                         break;
                 }
             } else {
                 if (Database::getInstance()->fieldExists($arrFilter['property'], $this->objMetaModel->getTableName())) {
                     // system column?
                     $objFilterRule = new MetaModelFilterRuleSimpleQuery(sprintf('SELECT id FROM %s WHERE %s %s %s', $this->objMetaModel->getTableName(), $arrFilter['property'], $arrFilter['operation'], $arrFilter['value']));
                 }
             }
             if (!$objFilterRule) {
                 throw new Exception('Error processing filter array - unknown property ' . var_export($arrFilter['property'], true), 1);
             }
             $objFilter->addFilterRule($objFilterRule);
             break;
         case 'IN':
             // rewrite the IN operation to a rephrased term: "(x=a) OR (x=b) OR ..."
             $arrSubRules = array();
             foreach ($arrFilter['value'] as $varValue) {
                 $arrSubRules[] = array('property' => $arrFilter['property'], 'operation' => '=', 'value' => $varValue);
             }
             $this->calculateSubfilter(array('operation' => 'OR', 'childs' => $arrSubRules), $objFilter);
             break;
         case 'LIKE':
             $objFilterRule = null;
             if ($objAttribute) {
                 $objFilterRule = new MetaModelFilterRuleSearchAttribute($objAttribute, $arrFilter['value'], $this->objMetaModel->getAvailableLanguages());
             } else {
                 if (Database::getInstance()->fieldExists($arrFilter['property'], $this->objMetaModel->getTableName())) {
                     // system column?
                     $objFilterRule = new MetaModelFilterRuleSimpleQuery(sprintf('SELECT id FROM %s WHERE %s LIKE ?', $this->objMetaModel->getTableName(), $arrFilter['property']), array($arrFilter['value']));
                 }
             }
             if (!$objFilterRule) {
                 throw new Exception('Error processing filter array - unknown property ' . var_export($arrFilter['property'], true), 1);
             }
             $objFilter->addFilterRule($objFilterRule);
             break;
         default:
             throw new Exception('Error processing filter array - unknown operation ' . var_export($arrFilter, true), 1);
     }
 }
Exemplo n.º 4
0
 /**
  * Create a new instance.
  *
  * @param IMetaModel $objMetaModel The model this item is represented by.
  *
  * @param array      $arrData      The initial data that shall be injected into the new instance.
  */
 public function __construct(IMetaModel $objMetaModel, $arrData)
 {
     $this->arrData = $arrData;
     $this->strModelName = $objMetaModel->getTableName();
 }
Exemplo n.º 5
0
 public function __construct(IMetaModel $objMetaModel)
 {
     if ($objMetaModel) {
         $this->strMetaModel = $objMetaModel->getTableName();
     }
 }