public function createAction()
{
$form = new DocumentTypeForm();
$form->setAttribute('action', $this->url()->fromRoute('development/document-type/create', array()));
$request = $this->getRequest();
$session = $this->getSession();
if (!$request->isPost()) {
$session['document-type'] = array('tabs' => array());
} else {
$postData = $this->getRequest()->getPost()->toArray();
$form->setData($postData);
$form->setValues($postData);
if (!$form->isValid()) {
$this->flashMessenger()->addErrorMessage('Can not save document type');
$this->useFlashMessenger();
} else {
$input = $form->getInputFilter();
$infosSubform = $input->get('infos');
$viewsSubform = $input->get('views');
$documentType = new DocumentType\Model();
$documentType->addData(array('name' => $infosSubform->getValue('name'), 'icon_id' => $infosSubform->getValue('icon_id'), 'description' => $infosSubform->getValue('description'), 'default_view_id' => $viewsSubform->getValue('default_view'), 'user_id' => $this->getServiceLocator()->get('Auth')->getIdentity()->getId()));
$documentType->getAdapter()->getDriver()->getConnection()->beginTransaction();
try {
$availableViews = $viewsSubform->getValue('available_views');
if (empty($availableViews)) {
$availableViews = array();
}
$documentType->addViews($availableViews);
$documentType->setDependencies($infosSubform->getValue('dependency'));
$documentType->save();
$existingTabs = $this->saveTabs($input->get('tabs'), $documentType);
$this->saveProperties($input->get('properties'), $existingTabs);
$documentType->getAdapter()->getDriver()->getConnection()->commit();
$this->flashMessenger()->addSuccessMessage('This document type has been saved');
return $this->redirect()->toRoute('development/document-type/edit', array('id' => $documentType->getId()));
} catch (Exception $e) {
$documentType->getAdapter()->getDriver()->getConnection()->rollBack();
throw new \Gc\Exception('Error Processing Request ' . print_r($e, true), 1);
}
}
}
return array('form' => $form);
}