public function docTypesAction()
{
if ($this->getParam("data")) {
$this->checkPermission("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\Listing();
if ($this->getParam("sort")) {
$list->setOrderKey($this->getParam("sort"));
$list->setOrder($this->getParam("dir"));
}
$list->load();
$docTypes = array();
foreach ($list->getDocTypes() as $type) {
if ($this->getUser()->isAllowed($type->getId(), "docType")) {
$docTypes[] = $type;
}
}
$this->_helper->json(array("data" => $docTypes, "success" => true, "total" => count($docTypes)));
}
$this->_helper->json(false);
}