当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassDefinition::getFieldDefinitions方法代码示例

本文整理汇总了PHP中Pimcore\Model\Object\ClassDefinition::getFieldDefinitions方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassDefinition::getFieldDefinitions方法的具体用法?PHP ClassDefinition::getFieldDefinitions怎么用?PHP ClassDefinition::getFieldDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pimcore\Model\Object\ClassDefinition的用法示例。


在下文中一共展示了ClassDefinition::getFieldDefinitions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCustomGridFieldDefinitions

 public static function getCustomGridFieldDefinitions($classId, $objectId)
 {
     $object = AbstractObject::getById($objectId);
     $class = ClassDefinition::getById($classId);
     $masterFieldDefinition = $class->getFieldDefinitions();
     if (!$object) {
         return null;
     }
     $user = AdminTool::getCurrentUser();
     if ($user->isAdmin()) {
         return null;
     }
     $permissionList = array();
     $parentPermissionSet = $object->getPermissions(null, $user, true);
     if ($parentPermissionSet) {
         $permissionList[] = $parentPermissionSet;
     }
     $childPermissions = $object->getChildPermissions(null, $user);
     $permissionList = array_merge($permissionList, $childPermissions);
     $layoutDefinitions = array();
     foreach ($permissionList as $permissionSet) {
         $allowedLayoutIds = self::getLayoutPermissions($classId, $permissionSet);
         if (is_array($allowedLayoutIds)) {
             foreach ($allowedLayoutIds as $allowedLayoutId) {
                 if ($allowedLayoutId) {
                     if (!$layoutDefinitions[$allowedLayoutId]) {
                         $customLayout = ClassDefinition\CustomLayout::getById($allowedLayoutId);
                         if (!$customLayout) {
                             continue;
                         }
                         $layoutDefinitions[$allowedLayoutId] = $customLayout;
                     }
                 }
             }
         }
     }
     $mergedFieldDefinition = unserialize(serialize($masterFieldDefinition));
     if (count($layoutDefinitions)) {
         foreach ($mergedFieldDefinition as $key => $def) {
             if ($def instanceof ClassDefinition\Data\Localizedfields) {
                 $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions();
                 foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) {
                     $mergedLocalizedFieldDefinitions[$locKey]->setInvisible(false);
                     $mergedLocalizedFieldDefinitions[$locKey]->setNotEditable(false);
                 }
                 $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions);
             } else {
                 $mergedFieldDefinition[$key]->setInvisible(false);
                 $mergedFieldDefinition[$key]->setNotEditable(false);
             }
         }
     }
     foreach ($layoutDefinitions as $customLayoutDefinition) {
         $layoutName = $customLayoutDefinition->getName();
         $layoutDefinitions = $customLayoutDefinition->getLayoutDefinitions();
         $dummyClass = new ClassDefinition();
         $dummyClass->setLayoutDefinitions($layoutDefinitions);
         $customFieldDefinitions = $dummyClass->getFieldDefinitions();
         foreach ($mergedFieldDefinition as $key => $value) {
             if (!$customFieldDefinitions[$key]) {
                 unset($mergedFieldDefinition[$key]);
             }
         }
         foreach ($customFieldDefinitions as $key => $def) {
             if ($def instanceof ClassDefinition\Data\Localizedfields) {
                 if (!$mergedFieldDefinition[$key]) {
                     continue;
                 }
                 $customLocalizedFieldDefinitions = $def->getFieldDefinitions();
                 $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions();
                 foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) {
                     self::mergeFieldDefinition($mergedLocalizedFieldDefinitions, $customLocalizedFieldDefinitions, $locKey);
                 }
                 $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions);
             } else {
                 self::mergeFieldDefinition($mergedFieldDefinition, $customFieldDefinitions, $key);
             }
         }
     }
     return $mergedFieldDefinition;
 }
开发者ID:elavarasann,项目名称:pimcore,代码行数:81,代码来源:Service.php

