public function docTypesAction()
{
if ($this->getParam("data")) {
$this->checkPermission("document_types");
if ($this->getParam("xaction") == "destroy") {
$data = \Zend_Json::decode($this->getParam("data"));
if (\Pimcore\Tool\Admin::isExtJS6()) {
$id = $data["id"];
} else {
$id = $data;
}
$type = Document\DocType::getById($id);
$type->delete();
$this->_helper->json(["success" => true, "data" => []]);
} elseif ($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(["data" => $type, "success" => true]);
} elseif ($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(["data" => $type, "success" => true]);
}
} else {
// get list of types
$list = new Document\DocType\Listing();
$list->load();
$docTypes = [];
foreach ($list->getDocTypes() as $type) {
if ($this->getUser()->isAllowed($type->getId(), "docType")) {
$docTypes[] = $type;
}
}
$this->_helper->json(["data" => $docTypes, "success" => true, "total" => count($docTypes)]);
}
$this->_helper->json(false);
}