Admin_AssetController::gridProxyAction PHP Метод

gridProxyAction() публичный Метод

public gridProxyAction ( )
    public function gridProxyAction()
    {
        if ($this->getParam("data")) {
            if ($this->getParam("xaction") == "update") {
                //TODO probably not needed
            }
        } else {
            $db = \Pimcore\Db::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");
            }
            $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
            if ($sortingSettings['orderKey']) {
                $orderKey = $sortingSettings['orderKey'];
                if ($orderKey == "fullpath") {
                    $orderKey = ["path", "filename"];
                }
                $order = $sortingSettings['order'];
            }
            $conditionFilters = [];
            if ($this->getParam("only_direct_children") == "true") {
                $conditionFilters[] = "parentId = " . $folder->getId();
            } else {
                $conditionFilters[] = "path LIKE '" . ($folder->getRealFullPath() == "/" ? "/%'" : $folder->getRealFullPath() . "/%'");
            }
            $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";
                    } elseif ($filter["type"] == "numeric") {
                        if ($filter["comparison"] == "lt") {
                            $operator = "<";
                        } elseif ($filter["comparison"] == "gt") {
                            $operator = ">";
                        } elseif ($filter["comparison"] == "eq") {
                            $operator = "=";
                        }
                    } elseif ($filter["type"] == "date") {
                        if ($filter["comparison"] == "lt") {
                            $operator = "<";
                        } elseif ($filter["comparison"] == "gt") {
                            $operator = ">";
                        } elseif ($filter["comparison"] == "eq") {
                            $operator = "=";
                        }
                        $filter["value"] = strtotime($filter["value"]);
                    } elseif ($filter["type"] == "list") {
                        $operator = "=";
                    } elseif ($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 = [];
            foreach ($list->getAssets() as $asset) {
                /** @var $asset Asset */
                $filename = PIMCORE_ASSET_DIRECTORY . "/" . $asset->getRealFullPath();
                $size = @filesize($filename);
                $assets[] = ["id" => $asset->getid(), "type" => $asset->getType(), "fullpath" => $asset->getRealFullPath(), "creationDate" => $asset->getCreationDate(), "modificationDate" => $asset->getModificationDate(), "size" => formatBytes($size), "idPath" => $data["idPath"] = Element\Service::getIdPath($asset)];
            }
            $this->_helper->json(["data" => $assets, "success" => true, "total" => $list->getTotalCount()]);
        }
    }