Ejemplo n.º 1
0
 public function run()
 {
     require_once TL_ROOT . '/system/config/langconfig.php';
     if ($this->Database->tableExists('tl_metafields')) {
         return false;
     }
     if (!is_array($GLOBALS['TL_LANG']['additional_metafields'])) {
         return false;
     }
     if (!array_key_exists('additional_metafields_exts', $GLOBALS['TL_CONFIG'])) {
         return false;
     }
     if (strlen($GLOBALS['TL_CONFIG']['additional_metafields_exts']) === 0) {
         return false;
     }
     $exts = $GLOBALS['TL_CONFIG']['additional_metafields_exts'];
     $dcaExt = new DcaExtractor('tl_metafields');
     $arrSql = $dcaExt->getDbInstallerArray();
     $strSql = "CREATE TABLE `tl_metafields` (" . implode(',', $arrSql["TABLE_FIELDS"]) . ',' . implode(',', $arrSql["TABLE_CREATE_DEFINITIONS"]) . ')' . $arrSql["TABLE_OPTIONS"] . ';';
     $this->Database->execute($strSql);
     foreach ($GLOBALS['TL_LANG']['additional_metafields'] as $alias => $label) {
         $objModel = new MetafieldsModel();
         $objModel->tstamp = time();
         $objModel->alias = $alias;
         $objModel->label = $label;
         $objModel->extensions = $exts;
         $objModel->save();
     }
 }
 private function loadFields()
 {
     if ($this->arrMetafields !== null) {
         return $this->arrMetafields;
     }
     $this->arrMetafields = array();
     // Todo label translation
     $collection = MetafieldsModel::findAll();
     if ($collection === null) {
         return $this->arrMetafields;
     }
     foreach ($collection as $objField) {
         $extensions = array_map('trim', explode(',', $objField->extensions));
         $alias = $objField->alias;
         $label = $objField->label;
         $folderAttr = $objField->folder === '1';
         foreach ($extensions as $ext) {
             if (!is_array($this->arrMetafields[$ext])) {
                 $this->arrMetafields[$ext] = array();
             }
             $this->arrMetafields[$ext][$alias] = $label;
             if ($folderAttr) {
                 if (!is_array($this->arrMetafields[static::TYPE_FOLDER])) {
                     $this->arrMetafields[static::TYPE_FOLDER] = array();
                 }
                 $this->arrMetafields[static::TYPE_FOLDER][$alias] = $label;
             }
         }
     }
     return $this->arrMetafields;
 }