/** * Loads a list of document-types for the specicifies parameters, returns an array of Document_DocType elements * * @return array */ public function load() { $docTypesData = $this->db->fetchAll("SELECT id FROM documents_doctypes" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); $docTypes = array(); foreach ($docTypesData as $docTypeData) { $docTypes[] = Document_DocType::getById($docTypeData["id"]); } $this->model->setDocTypes($docTypes); return $docTypes; }
public function docTypesAction() { if ($this->_getParam("data")) { if ($this->getUser()->isAllowed("document_types")) { if ($this->_getParam("xaction") == "destroy") { $id = Zend_Json::decode($this->_getParam("data")); $type = Document_DocType::getById($id); $type->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->_getParam("xaction") == "update") { $data = Zend_Json::decode($this->_getParam("data")); // save type $type = Document_DocType::getById($data["id"]); $type->setValues($data); $type->save(); $this->_helper->json(array("data" => $type, "success" => true)); } else { if ($this->_getParam("xaction") == "create") { $data = Zend_Json::decode($this->_getParam("data")); unset($data["id"]); // save type $type = Document_DocType::create(); $type->setValues($data); $type->save(); $this->_helper->json(array("data" => $type, "success" => true)); } } } } } else { // get list of types $list = new Document_DocType_List(); if ($this->_getParam("sort")) { $list->setOrderKey($this->_getParam("sort")); $list->setOrder($this->_getParam("dir")); } $list->load(); $docTypes = array(); foreach ($list->getDocTypes() as $type) { $docTypes[] = $type; } $this->_helper->json(array("data" => $docTypes, "success" => true, "total" => count($docTypes))); } $this->_helper->json(false); }