示例2: update

 /**
  * @throws \Exception
  * @throws \Zend_Db_Adapter_Exception
  */
 public function update()
 {
     $class = get_object_vars($this->model);
     $data = [];
     foreach ($class as $key => $value) {
         if (in_array($key, $this->getValidTableColumns("classes"))) {
             $data[$key] = $value;
         }
     }
     $this->db->update("classes", $data, $this->db->quoteInto("id = ?", $this->model->getId()));
     $objectTable = "object_query_" . $this->model->getId();
     $objectDatastoreTable = "object_store_" . $this->model->getId();
     $objectDatastoreTableRelation = "object_relations_" . $this->model->getId();
     $objectView = "object_" . $this->model->getId();
     // create object table if not exists
     $protectedColums = ["oo_id", "oo_classId", "oo_className"];
     $protectedDatastoreColumns = ["oo_id"];
     $this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectTable . "` (\n\t\t\t  `oo_id` int(11) NOT NULL default '0',\n\t\t\t  `oo_classId` int(11) default '" . $this->model->getId() . "',\n\t\t\t  `oo_className` varchar(255) default '" . $this->model->getName() . "',\n\t\t\t  PRIMARY KEY  (`oo_id`)\n\t\t\t) DEFAULT CHARSET=utf8mb4;");
     // update default value of classname columns
     $this->db->query('ALTER TABLE `' . $objectTable . "` ALTER COLUMN `oo_className` SET DEFAULT '" . $this->model->getName() . "';");
     $this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTable . "` (\n\t\t\t  `oo_id` int(11) NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`oo_id`)\n\t\t\t) DEFAULT CHARSET=utf8mb4;");
     $this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTableRelation . "` (\n          `src_id` int(11) NOT NULL DEFAULT '0',\n          `dest_id` int(11) NOT NULL DEFAULT '0',\n          `type` varchar(50) NOT NULL DEFAULT '',\n          `fieldname` varchar(70) NOT NULL DEFAULT '0',\n          `index` int(11) unsigned NOT NULL DEFAULT '0',\n          `ownertype` enum('object','fieldcollection','localizedfield','objectbrick') NOT NULL DEFAULT 'object',\n          `ownername` varchar(70) NOT NULL DEFAULT '',\n          `position` varchar(70) NOT NULL DEFAULT '0',\n          PRIMARY KEY (`src_id`,`dest_id`,`ownertype`,`ownername`,`fieldname`,`type`,`position`),\n          KEY `index` (`index`),\n          KEY `src_id` (`src_id`),\n          KEY `dest_id` (`dest_id`),\n          KEY `fieldname` (`fieldname`),\n          KEY `position` (`position`),\n          KEY `ownertype` (`ownertype`),\n          KEY `type` (`type`),\n          KEY `ownername` (`ownername`)\n        ) DEFAULT CHARSET=utf8mb4;");
     $existingColumns = $this->getValidTableColumns($objectTable, false);
     // no caching of table definition
     $existingDatastoreColumns = $this->getValidTableColumns($objectDatastoreTable, false);
     // no caching of table definition
     $columnsToRemove = $existingColumns;
     $datastoreColumnsToRemove = $existingDatastoreColumns;
     Object\ClassDefinition\Service::updateTableDefinitions($this->tableDefinitions, [$objectTable, $objectDatastoreTable]);
     // add non existing columns in the table
     if (is_array($this->model->getFieldDefinitions()) && count($this->model->getFieldDefinitions())) {
         foreach ($this->model->getFieldDefinitions() as $key => $value) {
             // if a datafield requires more than one column in the query table
             if (is_array($value->getQueryColumnType())) {
                 foreach ($value->getQueryColumnType() as $fkey => $fvalue) {
                     $this->addModifyColumn($objectTable, $key . "__" . $fkey, $fvalue, "", "NULL");
                     $protectedColums[] = $key . "__" . $fkey;
                 }
             }
             // if a datafield requires more than one column in the datastore table => only for non-relation types
             if (!$value->isRelationType() && is_array($value->getColumnType())) {
                 foreach ($value->getColumnType() as $fkey => $fvalue) {
                     $this->addModifyColumn($objectDatastoreTable, $key . "__" . $fkey, $fvalue, "", "NULL");
                     $protectedDatastoreColumns[] = $key . "__" . $fkey;
                 }
             }
             // everything else
             //                if (!is_array($value->getQueryColumnType()) && !is_array($value->getColumnType())) {
             if (!is_array($value->getQueryColumnType()) && $value->getQueryColumnType()) {
                 $this->addModifyColumn($objectTable, $key, $value->getQueryColumnType(), "", "NULL");
                 $protectedColums[] = $key;
             }
             if (!is_array($value->getColumnType()) && $value->getColumnType() && !$value->isRelationType()) {
                 $this->addModifyColumn($objectDatastoreTable, $key, $value->getColumnType(), "", "NULL");
                 $protectedDatastoreColumns[] = $key;
             }
             //                }
             // add indices
             $this->addIndexToField($value, $objectTable, "getQueryColumnType");
             $this->addIndexToField($value, $objectDatastoreTable, "getColumnType");
         }
     }
     // remove unused columns in the table
     $this->removeUnusedColumns($objectTable, $columnsToRemove, $protectedColums);
     $this->removeUnusedColumns($objectDatastoreTable, $datastoreColumnsToRemove, $protectedDatastoreColumns);
     // remove / cleanup unused relations
     if (is_array($datastoreColumnsToRemove)) {
         foreach ($datastoreColumnsToRemove as $value) {
             if (!in_array(strtolower($value), array_map('strtolower', $protectedDatastoreColumns))) {
                 $tableRelation = "object_relations_" . $this->model->getId();
                 $this->db->delete($tableRelation, "fieldname = " . $this->db->quote($value) . " AND ownertype = 'object'");
                 // @TODO: remove localized fields and fieldcollections
             }
         }
     }
     // create view
     try {
         //$this->db->query('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `objects` left JOIN `' . $objectTable . '` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id` WHERE `objects`.`o_classId` = ' . $this->model->getId() . ';');
         $this->db->query('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `' . $objectTable . '` JOIN `objects` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id`;');
     } catch (\Exception $e) {
         Logger::debug($e);
     }
     $this->tableDefinitions = null;
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:88,代码来源:Dao.php


注:本文中的Pimcore\Model\Object\ClassDefinition::getFieldDefinitions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。