/** * Instantiate the field an set all values * * @param array $data * @param MetaModel $objMM */ public function __construct(array $data, MetaModel $objMM) { $this->mmAttribute = $objMM->getAttributeById($data['attr_id']); $this->colName = $this->mmAttribute->get('colname'); $dcaArray = $this->mmAttribute->getFieldDefinition($data); $this->eval = $dcaArray['eval']; unset($dcaArray['eval']); $this->data = $dcaArray; if ($data['tl_class']) { $this->addEval('class', $data['tl_class']); } /** * Check for inputType and convert if necessary */ switch ($this->get('inputType')) { case 'fileTree': $this->set('inputType', 'upload'); $this->fieldType = 'upload'; break; } if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Url\\Url')) { $this->set('inputType', 'beUrl'); $this->fieldType = 'complex'; } if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\IComplex')) { $this->fieldType = 'complex'; } /** * Check for RTE support on longtext fields */ if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Longtext\\Longtext')) { if (isset($data['rte']) && !empty($data['rte'])) { $this->rte = $data['rte']; $class = $this->getEval('class') . ' ' . $data['rte']; if (!$this->modifyEval('class', $class)) { $this->addEval('class', $class); } } } /** * Get option values from select attributes */ if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Select\\AbstractSelect')) { $this->set('options', $this->mmAttribute->getFilterOptions(null, false)); } /** * Add Save Handler */ switch ($this->fieldType) { case 'upload': $this->setSaveHandler(new UploadSaveHandler($this)); break; default: $this->setSaveHandler(new SaveHandler($this)); break; } }
/** * Test if the passed attribute is acceptable. * * @param IAttribute $attribute The attribute to check. * * @return bool */ protected function accepts($attribute) { if (!$attribute->get('id')) { return false; } return true; }
/** * {@inheritDoc} */ public function getMatchingIds() { if ($this->mode == self::MODE_SINGLE) { return $this->runSimpleQuery('item_id', 'tl_metamodel_geolocation', 'latitude', 'longitude', array('att_id=?' => $this->singleAttribute->get('id'))); } else { return $this->runSimpleQuery('id', $this->getMetaModelTableName(), $this->latitudeAttribute->getColName(), $this->longitudeAttribute->getColName(), null); } }
/** * Check if an attribute is already present. * * @param IAttribute $attribute The attribute to check. * * @return bool */ private function knowsAttribute($attribute) { return array_key_exists($attribute->get('id'), $this->knownAttributes); }
/** * Fetch all options for a given model class. * * @param string $modelClass The model class. * @param IAttribute $attribute The MetaModel attribute which contains the select definitions. * * @return \Model\Collection|null */ protected function fetchOptionsCollection($modelClass, IAttribute $attribute) { if ($attribute->get('select_where')) { $collection = $modelClass::findBy(array($attribute->get('select_where')), array(), array('order' => $attribute->get('select_sorting'))); return $collection; } else { $collection = $modelClass::findAll(array('order' => $attribute->get('select_sorting'))); return $collection; } }