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


PHP Service::getLanguagePermissions方法代码示例

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


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

示例1: saveAction

 public function saveAction()
 {
     $object = Object::getById($this->getParam("id"));
     // set the latest available version for editmode
     $object = $this->getLatestVersion($object);
     $object->setUserModification($this->getUser()->getId());
     // data
     if ($this->getParam("data")) {
         $data = \Zend_Json::decode($this->getParam("data"));
         foreach ($data as $key => $value) {
             $fd = $object->getClass()->getFieldDefinition($key);
             if ($fd) {
                 if ($fd instanceof Object\ClassDefinition\Data\Localizedfields) {
                     $user = Tool\Admin::getCurrentUser();
                     if (!$user->getAdmin()) {
                         $allowedLanguages = Object\Service::getLanguagePermissions($object, $user, "lEdit");
                         if (!is_null($allowedLanguages)) {
                             $allowedLanguages = array_keys($allowedLanguages);
                             $submittedLanguages = array_keys($data[$key]);
                             foreach ($submittedLanguages as $submittedLanguage) {
                                 if (!in_array($submittedLanguage, $allowedLanguages)) {
                                     unset($value[$submittedLanguage]);
                                 }
                             }
                         }
                     }
                 }
                 if (method_exists($fd, "isRemoteOwner") and $fd->isRemoteOwner()) {
                     $remoteClass = Object\ClassDefinition::getByName($fd->getOwnerClassName());
                     $relations = $object->getRelationData($fd->getOwnerFieldName(), false, $remoteClass->getId());
                     $toAdd = $this->detectAddedRemoteOwnerRelations($relations, $value);
                     $toDelete = $this->detectDeletedRemoteOwnerRelations($relations, $value);
                     if (count($toAdd) > 0 or count($toDelete) > 0) {
                         $this->processRemoteOwnerRelations($object, $toDelete, $toAdd, $fd->getOwnerFieldName());
                     }
                 } else {
                     $object->setValue($key, $fd->getDataFromEditmode($value, $object));
                 }
             }
         }
     }
     // general settings
     // @TODO: IS THIS STILL NECESSARY?
     if ($this->getParam("general")) {
         $general = \Zend_Json::decode($this->getParam("general"));
         // do not allow all values to be set, will cause problems (eg. icon)
         if (is_array($general) && count($general) > 0) {
             foreach ($general as $key => $value) {
                 if (!in_array($key, array("o_id", "o_classId", "o_className", "o_type", "icon", "o_userOwner", "o_userModification"))) {
                     $object->setValue($key, $value);
                 }
             }
         }
     }
     $object = $this->assignPropertiesFromEditmode($object);
     // scheduled tasks
     if ($this->getParam("scheduler")) {
         $tasks = array();
         $tasksData = \Zend_Json::decode($this->getParam("scheduler"));
         if (!empty($tasksData)) {
             foreach ($tasksData as $taskData) {
                 $taskData["date"] = strtotime($taskData["date"] . " " . $taskData["time"]);
                 $task = new Model\Schedule\Task($taskData);
                 $tasks[] = $task;
             }
         }
         $object->setScheduledTasks($tasks);
     }
     if ($this->getParam("task") == "unpublish") {
         $object->setPublished(false);
     }
     if ($this->getParam("task") == "publish") {
         $object->setPublished(true);
     }
     // unpublish and save version is possible without checking mandatory fields
     if ($this->getParam("task") == "unpublish" || $this->getParam("task") == "version") {
         $object->setOmitMandatoryCheck(true);
     }
     if ($this->getParam("task") == "publish" && $object->isAllowed("publish") or $this->getParam("task") == "unpublish" && $object->isAllowed("unpublish")) {
         try {
             $object->save();
             $treeData = array();
             $treeData["qtipCfg"] = $object->getElementAdminStyle()->getElementQtipConfig();
             $this->_helper->json(array("success" => true, "treeData" => $treeData));
         } catch (\Exception $e) {
             \Logger::log($e);
             $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
         }
     } elseif ($this->getParam("task") == "session") {
         //$object->_fulldump = true; // not working yet, donno why
         Tool\Session::useSession(function ($session) use($object) {
             $key = "object_" . $object->getId();
             $session->{$key} = $object;
         }, "pimcore_objects");
         $this->_helper->json(array("success" => true));
     } else {
         if ($object->isAllowed("save")) {
             try {
                 $object->saveVersion();
                 $this->_helper->json(array("success" => true));
//.........这里部分代码省略.........
开发者ID:emanuel-london,项目名称:pimcore,代码行数:101,代码来源:ObjectController.php

示例2: getFromWebserviceImport

 /**
  * @param mixed $value
  * @param null $object
  * @param null $idMapper
  * @return mixed|null|Object\Localizedfield
  * @throws \Exception
  */
 public function getFromWebserviceImport($value, $object = null, $idMapper = null)
 {
     if (is_array($value)) {
         $validLanguages = Tool::getValidLanguages();
         if (!$idMapper || !$idMapper->ignoreMappingFailures()) {
             foreach ($value as $v) {
                 if (!in_array($v->language, $validLanguages)) {
                     throw new \Exception("Invalid language in localized fields");
                 }
             }
         }
         $localizedFields = $object->getLocalizedFields();
         if (!$localizedFields) {
             $localizedFields = new Object\Localizedfield();
         }
         if ($object instanceof Object\Concrete) {
             $localizedFields->setObject($object);
         }
         $user = Tool\Admin::getCurrentUser();
         $languagesAllowed = null;
         if ($user && !$user->isAdmin()) {
             $languagesAllowed = Object\Service::getLanguagePermissions($object, $user, "lEdit");
             if ($languagesAllowed) {
                 $languagesAllowed = array_keys($languagesAllowed);
             }
         }
         foreach ($value as $field) {
             if ($field instanceof \stdClass) {
                 $field = Tool\Cast::castToClass("\\Pimcore\\Model\\Webservice\\Data\\Object\\Element", $field);
             }
             if ($idMapper && $idMapper->ignoreMappingFailures()) {
                 if (!in_array($field->language, $validLanguages)) {
                     continue;
                 }
             }
             if ($languagesAllowed && !in_array($field->language, $languagesAllowed)) {
                 //TODO needs to be discussed. Maybe it is better to throw an exception instead of ignoring
                 //the language
                 continue;
             }
             if (!$field instanceof Model\Webservice\Data\Object\Element) {
                 throw new \Exception("Invalid import data in field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]");
             }
             $fd = $this->getFielddefinition($field->name);
             if (!$fd instanceof Object\ClassDefinition\Data) {
                 if ($idMapper && $idMapper->ignoreMappingFailures()) {
                     continue;
                 }
                 throw new \Exception("Unknown field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ] ");
             } else {
                 if ($fd->getFieldtype() != $field->type) {
                     throw new \Exception("Type mismatch for field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]. Should be [ " . $fd->getFieldtype() . " ], but is [ " . $field->type . " ] ");
                 }
             }
             $localizedFields->setLocalizedValue($field->name, $this->getFielddefinition($field->name)->getFromWebserviceImport($field->value, $object, $idMapper), $field->language);
         }
         return $localizedFields;
     } else {
         if (!empty($value)) {
             throw new \Exception("Invalid data in localized fields");
         } else {
             return null;
         }
     }
 }
开发者ID:yonetici,项目名称:pimcore-coreshop-demo,代码行数:72,代码来源:Localizedfields.php


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