Ejemplo n.º 1
0
 public function propertiesAction()
 {
     if ($this->_getParam("data")) {
         if ($this->getUser()->isAllowed("predefined_properties")) {
             if ($this->_getParam("xaction") == "destroy") {
                 $id = Zend_Json::decode($this->_getParam("data"));
                 $property = Property_Predefined::getById($id);
                 $property->delete();
                 $this->_helper->json(array("success" => true, "data" => array()));
             } else {
                 if ($this->_getParam("xaction") == "update") {
                     $data = Zend_Json::decode($this->_getParam("data"));
                     // save type
                     $property = Property_Predefined::getById($data["id"]);
                     $property->setValues($data);
                     $property->save();
                     $this->_helper->json(array("data" => $property, "success" => true));
                 } else {
                     if ($this->_getParam("xaction") == "create") {
                         $data = Zend_Json::decode($this->_getParam("data"));
                         unset($data["id"]);
                         // save type
                         $property = Property_Predefined::create();
                         $property->setValues($data);
                         $property->save();
                         $this->_helper->json(array("data" => $property, "success" => true));
                     }
                 }
             }
         } else {
             if ($this->getUser() != null) {
                 Logger::err("user [" . $this->getUser()->getId() . "] attempted to modify properties predefined, but has no permission to do so.");
             } else {
                 Logger::err("attempt to modify properties predefined, but no user in session.");
             }
         }
     } else {
         // get list of types
         $list = new Property_Predefined_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 `description` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%"));
         }
         $list->load();
         $properties = array();
         if (is_array($list->getProperties())) {
             foreach ($list->getProperties() as $property) {
                 $properties[] = $property;
             }
         }
         $this->_helper->json(array("data" => $properties, "success" => true, "total" => $list->getTotalCount()));
     }
 }