/** * 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(); }
/** * {@inheritdoc} */ public static function byId(IMetaModel $objMetaModel, $intId = 0) { if (self::$arrInstances[$intId]) { return self::$arrInstances[$intId]; } $objDB = Database::getInstance(); $objView = null; $objView = Database::getInstance()->prepare('SELECT * FROM tl_metamodel_rendersettings WHERE pid=? AND (id=? OR isdefault=1) ORDER BY isdefault ASC')->limit(1)->execute($objMetaModel->get('id'), $intId); if (!$objView->numRows) { $intId = 0; $objView = NULL; } $objRenderSetting = new MetaModelRenderSettings($objView ? $objView->row() : array()); self::collectAttributeSettings($objMetaModel, $objRenderSetting); return $objRenderSetting; }
/** * Get the fallback language of a certain record. * * @param mixed $mixID The ID of the record to retrieve. * * @return InterfaceGeneralModel */ public function getFallbackLanguage($mixID) { if ($this->objMetaModel->isTranslated()) { $objModel = new GeneralModelDefault(); $strLangCode = $this->objMetaModel->getFallbackLanguage(); $objModel->setID($strLangCode); $objModel->setProperty("name", $GLOBALS['TL_LANG']['LNG'][$strLangCode]); $objModel->setProperty("active", $this->getCurrentLanguage() == $strLangCode); return $objModel; } return null; }
/** * backend list display of fe-filter * @param array * @param string * @param object * @param string * @param string * @return string */ public function infoCallback($arrRow, $strLabel, $objDC, $imageAttribute, $strImage) { $this->objectsFromUrl($objDC); $objAttribute = $this->objMetaModel->getAttributeById($arrRow['attr_id']); if ($objAttribute) { $strAttrName = $objAttribute->getName(); $strAttrColName = $objAttribute->getColName(); } else { $strAttrName = $arrRow['attr_id']; $strAttrColName = $arrRow['attr_id']; } if (!empty($arrRow['comment'])) { $arrRow['comment'] = sprintf($GLOBALS['TL_LANG']['tl_metamodel_filtersetting']['typedesc']['_comment_'], specialchars($arrRow['comment'])); } $strReturn = sprintf($GLOBALS['TL_LANG']['tl_metamodel_filtersetting']['typedesc']['fefilter'], '<a href="' . $this->addToUrl('act=edit&id=' . $arrRow['id']) . '">' . $strImage . '</a>', $strLabel, $arrRow['comment'], $strAttrName, $arrRow['urlparam'] ? $arrRow['urlparam'] : $strAttrColName); return $strReturn; }
/** * Retrieves a palette from the database and populates the passed DCA 'fields' section with the correct settings. * * @param int $intPaletteId the id of the palette to retrieve * * @param IMetaModel $objMetaModel the MetaModel for which the palette shall be built. * * @param array $arrDCA the DCA that shall get populated (used by reference). * * @return string the palette string. */ protected function getPaletteAndFields($intPaletteId, $objMetaModel, &$arrDCA) { $strPalette = ''; $objDCASettings = Database::getInstance()->prepare('SELECT * FROM tl_metamodel_dcasetting WHERE pid=? AND published = 1 ORDER by sorting ASC')->execute($intPaletteId); $arrMyDCA = array(); while ($objDCASettings->next()) { switch ($objDCASettings->dcatype) { case 'attribute': $objAttribute = $objMetaModel->getAttributeById($objDCASettings->attr_id); if ($objAttribute) { // Get basics. $arrFieldSetting = $objDCASettings->row(); // Overwrite submitOnChange if we have a selector. if ($this->isSelector($objDCASettings->id)) { $arrFieldSetting = array_replace_recursive($objDCASettings->row(), array('submitOnChange' => true)); } $arrMyDCA = array_replace_recursive($arrMyDCA, $objAttribute->getItemDCA($arrFieldSetting)); // Check if we have a subpalette. If false, add to normal palettes. if ($objDCASettings->subpalette == 0) { $strPalette .= (strlen($strPalette) > 0 ? ',' : '') . $objAttribute->getColName(); } else { $strSelector = $this->getColNameByDcaSettingId($objMetaModel, $objDCASettings->subpalette); // This should never ever be true. If so, we have dead entries in the database. if ($strSelector === false) { break; } $arrMyDCA['metasubpalettes'][$strSelector][] = $objAttribute->getColName(); } } break; case 'legend': $arrLegend = deserialize($objDCASettings->legendtitle); if (is_array($arrLegend)) { // try to use the language string from the array. $strLegend = $arrLegend[$GLOBALS['TL_LANGUAGE']]; if (!$strLegend) { // use the fallback $strLegend = $arrLegend[$objMetaModel->getFallbackLanguage()]; if (!$strLegend) { // last resort, simply "legend" $strLegend = 'legend'; } } } else { $strLegend = $objDCASettings->legendtitle ? $objDCASettings->legendtitle : 'legend'; } $legendName = standardize($strLegend) . '_legend'; $GLOBALS['TL_LANG'][$objMetaModel->getTableName()][$legendName] = $strLegend; $strPalette .= (strlen($strPalette) > 0 ? ';' : '') . '{' . $legendName . ($objDCASettings->legendhide ? ':hide' : '') . '}'; break; default: throw new Exception("Unknown palette rendering mode " . $objDCASettings->dcatype); } } $arrDCA = array_replace_recursive($arrDCA, $arrMyDCA); return $strPalette; }
/** * Prepare the rendering */ public function prepare() { if ($this->objItems) { return $this; } // create an empty filter object if not done before if (!$this->objFilter) { $this->objFilter = $this->objMetaModel->getEmptyFilter(); } if ($this->objFilterSettings) { $this->objFilterSettings->addRules($this->objFilter, $this->arrParam); } $this->modifyFilter(); $intTotal = $this->objMetaModel->getCount($this->objFilter); $this->calculatePagination($intTotal); $this->objItems = $this->objMetaModel->findByFilter($this->objFilter, $this->strSortBy, $this->intOffset, $this->intLimit, $this->strSortDirection, $this->getAttributeNames()); return $this; }
/** * 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(); }
protected function prepareJumpToMcw(IMetaModel $objMetaModel) { $arrwidget = array(); if ($objMetaModel->isTranslated()) { $this->loadLanguageFile('languages'); $arrLanguages = array(); foreach ((array) $objMetaModel->getAvailableLanguages() as $strLangCode) { $arrLanguages[$strLangCode] = $GLOBALS['TL_LANG']['LNG'][$strLangCode]; } asort($arrLanguages); $GLOBALS['TL_DCA']['tl_metamodel_rendersettings']['fields']['jumpTo']['minCount'] = count($arrLanguages); $GLOBALS['TL_DCA']['tl_metamodel_rendersettings']['fields']['jumpTo']['maxCount'] = count($arrLanguages); $GLOBALS['TL_DCA']['tl_metamodel_rendersettings']['fields']['jumpTo']['eval']['columnFields']['langcode']['options'] = $arrLanguages; } else { $GLOBALS['TL_DCA']['tl_metamodel_rendersettings']['fields']['jumpTo']['minCount'] = 1; $GLOBALS['TL_DCA']['tl_metamodel_rendersettings']['fields']['jumpTo']['maxCount'] = 1; $GLOBALS['TL_DCA']['tl_metamodel_rendersettings']['fields']['jumpTo']['eval']['columnFields']['langcode']['options'] = array('xx' => $GLOBALS['TL_LANG']['tl_metamodel_rendersettings']['jumpTo_allLanguages']); } }
/** * Check if the item is published. * * @param IMetaModel $objMetaModel Current metamodels. * @param int $intItemId Id of the item. * * @return boolean True => Published | False => Not published */ protected function isPublishedItem($objMetaModel, $intItemId) { // Check publish state of an item. $objAttrCheckPublish = Database::getInstance()->prepare('SELECT colname FROM tl_metamodel_attribute WHERE pid=? AND check_publish=1')->limit(1)->execute($objMetaModel->get('id')); if ($objAttrCheckPublish->numRows > 0) { $objItem = $objMetaModel->findById($intItemId); if (!$objItem->get($objAttrCheckPublish->colname)) { return false; } } return true; }
/** * Create a widget for naming contexts. Use the language and translation information from the MetaModel. * * @param IMetaModel $objMetaModel The metamodel * * @param string $strLabelLang The label to use for the language indicator * * @param string $strLabelValue The label to use for the input field. * * @param bool $blnIsTextarea If true, the widget will become a textarea, false otherwise. * * @param array $arrValues The values for the widget, needed to highlight the fallback language. * * @return array */ public function makeMultiColumnName(IMetaModel $objMetaModel, &$strLabelLang, &$strLabelValue, $blnIsTextarea, $arrValues) { $arrwidget = array(); if (!$objMetaModel->isTranslated()) { $arrwidget = array('inputType' => 'text', 'eval' => array('tl_class' => 'w50')); } else { $this->loadLanguageFile('languages'); $arrLanguages = array(); foreach ((array) $objMetaModel->getAvailableLanguages() as $strLangCode) { $arrLanguages[$strLangCode] = $GLOBALS['TL_LANG']['LNG'][$strLangCode]; } asort($arrLanguages); // Ensure we have the values present. if (empty($arrValues)) { foreach ((array) $objMetaModel->getAvailableLanguages() as $strLangCode) { $arrValues[$strLangCode] = ''; } } $arrRowClasses = array(); foreach (array_keys(deserialize($arrValues)) as $strLangcode) { $arrRowClasses[] = $strLangcode == $objMetaModel->getFallbackLanguage() ? 'fallback_language' : 'normal_language'; } $arrwidget = array('inputType' => 'multiColumnWizard', 'eval' => array('minCount' => count($arrLanguages), 'maxCount' => count($arrLanguages), 'disableSorting' => true, 'tl_class' => 'clr', 'columnFields' => array('langcode' => array('label' => &$strLabelLang, 'exclude' => true, 'inputType' => 'justtextoption', 'options' => $arrLanguages, 'eval' => array('rowClasses' => $arrRowClasses, 'valign' => 'center', 'style' => 'min-width:75px;display:block;')), 'value' => array('label' => &$strLabelValue, 'exclude' => true, 'inputType' => $blnIsTextarea ? 'textarea' : 'text', 'eval' => array('rowClasses' => $arrRowClasses, 'style' => 'width:400px;', 'rows' => 3))))); } return $arrwidget; }
public function __construct(IMetaModel $objMetaModel) { if ($objMetaModel) { $this->strMetaModel = $objMetaModel->getTableName(); } }