public function addTabAction()
{
if (!$this->getRequest()->isPost()) {
return $this->returnJson(array('success' => false, 'message' => 'Error'));
}
$session = $this->getSession();
$name = $this->getRequest()->getPost()->get('name');
$description = $this->getRequest()->getPost()->get('description');
$documentTypeSession = $session['document-type'];
$tabs = empty($documentTypeSession['tabs']) ? array() : $documentTypeSession['tabs'];
foreach ($tabs as $tab) {
if ($name == $tab['name']) {
return $this->returnJson(array('success' => false, 'message' => 'Already exists'));
}
}
$lastId = empty($documentTypeSession['max-tab-id']) ? 0 : $documentTypeSession['max-tab-id'];
$currentId = $lastId + 1;
$documentTypeSession['max-tab-id'] = $currentId;
$tabs[$currentId] = array('name' => $name, 'description' => $description, 'properties' => array());
$documentTypeSession['tabs'] = $tabs;
$session['document-type'] = $documentTypeSession;
return $this->returnJson(array('success' => true, 'id' => $currentId, 'name' => $name, 'description' => $description));
}