/** * Collect the attribute settings for the given render setting. * * @param IMetaModel $metaModel The MetaModel instance to retrieve the settings for. * * @param ICollection $renderSetting The render setting. * * @return void */ public function collectAttributeSettings(IMetaModel $metaModel, $renderSetting) { $attributeRow = $this->serviceContainer->getDatabase()->prepare('SELECT * FROM tl_metamodel_rendersetting WHERE pid=? AND enabled=1 ORDER BY sorting')->execute($renderSetting->get('id')); while ($attributeRow->next()) { $attribute = $metaModel->getAttributeById($attributeRow->attr_id); if (!$attribute) { continue; } // TODO: we should provide attribute type based render setting elements in version 2.X. $attributeSetting = $renderSetting->getSetting($attribute->getColName()); if (!$attributeSetting) { $attributeSetting = $attribute->getDefaultRenderSettings(); } foreach ($attributeRow->row() as $strKey => $varValue) { if ($varValue) { $attributeSetting->set($strKey, deserialize($varValue)); } } $renderSetting->setSetting($attribute->getColName(), $attributeSetting); } }
/** * Return all attributes that shall be fetched from the MetaModel. * * In this base implementation, this only includes the attributes mentioned in the render setting. * * @author Christian Schiffler <*****@*****.**> * @copyright The MetaModels team. * @see MetaModels::getAttributeNames * @return string[] the names of the attributes to be fetched. */ protected function getAttributeNames() { $arrAttributes = $this->renderSetting->getSettingNames(); // Get the right jumpTo. $desiredLanguage = $this->getMetaModel()->getActiveLanguage(); $strFallbackLanguage = $this->getMetaModel()->getFallbackLanguage(); $filterSetting = 0; foreach ((array) $this->renderSetting->get('jumpTo') as $jumpTo) { // If either desired language or fallback, keep the result. if (!$this->getMetaModel()->isTranslated() || $jumpTo['langcode'] == $desiredLanguage || $jumpTo['langcode'] == $strFallbackLanguage) { $filterSetting = $jumpTo['filter']; // If the desired language, break. Otherwise try to get the desired one until all have been evaluated. if ($desiredLanguage == $jumpTo['langcode']) { break; } } } if ($filterSetting) { $objFilterSettings = MetaModelsFilterFactory::byId($filterSetting); $arrAttributes = array_merge($objFilterSettings->getReferencedAttributes(), $arrAttributes); } return $arrAttributes; }
/** * Retrieve the translation string for the given lang key. * * In order to achieve the correct caption text, the function tries several translation strings sequentially. * The first language key that is set will win, even if it is to be considered empty. * * This message is looked up in the following order: * 1. $GLOBALS['TL_LANG']['MSC'][<mm tablename>][<render settings id>][$langKey] * 2. $GLOBALS['TL_LANG']['MSC'][<mm tablename>][$langKey] * 3. $GLOBALS['TL_LANG']['MSC'][$langKey] * * @param string $langKey The language key to retrieve. * * @return string * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ private function getCaptionText($langKey) { $tableName = $this->getMetaModel()->getTableName(); if (isset($this->objView) && isset($GLOBALS['TL_LANG']['MSC'][$tableName][$this->objView->get('id')][$langKey])) { return $GLOBALS['TL_LANG']['MSC'][$tableName][$this->objView->get('id')][$langKey]; } elseif (isset($GLOBALS['TL_LANG']['MSC'][$tableName][$langKey])) { return $GLOBALS['TL_LANG']['MSC'][$tableName][$langKey]; } return $GLOBALS['TL_LANG']['MSC'][$langKey]; }
/** * Build the jumpTo link for use in templates. * * The returning array will hold the following keys: * * params - the url parameter (only if a valid filter setting could be determined). * * deep - boolean true, if parameters are non empty, false otherwise. * * page - id of the jumpTo page. * * url - the complete generated url * * @param ICollection $objSettings The render settings to use. * * @return array */ public function buildJumpToLink($objSettings) { if (!$objSettings) { return null; } return $objSettings->buildJumpToUrlFor($this); }
/** * Get the defined output format. * * @param RenderSetting $settings The render settings. * @param string $default The default output format. * * @return mixed|null|string */ protected function getOutputFormat(RenderSetting $settings = null, $default = 'text') { if ($settings) { $format = $settings->get('format'); if (strlen($format)) { return $format; } } return $default; }