/** * Build the marker. * * @param Item $item The metamodel item. * @param string $parentId Id of the parent layer. * * @return Marker */ protected function buildMarker(Item $item, $parentId) { $metaModel = $item->getMetaModel(); $coordinates = $this->getCoordinates($item); if (!$coordinates) { return null; } $settings = $this->getRenderSettings($metaModel); $icon = $this->getIcon($item->get('id')); $popup = $this->getPopupContent($item, $settings); $identifier = sprintf('%s_%s_%s_marker', $parentId, $metaModel->getTableName(), $item->get('id')); $marker = new Marker($identifier, $coordinates); if ($this->model->options) { $marker->setOptions((array) json_decode($this->model->options, true)); } if ($icon) { $marker->setIcon($icon); } if ($popup) { $marker->setPopupContent($popup); } // @codingStandardsIgnoreStart // TODO: Attributes mapping // @codingStandardsIgnoreEnd return $marker; }
/** * Load features from file attribute. * * @param Item $item The metamodel. * @param string $attribute The attribute name. * @param \callable $callback The callback being called for each file. * * @return void */ private function loadFeaturesFromFile(Item $item, $attribute, $callback) { $value = $item->parseAttribute($attribute); if (empty($value['raw']['path'])) { return; } foreach ($value['raw']['path'] as $key => $path) { $callback($path, $key); } }
/** * Remove invariant attributes from the render setting. * * This is done by cloning the input collection of render settings and removing any invariant attribute. * * @param IItem $nativeItem The native item. * * @param ICollection $renderSetting The render setting to be used. * * @return ICollection */ protected static function removeInvariantAttributes(IItem $nativeItem, ICollection $renderSetting) { $model = $nativeItem->getMetaModel(); if ($model->hasVariants() && !$nativeItem->isVariantBase()) { // Create a clone to have a separate copy of the object as we are going to manipulate it here. $renderSetting = clone $renderSetting; // Loop over all attributes and remove those from rendering that are not desired. foreach (array_keys($model->getInVariantAttributes()) as $strAttrName) { $renderSetting->setSetting($strAttrName, null); } } return $renderSetting; }
/** * Load the values from given MetaModels Item * * @throws \Exception When an MetaModels Item is missing */ public function loadValues() { if (is_null($this->mmItem)) { throw new \Exception('Trying to load values from empty mmItem - aborting'); return false; } /** * Set default values to fields */ $this->fields->reset(); while ($this->fields->next()) { $field = $this->fields->current(); if (!method_exists($field, 'setDefaultValue')) { continue; } $value = $this->mmItem->get($field->getColName()); $field->setDefaultValue($value); } }
/** * {@inheritdoc} */ public function generateFilterUrlFrom(IItem $objItem, IRenderSettings $objRenderSetting) { $objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id')); if ($objAttribute) { // TODO: shall we omit returning of empty values? $strResult = $objAttribute->getFilterUrlValue($objItem->get($objAttribute->getColName())); return array($this->getParamName() => $strResult); } return array(); }
/** * Get a MetaModel attribute by a column name of the FeatureModel which contains the id. * * @param string $column The name of the attribute id. * @param Item $item The metamodel item. * * @return Attribute */ protected function getAttribute($column, Item $item) { return $item->getMetaModel()->getAttributeById($this->model->{$column}); }
/** * Apply the path style. * * @param Item $item The MetaModel item. * @param mixed $definition The definition. * * @return void */ protected function applyStyle(Item $item, $definition) { if ($definition instanceof Path) { $style = $this->getStyle($item->get('id')); if ($style) { $style->apply($definition); } elseif ($this->fallbackStyle) { $this->fallbackStyle->apply($definition); } } }
/** * @param $model * @return string */ protected function generateLabel(IItem $model) { $templateName = $this->renderSetting->get('template'); $format = $this->getOutputFormat(); $data = array('settings' => $this->renderSetting, 'item' => $model->parseValue($format, $this->renderSetting)); return Template::render($templateName, $format, $data); }
/** * {@inheritdoc} */ public function delete(IItem $objItem) { $arrIds = array($objItem->get('id')); // Determine if the model is a variant base and if so, fetch the variants additionally. if ($objItem->isVariantBase()) { $objVariants = $objItem->getVariants(new Filter($this)); foreach ($objVariants as $objVariant) { /** @var IItem $objVariant */ $arrIds[] = $objVariant->get('id'); } } // Complex attributes shall delete their values first. foreach ($this->getAttributes() as $objAttribute) { if ($this->isComplexAttribute($objAttribute)) { /** @var IComplex $objAttribute */ $objAttribute->unsetDataFor($arrIds); } } // Now make the real row disappear. $this->getDatabase()->prepare(sprintf('DELETE FROM %s WHERE id IN (%s)', $this->getTableName(), $this->buildDatabaseParameterList($arrIds)))->execute($arrIds); }