Ejemplo n.º 1
0
 /**
  * Get a list of the sibling assets
  *
  * @return array
  */
 public function getSiblings()
 {
     if ($this->siblings === null) {
         $list = new Asset\Listing();
         // string conversion because parentId could be 0
         $list->addConditionParam("parentId = ?", (string) $this->getParentId());
         $list->addConditionParam("id != ?", $this->getId());
         $list->setOrderKey("filename");
         $list->setOrder("asc");
         $this->siblings = $list->load();
     }
     return $this->siblings;
 }
 public function gridProxyAction()
 {
     if ($this->getParam("data")) {
         if ($this->getParam("xaction") == "update") {
             //TODO probably not needed
         }
     } else {
         $db = \Pimcore\Resource::get();
         // get list of objects
         $folder = Asset::getById($this->getParam("folderId"));
         $start = 0;
         $limit = 20;
         $orderKey = "id";
         $order = "ASC";
         if ($this->getParam("limit")) {
             $limit = $this->getParam("limit");
         }
         if ($this->getParam("start")) {
             $start = $this->getParam("start");
         }
         if ($this->getParam("dir")) {
             $order = $this->getParam("dir");
         }
         if ($this->getParam("sort")) {
             $orderKey = $this->getParam("sort");
             if ($orderKey == "fullpath") {
                 $orderKey = array("path", "filename");
             }
         }
         $conditionFilters = array();
         if ($this->getParam("only_direct_children") == "true") {
             $conditionFilters[] = "parentId = " . $folder->getId();
         } else {
             $conditionFilters[] = "path LIKE '" . ($folder->getFullPath() == "/" ? "/%'" : $folder->getFullPath() . "/%'");
         }
         $conditionFilters[] = "type != 'folder'";
         $filterJson = $this->getParam("filter");
         if ($filterJson) {
             $filters = \Zend_Json::decode($filterJson);
             foreach ($filters as $filter) {
                 $operator = "=";
                 if ($filter["type"] == "string") {
                     $operator = "LIKE";
                 } else {
                     if ($filter["type"] == "numeric") {
                         if ($filter["comparison"] == "lt") {
                             $operator = "<";
                         } else {
                             if ($filter["comparison"] == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filter["comparison"] == "eq") {
                                     $operator = "=";
                                 }
                             }
                         }
                     } else {
                         if ($filter["type"] == "date") {
                             if ($filter["comparison"] == "lt") {
                                 $operator = "<";
                             } else {
                                 if ($filter["comparison"] == "gt") {
                                     $operator = ">";
                                 } else {
                                     if ($filter["comparison"] == "eq") {
                                         $operator = "=";
                                     }
                                 }
                             }
                             $filter["value"] = strtotime($filter["value"]);
                         } else {
                             if ($filter["type"] == "list") {
                                 $operator = "=";
                             } else {
                                 if ($filter["type"] == "boolean") {
                                     $operator = "=";
                                     $filter["value"] = (int) $filter["value"];
                                 }
                             }
                         }
                     }
                 }
                 // system field
                 $value = $filter["value"];
                 if ($operator == "LIKE") {
                     $value = "%" . $value . "%";
                 }
                 $field = "`" . $filter["field"] . "` ";
                 if ($filter["field"] == "fullpath") {
                     $field = "CONCAT(path,filename)";
                 }
                 $conditionFilters[] = $field . $operator . " " . $db->quote($value);
             }
         }
         $list = new Asset\Listing();
         $condition = implode(" AND ", $conditionFilters);
         $list->setCondition($condition);
         $list->setLimit($limit);
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $list->load();
         $assets = array();
         foreach ($list->getAssets() as $asset) {
             /** @var $asset Asset */
             $filename = PIMCORE_ASSET_DIRECTORY . "/" . $asset->getFullPath();
             $size = filesize($filename);
             $assets[] = array("id" => $asset->getid(), "type" => $asset->getType(), "fullpath" => $asset->getFullPath(), "creationDate" => $asset->getCreationDate(), "modificationDate" => $asset->getModificationDate(), "size" => formatBytes($size), "idPath" => $data["idPath"] = Element\Service::getIdPath($asset));
         }
         $this->_helper->json(array("data" => $assets, "success" => true, "total" => $list->getTotalCount()));
     }
 }