/**
  * Produces the json to feed the dynamic dropdown
  * Used by pimcore.object.tags.dynamicDropdown
  */
 public function optionsAction()
 {
     $filter = new \Zend_Filter_PregReplace(array("match" => "@[^a-zA-Z0-9/\\-_]@", "replace" => ""));
     $parentFolderPath = $filter->filter($this->_getParam("source_parent"));
     if ($parentFolderPath) {
         // remove trailing slash
         if ($parentFolderPath != "/") {
             $parentFolderPath = rtrim($parentFolderPath, "/ ");
         }
         // correct wrong path (root-node problem)
         $parentFolderPath = str_replace("//", "/", $parentFolderPath);
         $folder = Object_Folder::getByPath($parentFolderPath);
         if ($folder) {
             $options = $this->walk_path($folder);
         } else {
             Logger::warning("The folder submitted for could not be found: \"" . $this->_getParam("source_parent") . "\"");
         }
     } else {
         Logger::warning("The folder submitted for source_parent is not valid: \"" . $this->_getParam("source_parent") . "\"");
     }
     $sort = $this->_getParam("sort_by");
     usort($options, function ($a, $b) use($sort) {
         $field = "id";
         if ($sort == "byvalue") {
             $field = "key";
         }
         if ($a[$field] == $b[$field]) {
             return 0;
         }
         return $a[$field] < $b[$field] ? 0 : 1;
     });
     $this->_helper->json($options);
 }
Exemplo n.º 2
0
 public function removeFolders()
 {
     $blogFolder = Object_Folder::getByPath('/blog');
     if ($blogFolder) {
         $blogFolder->delete();
     }
 }
 /**
  * @param $folderPath
  *
  * @return mixed
  * @throws Exception
  *
  * Runs each level of the folder-path and checks if it is already existing in pimcore
  */
 protected function checkFolderPath($folderPath)
 {
     $folderObject = Object_Folder::getByPath($folderPath);
     if (!is_object($folderObject)) {
         $folderPathArray = explode('/', $folderPath);
         $growingPath = '';
         foreach ($folderPathArray as $folderName) {
             $folderObject = Object_Folder::getByPath($growingPath . '/' . $folderName);
             if (!is_object($folderObject) && !method_exists($folderObject, 'getId')) {
                 try {
                     $parentFolder = Object_Folder::getByPath($growingPath);
                     if (is_object($parentFolder)) {
                         $parentId = $parentFolder->getId();
                         $parentFolder = Object_Folder::create(array('type' => 'folder', 'key' => $folderName, 'parentId' => $parentId));
                     }
                 } catch (Exception $e) {
                     throw $e;
                 }
             }
             $growingPath .= '/' . $folderName;
         }
     }
     if (is_object($folderObject)) {
         return $folderObject;
     } else {
         return $parentFolder;
     }
 }