コード例 #1
0
ファイル: StaffController.php プロジェクト: Primetron/Edusoft
 public function addAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $form = new StaffForm($entityManager);
     $staffHistory = new staffHistory();
     $staff = new Staff();
     $form->bind($staff);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $dataForm = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($dataForm);
         //var_dump($form);
         if ($form->isValid()) {
             $pre = $form->getData('staff');
             //var_dump($pre);
             $staff->setStatus('Active');
             $staff->setClevel($pre->getLevel());
             $staff->setCstep($pre->getStep());
             $staffHistory->setStaff($pre);
             $staffHistory->setYear($pre->getYear());
             $staffHistory->setLevel($pre->getLevel());
             $staffHistory->setStep($pre->getStep());
             //get role id and store in user table
             $role = $entityManager->getRepository('EduUser\\Entity\\Role')->findOneBy(array('roleId' => 'parent'));
             $user = new User();
             $user->setUsername($pre->getStaffNo());
             $user->setDisplayName($pre->getFname() . ' ' . $pre->getLname() . ' ' . $pre->getMname());
             $user->setEmail($pre->getStaffNo() . '@brainfield.com');
             $user->setPassword($this->getPassword());
             $user->addRole($role);
             $user->setState(1);
             $entityManager->persist($user);
             $entityManager->flush();
             $staff->setUser($user);
             $entityManager->persist($staff);
             $entityManager->persist($staffHistory);
             $entityManager->flush();
             return $this->redirect()->toRoute('staff', array('controller' => 'staff', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form));
 }
コード例 #2
0
ファイル: CrudController.php プロジェクト: Primetron/Edusoft
 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));
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function removeRoles(\Doctrine\Common\Collections\Collection $roles)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'removeRoles', array($roles));
     return parent::removeRoles($roles);
 }