/** * create new ATC * * * @access public * * @return ViewModel */ public function newAction() { $variables = array(); $cleanQuery = $this->getServiceLocator()->get('wrapperQuery'); $query = $cleanQuery->setEntity('Users\\Entity\\User'); $orgsQuery = $cleanQuery->setEntity('Organizations\\Entity\\Organization'); $orgModel = $this->getServiceLocator()->get('Organizations\\Model\\Organization'); $auth = new AuthenticationService(); $storage = $auth->getIdentity(); $isAdminUser = false; $creatorId = false; $userEmail = false; if ($auth->hasIdentity()) { if (in_array(Role::ADMIN_ROLE, $storage['roles'])) { $isAdminUser = true; } $creatorId = $storage['id']; $userEmail = $storage['email']; } $orgObj = new OrgEntity(); $options = array(); // organization type $orgType = $_GET['organization']; $rolesArray = $orgModel->getRequiredRoles($orgType); $validationResult = $this->getServiceLocator()->get('aclValidator')->validateOrganizationAccessControl($this->getResponse(), $rolesArray); if ($validationResult["isValid"] === false && !empty($validationResult["redirectUrl"])) { return $this->redirect()->toUrl($validationResult["redirectUrl"]); } $savedState = $orgModel->hasSavedState($orgType, $creatorId); if ($savedState != null) { $url = $this->getEvent()->getRouter()->assemble(array('action' => 'edit', 'id' => $savedState), array('name' => 'edit_org')); $this->redirect()->toUrl($url . '?organization=' . $orgType); } $options['query'] = $query; $options['staticLangs'] = OrgEntity::getStaticLangs(); $options['staticOss'] = OrgEntity::getOSs(); $options['staticOfficeVersions'] = OrgEntity::getOfficeVersions(); $form = new OrgForm(null, $options); $atcSkippedParams = $this->getServiceLocator()->get('Config')['atcSkippedParams']; $atpSkippedParams = $this->getServiceLocator()->get('Config')['atpSkippedParams']; $request = $this->getRequest(); if ($request->isPost()) { // Make certain to merge the files info! $fileData = $request->getFiles()->toArray(); $data = array_merge_recursive($request->getPost()->toArray(), $fileData); $inputFilter = $orgObj->getInputFilter($query); $form->setInputFilter($orgObj->getInputFilter($orgsQuery)); $form->setData($data); switch ($data['type']) { case '1': foreach ($atcSkippedParams as $param) { $inputFilter->get($param)->setRequired(false); $data[$param] = null; } break; case '2': foreach ($atpSkippedParams as $param) { $inputFilter->get($param)->setRequired(false); $data[$param] = null; } break; } $data['creatorId'] = $creatorId; if ($form->isValid()) { $orgModel->saveOrganization($data, null, null, $creatorId, $userEmail, $isAdminUser); // redirecting if ($data['type'] == 1) { $url = $this->getEvent()->getRouter()->assemble(array('action' => 'atps'), array('name' => 'list_atc_orgs')); } else { if ($data['type'] == 2 || $data['type'] == 3) { $url = $this->getEvent()->getRouter()->assemble(array('action' => 'atcs'), array('name' => 'list_atp_orgs')); } } $this->redirect()->toUrl($url); } } $variables['orgForm'] = $this->getFormView($form); return new ViewModel($variables); }