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


PHP Service::getFieldForBrickType方法代码示例

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


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

示例1: gridProxyAction

 public function gridProxyAction()
 {
     if ($this->getParam("language")) {
         $this->setLanguage($this->getParam("language"), true);
     }
     if ($this->getParam("data")) {
         if ($this->getParam("xaction") == "update") {
             try {
                 $data = \Zend_Json::decode($this->getParam("data"));
                 // save
                 $object = Object::getById($data["id"]);
                 /** @var Object\ClassDefinition $class */
                 $class = $object->getClass();
                 if (!$object->isAllowed("publish")) {
                     throw new \Exception("Permission denied. You don't have the rights to save this object.");
                 }
                 $user = Tool\Admin::getCurrentUser();
                 if (!$user->isAdmin()) {
                     $languagePermissions = $object->getPermissions("lEdit", $user);
                     $languagePermissions = explode(",", $languagePermissions["lEdit"]);
                 }
                 $objectData = array();
                 foreach ($data as $key => $value) {
                     $parts = explode("~", $key);
                     if (substr($key, 0, 1) == "~") {
                         $type = $parts[1];
                         $field = $parts[2];
                         $keyid = $parts[3];
                         $getter = "get" . ucfirst($field);
                         $setter = "set" . ucfirst($field);
                         $keyValuePairs = $object->{$getter}();
                         if (!$keyValuePairs) {
                             $keyValuePairs = new Object\Data\KeyValue();
                             $keyValuePairs->setObjectId($object->getId());
                             $keyValuePairs->setClass($object->getClass());
                         }
                         $keyValuePairs->setPropertyWithId($keyid, $value, true);
                         $object->{$setter}($keyValuePairs);
                     } elseif (count($parts) > 1) {
                         $brickType = $parts[0];
                         $brickKey = $parts[1];
                         $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                         $fieldGetter = "get" . ucfirst($brickField);
                         $brickGetter = "get" . ucfirst($brickType);
                         $valueSetter = "set" . ucfirst($brickKey);
                         $brick = $object->{$fieldGetter}()->{$brickGetter}();
                         if (empty($brick)) {
                             $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
                             $brickSetter = "set" . ucfirst($brickType);
                             $brick = new $classname($object);
                             $object->{$fieldGetter}()->{$brickSetter}($brick);
                         }
                         $brick->{$valueSetter}($value);
                     } else {
                         if (!$user->isAdmin() && $languagePermissions) {
                             $fd = $class->getFieldDefinition($key);
                             if (!$fd) {
                                 // try to get via localized fields
                                 $localized = $class->getFieldDefinition("localizedfields");
                                 if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) {
                                     $field = $localized->getFieldDefinition($key);
                                     if ($field) {
                                         $currentLocale = (string) \Zend_Registry::get("Zend_Locale");
                                         if (!in_array($currentLocale, $languagePermissions)) {
                                             continue;
                                         }
                                     }
                                 }
                             }
                         }
                         $objectData[$key] = $value;
                     }
                 }
                 $object->setValues($objectData);
                 $object->save();
                 $this->_helper->json(array("data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true));
             } catch (\Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         }
     } else {
         // get list of objects
         $folder = Object::getById($this->getParam("folderId"));
         $class = Object\ClassDefinition::getById($this->getParam("classId"));
         $className = $class->getName();
         $colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate");
         $start = 0;
         $limit = 20;
         $orderKey = "o_id";
         $order = "ASC";
         $fields = array();
         $bricks = array();
         if ($this->getParam("fields")) {
             $fields = $this->getParam("fields");
             foreach ($fields as $f) {
                 $parts = explode("~", $f);
                 $sub = substr($f, 0, 1);
                 if (substr($f, 0, 1) == "~") {
                     //                        $type = $parts[1];
                     //                        $field = $parts[2];
//.........这里部分代码省略.........
开发者ID:emanuel-london,项目名称:pimcore,代码行数:101,代码来源:ObjectController.php

示例2: getVariantsAction

 public function getVariantsAction()
 {
     // get list of variants
     if ($this->getParam("language")) {
         $this->setLanguage($this->getParam("language"), true);
     }
     if ($this->getParam("xaction") == "update") {
         $data = \Zend_Json::decode($this->getParam("data"));
         // save
         $object = Object::getById($data["id"]);
         if ($object->isAllowed("publish")) {
             $objectData = [];
             foreach ($data as $key => $value) {
                 $parts = explode("~", $key);
                 if (substr($key, 0, 1) == "~") {
                     $type = $parts[1];
                     $field = $parts[2];
                     $keyid = $parts[3];
                     $getter = "get" . ucfirst($field);
                     $setter = "set" . ucfirst($field);
                     $keyValuePairs = $object->{$getter}();
                     if (!$keyValuePairs) {
                         $keyValuePairs = new Object\Data\KeyValue();
                         $keyValuePairs->setObjectId($object->getId());
                         $keyValuePairs->setClass($object->getClass());
                     }
                     $keyValuePairs->setPropertyWithId($keyid, $value, true);
                     $object->{$setter}($keyValuePairs);
                 } elseif (count($parts) > 1) {
                     $brickType = $parts[0];
                     $brickKey = $parts[1];
                     $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                     $fieldGetter = "get" . ucfirst($brickField);
                     $brickGetter = "get" . ucfirst($brickType);
                     $valueSetter = "set" . ucfirst($brickKey);
                     $brick = $object->{$fieldGetter}()->{$brickGetter}();
                     if (empty($brick)) {
                         $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
                         $brickSetter = "set" . ucfirst($brickType);
                         $brick = new $classname($object);
                         $object->{$fieldGetter}()->{$brickSetter}($brick);
                     }
                     $brick->{$valueSetter}($value);
                 } else {
                     $objectData[$key] = $value;
                 }
             }
             $object->setValues($objectData);
             try {
                 $object->save();
                 $this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true]);
             } catch (\Exception $e) {
                 $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
             }
         } else {
             throw new \Exception("Permission denied");
         }
     } else {
         $parentObject = Object\Concrete::getById($this->getParam("objectId"));
         if (empty($parentObject)) {
             throw new \Exception("No Object found with id " . $this->getParam("objectId"));
         }
         if ($parentObject->isAllowed("view")) {
             $class = $parentObject->getClass();
             $className = $parentObject->getClass()->getName();
             $start = 0;
             $limit = 15;
             $orderKey = "o_id";
             $order = "ASC";
             $fields = [];
             $bricks = [];
             if ($this->getParam("fields")) {
                 $fields = $this->getParam("fields");
                 foreach ($fields as $f) {
                     $parts = explode("~", $f);
                     if (count($parts) > 1) {
                         $bricks[$parts[0]] = $parts[0];
                     }
                 }
             }
             if ($this->getParam("limit")) {
                 $limit = $this->getParam("limit");
             }
             if ($this->getParam("start")) {
                 $start = $this->getParam("start");
             }
             $orderKey = "o_id";
             $order = "ASC";
             $colMappings = ["filename" => "o_key", "fullpath" => ["o_path", "o_key"], "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"];
             $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
             if ($sortingSettings['orderKey'] && $sortingSettings['order']) {
                 $orderKey = $sortingSettings['orderKey'];
                 if (array_key_exists($orderKey, $colMappings)) {
                     $orderKey = $colMappings[$orderKey];
                 }
                 $order = $sortingSettings['order'];
             }
             if ($this->getParam("dir")) {
                 $order = $this->getParam("dir");
             }
//.........这里部分代码省略.........
开发者ID:solverat,项目名称:pimcore,代码行数:101,代码来源:VariantsController.php

示例3: batchAction

 public function batchAction()
 {
     $success = true;
     try {
         $object = Object::getById($this->getParam("job"));
         if ($object) {
             $className = $object->getClassName();
             $class = Object\ClassDefinition::getByName($className);
             $value = $this->getParam("value");
             if ($this->getParam("valueType") == "object") {
                 $value = \Zend_Json::decode($value);
             }
             $name = $this->getParam("name");
             $parts = explode("~", $name);
             if (substr($name, 0, 1) == "~") {
                 $type = $parts[1];
                 $field = $parts[2];
                 $keyid = $parts[3];
                 $getter = "get" . ucfirst($field);
                 $setter = "set" . ucfirst($field);
                 $keyValuePairs = $object->{$getter}();
                 if (!$keyValuePairs) {
                     $keyValuePairs = new Object\Data\KeyValue();
                     $keyValuePairs->setObjectId($object->getId());
                     $keyValuePairs->setClass($object->getClass());
                 }
                 $keyValuePairs->setPropertyWithId($keyid, $value, true);
                 $object->{$setter}($keyValuePairs);
             } else {
                 if (count($parts) > 1) {
                     // check for bricks
                     $brickType = $parts[0];
                     $brickKey = $parts[1];
                     $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                     $fieldGetter = "get" . ucfirst($brickField);
                     $brickGetter = "get" . ucfirst($brickType);
                     $valueSetter = "set" . ucfirst($brickKey);
                     $brick = $object->{$fieldGetter}()->{$brickGetter}();
                     if (empty($brick)) {
                         $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
                         $brickSetter = "set" . ucfirst($brickType);
                         $brick = new $classname($object);
                         $object->{$fieldGetter}()->{$brickSetter}($brick);
                     }
                     $brickClass = Object\Objectbrick\Definition::getByKey($brickType);
                     $field = $brickClass->getFieldDefinition($brickKey);
                     $brick->{$valueSetter}($field->getDataFromEditmode($value, $object));
                 } else {
                     // everything else
                     $field = $class->getFieldDefinition($name);
                     if ($field) {
                         $object->setValue($name, $field->getDataFromEditmode($value, $object));
                     } else {
                         // check if it is a localized field
                         if ($this->getParam("language")) {
                             $localizedField = $class->getFieldDefinition("localizedfields");
                             if ($localizedField) {
                                 $field = $localizedField->getFieldDefinition($name);
                                 if ($field) {
                                     $object->{"set" . $name}($value, $this->getParam("language"));
                                 }
                             }
                         }
                         // seems to be a system field, this is actually only possible for the "published" field yet
                         if ($name == "published") {
                             if ($value == "false" || empty($value)) {
                                 $object->setPublished(false);
                             } else {
                                 $object->setPublished(true);
                             }
                         }
                     }
                 }
             }
             try {
                 // don't check for mandatory fields here
                 $object->setOmitMandatoryCheck(true);
                 $object->setUserModification($this->getUser()->getId());
                 $object->save();
                 $success = true;
             } catch (\Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         } else {
             \Logger::debug("ObjectController::batchAction => There is no object left to update.");
             $this->_helper->json(array("success" => false, "message" => "ObjectController::batchAction => There is no object left to update."));
         }
     } catch (\Exception $e) {
         \Logger::err($e);
         $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
     }
     $this->_helper->json(array("success" => $success));
 }
开发者ID:cannonerd,项目名称:pimcore,代码行数:93,代码来源:ObjectHelperController.php

示例4: gridProxyAction

 public function gridProxyAction()
 {
     $requestedLanguage = $this->getParam("language");
     if ($requestedLanguage) {
         if ($requestedLanguage != "default") {
             $this->setLanguage($requestedLanguage, true);
         }
     } else {
         $requestedLanguage = $this->getLanguage();
     }
     if ($this->getParam("data")) {
         if ($this->getParam("xaction") == "update") {
             try {
                 $data = \Zend_Json::decode($this->getParam("data"));
                 // save
                 $object = Object::getById($data["id"]);
                 /** @var Object\ClassDefinition $class */
                 $class = $object->getClass();
                 if (!$object->isAllowed("publish")) {
                     throw new \Exception("Permission denied. You don't have the rights to save this object.");
                 }
                 $user = Tool\Admin::getCurrentUser();
                 $allLanguagesAllowed = false;
                 if (!$user->isAdmin()) {
                     $languagePermissions = $object->getPermissions("lEdit", $user);
                     //sets allowed all languages modification when the lEdit column is empty
                     $allLanguagesAllowed = $languagePermissions["lEdit"] == '';
                     $languagePermissions = explode(",", $languagePermissions["lEdit"]);
                 }
                 $objectData = [];
                 foreach ($data as $key => $value) {
                     $parts = explode("~", $key);
                     if (substr($key, 0, 1) == "~") {
                         $type = $parts[1];
                         $field = $parts[2];
                         $keyid = $parts[3];
                         if ($type == "classificationstore") {
                             $groupKeyId = explode("-", $keyid);
                             $groupId = $groupKeyId[0];
                             $keyid = $groupKeyId[1];
                             $getter = "get" . ucfirst($field);
                             if (method_exists($object, $getter)) {
                                 /** @var  $classificationStoreData Object\Classificationstore */
                                 $classificationStoreData = $object->{$getter}();
                                 $classificationStoreData->setLocalizedKeyValue($groupId, $keyid, $value, $requestedLanguage);
                             }
                         } else {
                             $getter = "get" . ucfirst($field);
                             $setter = "set" . ucfirst($field);
                             $keyValuePairs = $object->{$getter}();
                             if (!$keyValuePairs) {
                                 $keyValuePairs = new Object\Data\KeyValue();
                                 $keyValuePairs->setObjectId($object->getId());
                                 $keyValuePairs->setClass($object->getClass());
                             }
                             $keyValuePairs->setPropertyWithId($keyid, $value, true);
                             $object->{$setter}($keyValuePairs);
                         }
                     } elseif (count($parts) > 1) {
                         $brickType = $parts[0];
                         $brickKey = $parts[1];
                         $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                         $fieldGetter = "get" . ucfirst($brickField);
                         $brickGetter = "get" . ucfirst($brickType);
                         $valueSetter = "set" . ucfirst($brickKey);
                         $brick = $object->{$fieldGetter}()->{$brickGetter}();
                         if (empty($brick)) {
                             $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
                             $brickSetter = "set" . ucfirst($brickType);
                             $brick = new $classname($object);
                             $object->{$fieldGetter}()->{$brickSetter}($brick);
                         }
                         $brick->{$valueSetter}($value);
                     } else {
                         if (!$user->isAdmin() && $languagePermissions) {
                             $fd = $class->getFieldDefinition($key);
                             if (!$fd) {
                                 // try to get via localized fields
                                 $localized = $class->getFieldDefinition("localizedfields");
                                 if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) {
                                     $field = $localized->getFieldDefinition($key);
                                     if ($field) {
                                         $currentLocale = (string) \Zend_Registry::get("Zend_Locale");
                                         if (!$allLanguagesAllowed && !in_array($currentLocale, $languagePermissions)) {
                                             continue;
                                         }
                                     }
                                 }
                             }
                         }
                         $objectData[$key] = $value;
                     }
                 }
                 $object->setValues($objectData);
                 $object->save();
                 $this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields"), $requestedLanguage), "success" => true]);
             } catch (\Exception $e) {
                 $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
             }
         }
//.........这里部分代码省略.........
开发者ID:pimcore,项目名称:pimcore,代码行数:101,代码来源:ObjectController.php


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