Admin_SettingsController::staticroutesAction PHP Метод

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

public staticroutesAction ( )
    public function staticroutesAction()
    {
        if ($this->getParam("data")) {
            $this->checkPermission("routes");
            $data = \Zend_Json::decode($this->getParam("data"));
            if (is_array($data)) {
                foreach ($data as &$value) {
                    if (is_string($value)) {
                        $value = trim($value);
                    }
                }
            }
            if ($this->getParam("xaction") == "destroy") {
                $data = \Zend_Json::decode($this->getParam("data"));
                if (\Pimcore\Tool\Admin::isExtJS6()) {
                    $id = $data["id"];
                } else {
                    $id = $data;
                }
                $route = Staticroute::getById($id);
                $route->delete();
                $this->_helper->json(["success" => true, "data" => []]);
            } elseif ($this->getParam("xaction") == "update") {
                // save routes
                $route = Staticroute::getById($data["id"]);
                $route->setValues($data);
                $route->save();
                $this->_helper->json(["data" => $route, "success" => true]);
            } elseif ($this->getParam("xaction") == "create") {
                unset($data["id"]);
                // save route
                $route = new Staticroute();
                $route->setValues($data);
                $route->save();
                $this->_helper->json(["data" => $route, "success" => true]);
            }
        } else {
            // get list of routes
            $list = new Staticroute\Listing();
            if ($this->getParam("filter")) {
                $filter = $this->getParam("filter");
                $list->setFilter(function ($row) use($filter) {
                    foreach ($row as $value) {
                        if (strpos($value, $filter) !== false) {
                            return true;
                        }
                    }
                    return false;
                });
            }
            $list->load();
            $routes = [];
            foreach ($list->getRoutes() as $route) {
                $routes[] = $route;
            }
            $this->_helper->json(["data" => $routes, "success" => true, "total" => $list->getTotalCount()]);
        }
        $this->_helper->json(false);
    }