/**
  * retrieve the MetaModel this filter belongs to.
  *
  * @return IMetaModel
  */
 public function getMetaModel()
 {
     if (!$this->arrData['pid']) {
         throw new Exception(sprintf('Error: Filtersetting %d not attached to a MetaModel', $this->arrData['id']));
     }
     return MetaModelFactory::byId($this->arrData['pid']);
 }
Beispiel #2
0
 /**
  * Fetch all attribute names for the current metamodel
  *
  * @param DataContainer $objDC the datacontainer calling this method.
  *
  * @return string[string] array of all attributes as colName => human name
  */
 public function getAttributeNames(DataContainer $objDC)
 {
     $arrAttributeNames = array('sorting' => $GLOBALS['TL_LANG']['MSC']['sorting'], 'random' => $GLOBALS['TL_LANG']['MSC']['random']);
     $objMetaModel = MetaModelFactory::byId($objDC->activeRecord->metamodel);
     if ($objMetaModel) {
         foreach ($objMetaModel->getAttributes() as $objAttribute) {
             $arrAttributeNames[$objAttribute->getColName()] = $objAttribute->getName();
         }
     }
     return $arrAttributeNames;
 }
 /**
  * Create a MetaModelAttribute instance with the given information.
  *
  * @param array $arrData the meta information for the MetaModelAttribute.
  *
  * @return IMetaModelAttribute|null the created instance or null if unable to construct.
  */
 protected static function createInstance($arrData)
 {
     $strFactoryName = self::getAttributeTypeFactory($arrData['type']);
     $objAttribute = null;
     if ($strFactoryName) {
         $objAttribute = call_user_func_array(array($strFactoryName, 'createInstance'), array($arrData));
     } else {
         $strClassName = self::getAttributeTypeClass($arrData['type']);
         if ($strClassName) {
             $objMetaModel = MetaModelFactory::byId($arrData['pid']);
             $objAttribute = new $strClassName($objMetaModel, $arrData);
         }
     }
     return $objAttribute;
 }
    /**
     * Add the type of input field
     * @param array
     * @return string
     */
    public function renderField($arrRow)
    {
        $objMetaModel = MetaModelFactory::byId($arrRow['pid']);
        $strColName = $arrRow['colname'];
        $strType = $arrRow['type'];
        $strImages = '';
        $strTypeImage = '';
        $arrName = deserialize($arrRow['name']);
        if (is_array($arrName)) {
            $strName = $arrName[$GLOBALS['TL_LANGUAGE']];
            if (!$strName) {
                $strName = $arrName[$objMetaModel->getFallbackLanguage()];
            }
        } else {
            $strName = $arrRow['name'];
        }
        $arrDescription = deserialize($arrRow['description']);
        if (is_array($arrDescription)) {
            $strDescription = $arrDescription[$GLOBALS['TL_LANGUAGE']];
            if (!$strDescription) {
                $strDescription = $arrDescription[$objMetaModel->getFallbackLanguage()];
            }
        } else {
            $strDescription = $arrRow['name'];
        }
        $strTypeImage = '<img src="' . $GLOBALS['METAMODELS']['attributes'][$strType]['image'] . '" />';
        return sprintf('<div class="field_heading cte_type"><strong>%s</strong> <em>[%s]</em></div>
<div class="field_type block">
	<div style="padding-top:3px; float:right;">%s</div>
	%s<strong>%s</strong> - %s<br />
	' . ($arrRow['insertBreak'] ? '<span style="padding-left:20px;" class="legend" title="' . $GLOBALS['TL_LANG']['tl_metamodel_attribute']['legendTitle'][0] . '">' . $legendImage . ' ' . $arrRow['legendTitle'] . '</span>' : '') . '
</div>', $strColName, $strType, $strImages, $strTypeImage, $strName, $strDescription);
    }
 public function injectIntoBackendModules()
 {
     $arrPTables = $this->arrPTables;
     $intCount = count($arrPTables);
     // loop until all tables are injected or until there was no injection during one run.
     // This is important, as we might have models that are child of another model.
     while ($arrPTables) {
         foreach ($arrPTables as $strTable => $arrModels) {
             foreach ($GLOBALS['BE_MOD'] as $strGroup => $arrModules) {
                 foreach ($arrModules as $strModule => $arrConfig) {
                     if (isset($arrConfig['tables']) && in_array($strTable, $arrConfig['tables'])) {
                         $arrSubTables = array();
                         foreach ($arrModels as $intModel) {
                             $arrSubTables[] = MetaModelFactory::byId($intModel)->getTableName();
                         }
                         $GLOBALS['BE_MOD'][$strGroup][$strModule]['tables'] = array_merge($GLOBALS['BE_MOD'][$strGroup][$strModule]['tables'], $arrSubTables);
                         unset($arrPTables[$strTable]);
                     }
                 }
             }
         }
         if (count($arrPTables) == $intCount) {
             break;
         }
         $intCount = count($arrPTables);
     }
 }
 public function getAttributes()
 {
     $objMetaModel = MetaModelFactory::byId();
     $tables = array();
     foreach ($this->Database->listTables() as $table) {
         $tables[$table] = $table;
     }
     return $tables;
 }
 /**
  *
  * @param type $objDC
  * @return type
  * @throws Exception
  */
 public function onLoadCallback($objDC)
 {
     // do nothing if not in edit/create mode.
     if (!(($this->Input->get('pid') || $this->Input->get('id')) && in_array($this->Input->get('act'), array('create', 'edit')))) {
         return;
     }
     if ($objDC->id) {
         $objMetaModel = MetaModelFactory::byId($this->Database->prepare('SELECT pid FROM tl_metamodel_rendersettings WHERE id = ?')->execute($objDC->id)->pid);
     } else {
         if ($this->Input->get('pid')) {
             $objMetaModel = MetaModelFactory::byId($this->Input->get('pid'));
         }
     }
     if (!$objMetaModel) {
         throw new Exception('unexpected condition, metamodel unknown', 1);
     }
     $this->prepareJumpToMcw($objMetaModel);
 }
 /**
  * Prepare the MetaModel.
  *
  * @return void
  *
  * @throws RuntimeException
  */
 protected function prepareMetaModel()
 {
     $this->objMetaModel = MetaModelFactory::byId($this->intMetaModel);
     if (!$this->objMetaModel) {
         throw new \RuntimeException('Could get metamodel id: ' . $this->intMetaModel);
     }
 }
 /**
  * Generate module
  */
 public function addAll()
 {
     $this->loadLanguageFile('default');
     $this->loadLanguageFile('tl_metamodel_rendersetting');
     $this->Template = new BackendTemplate('be_autocreateview');
     $this->Template->cacheMessage = '';
     $this->Template->updateMessage = '';
     $this->Template->href = $this->getReferer(true);
     $this->Template->headline = $GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['addall'][1];
     // severity: error, confirm, info, new
     $arrMessages = array();
     $objPalette = $this->Database->prepare('SELECT * FROM tl_metamodel_rendersettings WHERE id=?')->execute($this->Input->get('id'));
     $objMetaModel = MetaModelFactory::byId($objPalette->pid);
     $objAlreadyExist = $this->Database->prepare('SELECT * FROM tl_metamodel_rendersetting WHERE pid=?')->execute($this->Input->get('id'));
     $arrKnown = array();
     $intMax = 128;
     while ($objAlreadyExist->next()) {
         $arrKnown[$objAlreadyExist->attr_id] = $objAlreadyExist->row();
         if ($intMax < $objAlreadyExist->sorting) {
             $intMax = $objAlreadyExist->sorting;
         }
     }
     $blnWantPerform = false;
     // perform the labour work
     if ($this->Input->post('act') == 'perform') {
         // loop over all attributes now.
         foreach ($objMetaModel->getAttributes() as $objAttribute) {
             if (!array_key_exists($objAttribute->get('id'), $arrKnown)) {
                 $arrData = array();
                 $objRenderSetting = $objAttribute->getDefaultRenderSettings();
                 foreach ($objRenderSetting->getKeys() as $key) {
                     $arrData[$key] = $objRenderSetting->get($key);
                 }
                 $arrData = array_replace_recursive($arrData, array('pid' => $this->Input->get('id'), 'sorting' => $intMax, 'tstamp' => time(), 'attr_id' => $objAttribute->get('id')));
                 $intMax += 128;
                 $this->Database->prepare('INSERT INTO tl_metamodel_rendersetting %s')->set($arrData)->execute();
                 $arrMessages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['addAll_addsuccess'], $objAttribute->getName()));
             }
         }
     } else {
         // loop over all attributes now.
         foreach ($objMetaModel->getAttributes() as $objAttribute) {
             if (array_key_exists($objAttribute->get('id'), $arrKnown)) {
                 $arrMessages[] = array('severity' => 'info', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['addAll_alreadycontained'], $objAttribute->getName()));
             } else {
                 $arrMessages[] = array('severity' => 'confirm', 'message' => sprintf($GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['addAll_willadd'], $objAttribute->getName()));
                 $blnWantPerform = true;
             }
         }
     }
     if ($blnWantPerform) {
         $this->Template->action = ampersand($this->Environment->request);
         $this->Template->submit = $GLOBALS['TL_LANG']['MSC']['continue'];
     } else {
         $this->Template->action = ampersand($this->getReferer(true));
         $this->Template->submit = $GLOBALS['TL_LANG']['MSC']['saveNclose'];
     }
     $this->Template->error = $arrMessages;
     return $this->Template->parse();
 }
 /**
  * Try to load the mm by id or name.
  * 
  * @param mixed $nameOrId Name or id of mm.
  * 
  * @return IMetaModel|null
  */
 protected function loadMM($nameOrId)
 {
     // ID.
     if (is_numeric($nameOrId)) {
         return MetaModelFactory::byId($nameOrId);
     } elseif (is_string($nameOrId)) {
         return MetaModelFactory::byTableName($nameOrId);
     }
     // Unknown.
     return null;
 }
 /**
  * Get a list with all allowed attributes for meta description.
  * 
  * @param DataContainer $objDC
  * 
  * @return array A list with all found attributes.
  */
 public function getAttributeNamesForModel($intMetaModel, $arrTypes = array())
 {
     $arrAttributeNames = array();
     $objMetaModel = MetaModelFactory::byId($intMetaModel);
     if ($objMetaModel) {
         foreach ($objMetaModel->getAttributes() as $objAttribute) {
             if (empty($arrTypes) || in_array($objAttribute->get('type'), $arrTypes)) {
                 $arrAttributeNames[$objAttribute->getColName()] = $objAttribute->getName() . ' [' . $objAttribute->getColName() . ']';
             }
         }
     }
     return $arrAttributeNames;
 }
 public function subpaletteButton($row, $href, $label, $title, $icon, $attributes)
 {
     // Check if we have a attribute
     if ($row['dcatype'] != 'attribute' || strlen($this->Input->get('subpaletteid')) != 0) {
         return $this->makeDisabledButton($icon, $label);
     }
     // Get MM and check if we have a valide one.
     $intId = $this->Database->prepare('SELECT pid FROM tl_metamodel_dca WHERE id=?')->execute($row['pid'])->pid;
     $objMetaModel = MetaModelFactory::byId($intId);
     if (is_null($objMetaModel)) {
         return $this->makeDisabledButton($icon, $label);
     }
     // Get attribute and check if we have a valide one.
     $objAttribute = $objMetaModel->getAttributeById($row['attr_id']);
     if (is_null($objAttribute)) {
         return $this->makeDisabledButton($icon, $label);
     }
     // TODO: add some attribute::supports method to add only for attributes that indeed support subpaletting.
     // For the moment we add a dirty check, only for checkboxes.
     if (in_array($objAttribute->get('type'), array('checkbox'))) {
         return '<a href="' . $this->addToUrl($href . '&amp;id=' . $row['pid'] . '&amp;subpaletteid=' . $row['id']) . '" title="' . specialchars($title) . '"' . $attributes . '>' . $this->generateImage($icon, $label) . '</a> ';
     }
     return $this->makeDisabledButton($icon, $label);
 }
 /**
  * Fetch all attributes from the parenting MetaModel. Called as options_callback.
  *
  * @return array
  */
 public function getAllAttributes()
 {
     $intID = $this->Input->get('id');
     $intPid = $this->Input->get('pid');
     $arrReturn = array();
     if (empty($intPid)) {
         $objResult = $this->Database->prepare('SELECT pid FROM tl_metamodel_dca WHERE id=?')->limit(1)->execute($intID);
         if ($objResult->numRows == 0) {
             return $arrReturn;
         }
         $objMetaModel = MetaModelFactory::byId($objResult->pid);
     } else {
         $objMetaModel = MetaModelFactory::byId($intPid);
     }
     foreach ($objMetaModel->getAttributes() as $objAttribute) {
         $arrReturn[$objAttribute->getColName()] = $objAttribute->getName();
     }
     return $arrReturn;
 }
    protected function objectsFromUrl($objDC)
    {
        if ($this->Input->get('do') != 'metamodels' || (is_object($objDC) && $objDC->table != 'tl_metamodel_filtersetting' || !is_object($objDC) && $objDC != 'tl_metamodel_filtersetting')) {
            return;
        }
        // TODO: detect all other ways we might end up here and fetch $objMetaModel accordingly.
        if ($this->objMetaModel) {
            return;
        }
        if (is_object($objDC) && $objDC->getCurrentModel()) {
            $this->strSettingType = $objDC->getCurrentModel()->getProperty('type');
            $this->objFilter = $this->Database->prepare('SELECT * FROM tl_metamodel_filter WHERE id=?')->execute($objDC->getCurrentModel()->getProperty('fid'));
            $this->objMetaModel = MetaModelFactory::byId($this->objFilter->pid);
        }
        if ($this->Input->get('act')) {
            // act present, but we have an id
            switch ($this->Input->get('act')) {
                case 'edit':
                    if ($this->Input->get('id')) {
                        $this->objFilter = $this->Database->prepare('
							SELECT tl_metamodel_filter.*,
								tl_metamodel_filtersetting.type AS tl_metamodel_filtersetting_type,
								tl_metamodel_filtersetting.id AS tl_metamodel_filtersetting_id
							FROM tl_metamodel_filtersetting
							LEFT JOIN tl_metamodel_filter
							ON (tl_metamodel_filtersetting.fid = tl_metamodel_filter.id)
							WHERE (tl_metamodel_filtersetting.id=?)')->execute($this->Input->get('id'));
                        $this->strSettingType = $this->objFilter->tl_metamodel_filtersetting_type;
                        $this->objMetaModel = MetaModelFactory::byId($this->objFilter->pid);
                    }
                    break;
                case 'paste':
                    if ($this->Input->get('id')) {
                        switch ($this->Input->get('mode')) {
                            case 'create':
                                $this->objFilter = $this->Database->prepare('SELECT * FROM tl_metamodel_filter WHERE id=?')->execute($this->Input->get('id'));
                                $this->objMetaModel = MetaModelFactory::byId($this->objFilter->pid);
                                break;
                            case 'cut':
                                $this->objFilter = $this->Database->prepare('
									SELECT tl_metamodel_filter.*,
										tl_metamodel_filtersetting.type AS tl_metamodel_filtersetting_type,
										tl_metamodel_filtersetting.id AS tl_metamodel_filtersetting_id
									FROM tl_metamodel_filtersetting
									LEFT JOIN tl_metamodel_filter
									ON (tl_metamodel_filtersetting.fid = tl_metamodel_filter.id)
									WHERE (tl_metamodel_filtersetting.id=?)')->execute($this->Input->get('source'));
                                $this->strSettingType = $this->objFilter->tl_metamodel_filtersetting_type;
                                $this->objMetaModel = MetaModelFactory::byId($this->objFilter->pid);
                                break;
                        }
                    }
                    break;
                case 'create':
                    $this->objFilter = $this->Database->prepare('SELECT * FROM tl_metamodel_filter WHERE id=?')->execute($this->Input->get('id'));
                    $this->objMetaModel = MetaModelFactory::byId($this->objFilter->pid);
                    break;
                default:
            }
        } else {
            // no act but we have an id, should be list mode then, no type name available.
            if ($this->Input->get('id')) {
                $this->objFilter = $this->Database->prepare('SELECT * FROM tl_metamodel_filter WHERE id=?')->execute($this->Input->get('id'));
                $this->objMetaModel = MetaModelFactory::byId($this->objFilter->pid);
            }
        }
        // select all root entries for the current filter.
        $GLOBALS['TL_DCA']['tl_metamodel_filtersetting']['list']['sorting']['root'] = $this->Database->prepare('SELECT * FROM tl_metamodel_filtersetting WHERE fid=? AND pid=0')->execute($this->objFilter->id)->fetchEach('id');
        $GLOBALS['TL_DCA']['tl_metamodel_filtersetting']['list']['sorting']['rootPaste'] = true;
        if ($this->objMetaModel) {
            $GLOBALS['TL_LANG']['MSC']['editRecord'] = sprintf($GLOBALS['TL_LANG']['MSC']['metamodel_filtersetting']['editRecord'], $this->objFilter->name, $this->objMetaModel->getName());
            $GLOBALS['TL_DCA']['tl_metamodel_filtersetting']['config']['label'] = sprintf($GLOBALS['TL_LANG']['MSC']['metamodel_filtersetting']['label'], $this->objFilter->name, $this->objMetaModel->getName());
        }
    }
 protected function getFourthLevel($strTable, $strParentTable, $strIcon)
 {
     $strUrl = 'contao/main.php?do=metamodels&table=' . $strTable . '&id=' . $intCurrrentID;
     switch ($strTable) {
         case 'metamodel_dcasetting_subpalette':
             $objParent = Database::getInstance()->prepare('SELECT id, pid, name FROM tl_metamodel_attribute WHERE id=(SELECT attr_id FROM tl_metamodel_dcasetting WHERE pid=? AND id=?)')->executeUncached($this->intID, Input::getInstance()->get('subpaletteid'));
             /**
              * @var IMetaModel
              */
             $objMetaModel = MetaModelFactory::byId($objParent->pid);
             $objAttribute = $objMetaModel->getAttributeById($objParent->id);
             // Change id for next entry.
             $strName = $objAttribute->getName();
             $intCurrrentID = $this->intID;
             //$this->intID = $objParent->pid;
             $strSubfilter = 'subpaletteid=' . Input::getInstance()->get('subpaletteid');
             $strUrl = 'contao/main.php?do=metamodels&table=' . $strParentTable . '&id=' . $intCurrrentID . '&' . $strSubfilter;
             break;
     }
     return array('url' => $strUrl, 'text' => sprintf($this->getLanguage($strTable), $strName), 'icon' => !empty($strIcon) ? Environment::getInstance()->base . '/system/modules/metamodels/html/' . $strIcon : null);
 }