Ejemplo n.º 1
0
 public function staticroutesAction()
 {
     if ($this->_getParam("data")) {
         if ($this->getUser()->isAllowed("routes")) {
             if ($this->_getParam("xaction") == "destroy") {
                 $id = Zend_Json::decode($this->_getParam("data"));
                 $route = Staticroute::getById($id);
                 $route->delete();
                 $this->_helper->json(array("success" => true, "data" => array()));
             } else {
                 if ($this->_getParam("xaction") == "update") {
                     $data = Zend_Json::decode($this->_getParam("data"));
                     // save routes
                     $route = Staticroute::getById($data["id"]);
                     $route->setValues($data);
                     $route->save();
                     $this->_helper->json(array("data" => $route, "success" => true));
                 } else {
                     if ($this->_getParam("xaction") == "create") {
                         $data = Zend_Json::decode($this->_getParam("data"));
                         unset($data["id"]);
                         // save route
                         $route = new Staticroute();
                         $route->setValues($data);
                         $route->save();
                         $this->_helper->json(array("data" => $route, "success" => true));
                     }
                 }
             }
         } else {
             Logger::err("user [" . $this->getUser()->getId() . "] attempted to modify static routes, but has no permission to do so.");
         }
     } else {
         // get list of routes
         $list = new Staticroute_List();
         $list->setLimit($this->_getParam("limit"));
         $list->setOffset($this->_getParam("start"));
         if ($this->_getParam("sort")) {
             $list->setOrderKey($this->_getParam("sort"));
             $list->setOrder($this->_getParam("dir"));
         }
         if ($this->_getParam("filter")) {
             $list->setCondition("`name` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `pattern` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `reverse` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `controller` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `action` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%"));
         }
         $list->load();
         $routes = array();
         foreach ($list->getRoutes() as $route) {
             $routes[] = $route;
         }
         $this->_helper->json(array("data" => $routes, "success" => true, "total" => $list->getTotalCount()));
     }
     $this->_helper->json(false);
 }