Ejemplo n.º 1
0
 public function addAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $form = new StudentForm($entityManager);
     $person = new Student();
     $studentHistory = new StudentHistory($entityManager);
     $form->bind($person);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $dataForm = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         //set data post and file ...
         $form->get('student')->get('status')->setValue('Active');
         // var_dump($form);
         $form->setData($dataForm);
         //var_dump($form);
         if ($form->isValid()) {
             $pre = $form->getData('student');
             $pern = $form->getData('student')->getPerson();
             //var_dump($pern);die;
             $person->setStatus('Active');
             $person->setCurrentclass($pre->getClass());
             $studentHistory->setStudent($pre);
             $studentHistory->setYear($pre->getYear());
             $studentHistory->setClass($pre->getClass());
             // $person->setStatus(1);
             //get role id and store in user table
             $role = $entityManager->getRepository('EduUser\\Entity\\Role')->findOneBy(array('roleId' => 'student'));
             $user = new User();
             $user->setUsername($pre->getAdmNo());
             $user->setDisplayName($pern->getFname());
             $user->setEmail($pre->getAdmNo() . '@brainfield.com');
             $user->setPassword($this->getPassword());
             $user->addRole($role);
             $user->setState(1);
             $entityManager->persist($user);
             $entityManager->flush();
             $person->setUser($user);
             $entityManager->persist($person);
             $entityManager->persist($studentHistory);
             $entityManager->flush();
             return $this->redirect()->toRoute('student', array('controller' => 'student', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form));
 }
Ejemplo n.º 2
0
 public function addstaffAction()
 {
     $form = new EduUserForm($this->getOM());
     if ($this->getRequest()->isPost()) {
         $id = $this->params()->fromPost('staff');
         $roleid = $this->params()->fromPost('role');
         $role = $this->getOM()->getRepository('EduUser\\Entity\\Role')->findOneby(array('id' => $roleid));
         // var_dump($role);die;
         $staff = $this->getOM()->getRepository('Admin\\Entity\\Staff')->findOneby(array('id' => $id));
         $user = new User();
         $user->setUsername($staff->getFname() . $staff->getLname());
         $user->setDisplayName($staff->getFname());
         $user->setEmail($staff->getFname() . $staff->getLname() . '@brainfield.com');
         $user->setPassword($this->getPassword());
         $user->addRole($role);
         $user->setState(1);
         $this->getOM()->persist($user);
         $this->getOM()->flush();
         $staff->setUser($user);
         $this->getOM()->persist($staff);
         $this->getOM()->flush();
         $this->flashMessenger()->addSuccessMessage('User saved');
         return $this->redirect()->toRoute('crud');
     }
     return new ViewModel(array('form' => $form));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function setPassword($password)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setPassword', array($password));
     return parent::setPassword($password);
 }