public function addPropertyAction()
{
if (!$this->getRequest()->isPost()) {
return $this->returnJson(array('success' => false, 'message' => 'Error'));
}
$post = $this->getRequest()->getPost();
$identifier = $post->get('identifier');
$tabId = $post->get('tab');
$session = $this->getSession();
$documentTypeSession = $session['document-type'];
$tabs = $documentTypeSession['tabs'];
if (empty($documentTypeSession['tabs'][$tabId])) {
return $this->returnJson(array('success' => false, 'message' => 'Tab does not exists'));
}
$tab = $documentTypeSession['tabs'][$tabId];
$properties = $tab['properties'];
foreach ($tabs as $tab) {
if (empty($tab['properties'])) {
continue;
}
foreach ($tab['properties'] as $property) {
if (!empty($property['identifier']) and $identifier == $property['identifier']) {
return $this->returnJson(array('success' => false, 'message' => 'Identifier already exists'));
}
}
}
$lastId = empty($documentTypeSession['max-property-id']) ? 0 : $documentTypeSession['max-property-id'];
$currentId = $lastId + 1;
$documentTypeSession['max-property-id'] = $currentId;
$properties[$currentId] = array('name' => $post->get('name'), 'identifier' => $identifier, 'tab' => $tabId, 'description' => $post->get('description'), 'isRequired' => $post->get('isRequired') == 1 ? true : false, 'datatype' => $post->get('datatype'));
$documentTypeSession['tabs'][$tabId]['properties'] = $properties;
$session['document-type'] = $documentTypeSession;
$properties[$currentId]['success'] = true;
$properties[$currentId]['id'] = $currentId;
return $this->returnJson($properties[$currentId]);
}