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


PHP Service::getValidKey方法代码示例

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


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

示例1: setName

 /**
  * @param string $name
  * @return $this|void
  * @throws DAV\Exception\Forbidden
  * @throws \Exception
  */
 public function setName($name)
 {
     if ($this->asset->isAllowed("rename")) {
         $user = AdminTool::getCurrentUser();
         $this->asset->setUserModification($user->getId());
         $this->asset->setFilename(Element\Service::getValidKey($name), "asset");
         $this->asset->save();
     } else {
         throw new DAV\Exception\Forbidden();
     }
     return $this;
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:18,代码来源:File.php

示例2: move

 /**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = Element\Service::getValidKey($nameParts[count($nameParts) - 1], "asset");
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = Element\Service::getValidKey($nameParts[count($nameParts) - 1], "asset");
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             $asset = null;
             if ($asset = Asset::getByPath("/" . $destinationPath)) {
                 // If we got here, this means the destination exists, and needs to be overwritten
                 $sourceAsset = Asset::getByPath("/" . $sourcePath);
                 $asset->setData($sourceAsset->getData());
                 $sourceAsset->delete();
             }
             // see: Asset\WebDAV\File::delete() why this is necessary
             $log = Asset\WebDAV\Service::getDeleteLog();
             if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
                 $asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
                 if ($asset) {
                     $sourceAsset = Asset::getByPath("/" . $sourcePath);
                     $asset->setData($sourceAsset->getData());
                     $sourceAsset->delete();
                 }
             }
             if (!$asset) {
                 $asset = Asset::getByPath("/" . $sourcePath);
             }
             $asset->setFilename(basename($destinationPath));
         } else {
             $asset = Asset::getByPath("/" . $sourcePath);
             $parent = Asset::getByPath("/" . dirname($destinationPath));
             $asset->setPath($parent->getRealFullPath() . "/");
             $asset->setParentId($parent->getId());
         }
         $user = \Pimcore\Tool\Admin::getCurrentUser();
         $asset->setUserModification($user->getId());
         $asset->save();
     } catch (\Exception $e) {
         Logger::error($e);
     }
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:51,代码来源:Tree.php

示例3: getValidFilenameAction

 public function getValidFilenameAction()
 {
     $this->_helper->json(["filename" => \Pimcore\Model\Element\Service::getValidKey($this->getParam("value"), $this->getParam("type"))]);
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:4,代码来源:MiscController.php

示例4: getUniqueKey

 public static function getUniqueKey($item, $nr = 0)
 {
     $list = new Listing();
     $list->setUnpublished(true);
     $key = Element\Service::getValidKey($item->getKey(), "object");
     if (!$key) {
         throw new \Exception("No item key set.");
     }
     if ($nr) {
         $key = $key . '_' . $nr;
     }
     $parent = $item->getParent();
     if (!$parent) {
         throw new \Exception("You have to set a parent Object to determine a unique Key");
     }
     if (!$item->getId()) {
         $list->setCondition('o_parentId = ? AND `o_key` = ? ', [$parent->getId(), $key]);
     } else {
         $list->setCondition('o_parentId = ? AND `o_key` = ? AND o_id != ? ', [$parent->getId(), $key, $item->getId()]);
     }
     $check = $list->loadIdList();
     if (!empty($check)) {
         $nr++;
         $key = self::getUniqueKey($item, $nr);
     }
     return $key;
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:27,代码来源:Service.php

示例5: importUrlAction

 public function importUrlAction()
 {
     $success = true;
     $data = Tool::getHttpData($this->getParam("url"));
     $filename = basename($this->getParam("url"));
     $parentId = $this->getParam("id");
     $parentAsset = Asset::getById(intval($parentId));
     $filename = Element\Service::getValidKey($filename, "asset");
     $filename = $this->getSafeFilename($parentAsset->getRealFullPath(), $filename);
     if (empty($filename)) {
         throw new \Exception("The filename of the asset is empty");
     }
     // check for duplicate filename
     $filename = $this->getSafeFilename($parentAsset->getRealFullPath(), $filename);
     if ($parentAsset->isAllowed("create")) {
         $asset = Asset::create($parentId, ["filename" => $filename, "data" => $data, "userOwner" => $this->user->getId(), "userModification" => $this->user->getId()]);
         $success = true;
     } else {
         Logger::debug("prevented creating asset because of missing permissions");
     }
     $this->_helper->json(["success" => $success]);
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:22,代码来源:AssetController.php

示例6: setName

 /**
  * @param string $name
  * @return $this|void
  * @throws DAV\Exception\Forbidden
  * @throws \Exception
  */
 public function setName($name)
 {
     if ($this->asset->isAllowed("rename")) {
         $this->asset->setFilename(Element\Service::getValidKey($name, "asset"));
         $this->asset->save();
     } else {
         throw new DAV\Exception\Forbidden();
     }
     return $this;
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:16,代码来源:Folder.php

示例7: map

 private static function map($wsData, $data)
 {
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $tmp = [];
             foreach ($value as $subkey => $subvalue) {
                 if (is_array($subvalue)) {
                     $object = new stdClass();
                     $object = self::map($object, $subvalue);
                     $tmp[$subkey] = $object;
                 } else {
                     $tmp[$subkey] = $subvalue;
                 }
             }
             $value = $tmp;
         }
         $wsData->{$key} = $value;
     }
     if ($wsData instanceof Pimcore\Model\Webservice\Data\Object) {
         /** @var Pimcore\Model\Webservice\Data\Object key */
         $wsData->key = Element\Service::getValidKey($wsData->key, "object");
     } elseif ($wsData instanceof Pimcore\Model\Webservice\Data\Document) {
         /** @var Pimcore\Model\Webservice\Data\Document key */
         $wsData->key = Element\Service::getValidKey($wsData->key, "document");
     } elseif ($wsData instanceof Pimcore\Model\Webservice\Data\Asset) {
         /** @var Pimcore\Model\Webservice\Data\Asset $wsData */
         $wsData->filename = Element\Service::getValidKey($wsData->filename, "asset");
     }
     return $wsData;
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:30,代码来源:RestController.php

示例8: addAction

 public function addAction()
 {
     $success = false;
     $errorMessage = "";
     // check for permission
     $parentDocument = Document::getById(intval($this->getParam("parentId")));
     if ($parentDocument->isAllowed("create")) {
         $intendedPath = $parentDocument->getRealFullPath() . "/" . $this->getParam("key");
         if (!Document\Service::pathExists($intendedPath)) {
             $createValues = ["userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId(), "published" => false];
             $createValues["key"] = \Pimcore\Model\Element\Service::getValidKey($this->getParam("key"), "document");
             // check for a docType
             $docType = Document\DocType::getById(intval($this->getParam("docTypeId")));
             if ($docType) {
                 $createValues["template"] = $docType->getTemplate();
                 $createValues["controller"] = $docType->getController();
                 $createValues["action"] = $docType->getAction();
                 $createValues["module"] = $docType->getModule();
             } elseif ($this->getParam("translationsBaseDocument")) {
                 $translationsBaseDocument = Document::getById($this->getParam("translationsBaseDocument"));
                 $createValues["template"] = $translationsBaseDocument->getTemplate();
                 $createValues["controller"] = $translationsBaseDocument->getController();
                 $createValues["action"] = $translationsBaseDocument->getAction();
                 $createValues["module"] = $translationsBaseDocument->getModule();
             } elseif ($this->getParam("type") == "page" || $this->getParam("type") == "snippet" || $this->getParam("type") == "email") {
                 $createValues["controller"] = Config::getSystemConfig()->documents->default_controller;
                 $createValues["action"] = Config::getSystemConfig()->documents->default_action;
             }
             if ($this->getParam("inheritanceSource")) {
                 $createValues["contentMasterDocumentId"] = $this->getParam("inheritanceSource");
             }
             switch ($this->getParam("type")) {
                 case "page":
                     $document = Document\Page::create($this->getParam("parentId"), $createValues, false);
                     $document->setTitle($this->getParam('title', null));
                     $document->setProperty("navigation_name", "text", $this->getParam('name', null), false);
                     $document->save();
                     $success = true;
                     break;
                 case "snippet":
                     $document = Document\Snippet::create($this->getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "email":
                     //ckogler
                     $document = Document\Email::create($this->getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "link":
                     $document = Document\Link::create($this->getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "hardlink":
                     $document = Document\Hardlink::create($this->getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "folder":
                     $document = Document\Folder::create($this->getParam("parentId"), $createValues);
                     $document->setPublished(true);
                     try {
                         $document->save();
                         $success = true;
                     } catch (\Exception $e) {
                         $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                     }
                     break;
                 default:
                     $classname = "\\Pimcore\\Model\\Document\\" . ucfirst($this->getParam("type"));
                     // this is the fallback for custom document types using prefixes
                     // so we need to check if the class exists first
                     if (!\Pimcore\Tool::classExists($classname)) {
                         $oldStyleClass = "\\Document_" . ucfirst($this->getParam("type"));
                         if (\Pimcore\Tool::classExists($oldStyleClass)) {
                             $classname = $oldStyleClass;
                         }
                     }
                     if (Tool::classExists($classname)) {
                         $document = $classname::create($this->getParam("parentId"), $createValues);
                         try {
                             $document->save();
                             $success = true;
                         } catch (\Exception $e) {
                             $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                         }
                         break;
                     } else {
                         Logger::debug("Unknown document type, can't add [ " . $this->getParam("type") . " ] ");
                     }
                     break;
             }
         } else {
             $errorMessage = "prevented adding a document because document with same path+key [ {$intendedPath} ] already exists";
             Logger::debug($errorMessage);
         }
     } else {
         $errorMessage = "prevented adding a document because of missing permissions";
         Logger::debug($errorMessage);
     }
     if ($success) {
         if ($this->getParam("translationsBaseDocument")) {
//.........这里部分代码省略.........
开发者ID:pimcore,项目名称:pimcore,代码行数:101,代码来源:DocumentController.php

示例9: importProcessAction

 public function importProcessAction()
 {
     $success = true;
     $parentId = $this->getParam("parentId");
     $job = $this->getParam("job");
     $id = $this->getParam("id");
     $mappingRaw = \Zend_Json::decode($this->getParam("mapping"));
     $class = Object\ClassDefinition::getById($this->getParam("classId"));
     $skipFirstRow = $this->getParam("skipHeadRow") == "true";
     $fields = $class->getFieldDefinitions();
     $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id;
     // currently only csv supported
     // determine type
     $dialect = Tool\Admin::determineCsvDialect(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id . "_original");
     $count = 0;
     if (($handle = fopen($file, "r")) !== false) {
         $data = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
     }
     if ($skipFirstRow && $job == 1) {
         //read the next row, we need to skip the head row
         $data = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
     }
     $tmpFile = $file . "_tmp";
     $tmpHandle = fopen($tmpFile, "w+");
     while (!feof($handle)) {
         $buffer = fgets($handle);
         fwrite($tmpHandle, $buffer);
     }
     fclose($handle);
     fclose($tmpHandle);
     unlink($file);
     rename($tmpFile, $file);
     // prepare mapping
     foreach ($mappingRaw as $map) {
         if ($map[0] !== "" && $map[1] && !empty($map[2])) {
             $mapping[$map[2]] = $map[0];
         } elseif ($map[1] == "published (system)") {
             $mapping["published"] = $map[0];
         } elseif ($map[1] == "type (system)") {
             $mapping["type"] = $map[0];
         }
     }
     // create new object
     $className = "Pimcore\\Model\\Object\\" . ucfirst($this->getParam("className"));
     $parent = Object::getById($this->getParam("parentId"));
     $objectKey = "object_" . $job;
     if ($this->getParam("filename") == "id") {
         $objectKey = null;
     } elseif ($this->getParam("filename") != "default") {
         $objectKey = Element\Service::getValidKey($data[$this->getParam("filename")], "object");
     }
     $overwrite = false;
     if ($this->getParam("overwrite") == "true") {
         $overwrite = true;
     }
     if ($parent->isAllowed("create")) {
         $intendedPath = $parent->getRealFullPath() . "/" . $objectKey;
         if ($overwrite) {
             $object = Object::getByPath($intendedPath);
             if (!$object instanceof Object\Concrete) {
                 //create new object
                 $object = \Pimcore::getDiContainer()->make($className);
             } elseif ($object instanceof Object\Concrete and !$object instanceof $className) {
                 //delete the old object it is of a different class
                 $object->delete();
                 $object = \Pimcore::getDiContainer()->make($className);
             } elseif ($object instanceof Object\Folder) {
                 //delete the folder
                 $object->delete();
                 $object = \Pimcore::getDiContainer()->make($className);
             } else {
                 //use the existing object
             }
         } else {
             $counter = 1;
             while (Object::getByPath($intendedPath) != null) {
                 $objectKey .= "_" . $counter;
                 $intendedPath = $parent->getRealFullPath() . "/" . $objectKey;
                 $counter++;
             }
             $object = new $className();
         }
         $object->setClassId($this->getParam("classId"));
         $object->setClassName($this->getParam("className"));
         $object->setParentId($this->getParam("parentId"));
         $object->setKey($objectKey);
         $object->setCreationDate(time());
         $object->setUserOwner($this->getUser()->getId());
         $object->setUserModification($this->getUser()->getId());
         if (in_array($data[$mapping["type"]], ["object", "variant"])) {
             $object->setType($data[$mapping["type"]]);
         } else {
             $object->setType("object");
         }
         if ($data[$mapping["published"]] === "1") {
             $object->setPublished(true);
         } else {
             $object->setPublished(false);
         }
         foreach ($class->getFieldDefinitions() as $key => $field) {
//.........这里部分代码省略.........
开发者ID:pimcore,项目名称:pimcore,代码行数:101,代码来源:ObjectHelperController.php


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