protected function setupForm($formDataSample)
 {
     $form = new UsersForm();
     $form->addSettori(array(1 => 'Settore 1', 2 => 'Settore 2'));
     $form->addRoles(array(1 => 'Role 1', 2 => 'Role 2'));
     $inputFilter = new UsersFormInputFilter();
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($formDataSample);
     return $form;
 }
Esempio n. 2
0
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $inputFilter = new UsersFormInputFilter();
     $form = new UsersForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $helper = new UsersControllerHelper();
     $helper->setConnection($connection);
     $helper->getConnection()->beginTransaction();
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $helper->setLoggedUser($userDetails);
         $userEmail = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('email' => $inputFilter->email, 'limit' => 1));
         $helper->checkRecordsAreEmpty($userEmail, 'Esiste un utente registrato con questa email');
         $lastInsertId = $helper->insert($inputFilter);
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Inserito nuovo utente " . $inputFilter->name . ' ' . $inputFilter->surname, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Utente inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/users-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $this->params()->fromRoute('modulename'))), 'backToSummaryText' => "Elenco utenti"));
         $helper->getConnection()->commit();
     } catch (\Exception $e) {
         try {
             $helper->getConnection()->rollBack();
         } catch (\Doctrine\DBAL\ConnectionException $ex) {
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore creazione nuovo utente: " . $inputFilter->name . ' ' . $inputFilter->surname, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore creazione nuovo utente', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al form di inserimento dati'));
     }
     $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
 }
Esempio n. 3
0
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $userDetails = $this->layout()->getVariable('userDetails');
     /* Check user ID and UPDATE permission */
     if ($userDetails->id != $id and !$userDetails->acl->hasResource('users_update') and $id != '') {
         return $this->redirect()->toRoute('admin/not-authorized', array('lang' => 'it'));
     }
     /* Check user ID and INSERT permission */
     if ($id == '' and !$userDetails->acl->hasResource('users_add')) {
         return $this->redirect()->toRoute('admin/not-authorized', array('lang' => 'it'));
     }
     $helper = new UsersControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new UsersGetterWrapper(new UsersGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $form = new UsersForm();
     if (!empty($records)) {
         $form->addPasswords();
     } else {
         $form->addPasswordsMandatory();
     }
     /* Check Roles permission */
     if ($userDetails->acl->hasResource('users_roles_update')) {
         $rolesRecords = $helper->recoverWrapperRecords(new UsersRolesGetterWrapper(new UsersRolesGetter($em)), array());
         $rolesRecordsForDropDown = $helper->formatForDropwdown($rolesRecords, 'id', 'name');
         $form->addRoles($rolesRecordsForDropDown);
     }
     /* Check Settori permission */
     if ($userDetails->acl->hasResource('users_settori_update')) {
         $settoriRecords = $helper->recoverWrapperRecords(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array());
         $settoriRecordsForDropDown = $helper->formatForDropwdown($settoriRecords, 'id', 'nome');
         $form->addSettori($settoriRecordsForDropDown);
     }
     if (!empty($records)) {
         $formAction = $this->url()->fromRoute('admin/users-update', array('lang' => $lang));
         $formTitle = 'Modifica utente';
         $formDescription = 'Modifica dati utente. Per creare una <strong>password sicura</strong>, scegliere una string lunga almeno 8 caratteri e che contenga caratteri speciali, lettere maiuscole e\\o minuscole e numeri.';
         $form->setData($records[0]);
     } else {
         $formAction = $this->url()->fromRoute('admin/users-insert', array('lang' => $lang));
         $formTitle = 'Nuovo utente';
         $formDescription = 'Creazione nuovo utente. Per creare una <strong>password sicura</strong>, scegliere una string lunga almeno 8 caratteri e che contenga caratteri speciali, lettere maiuscole e\\o minuscole e numeri.';
     }
     $this->layout()->setVariables(array('form' => $form, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'formAction' => $formAction, 'formBreadCrumbCategory' => 'Utenti', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/users-summary', array('lang' => $this->params()->fromRoute('lang'))), 'templatePartial' => self::formTemplate));
     $this->layout()->setTemplate($mainLayout);
 }