コード例 #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));
 }
コード例 #2
0
 public function addwardAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('guardian', array('controller' => 'guardian', 'action' => 'view'));
     }
     $guardian = $entityManager->find('Admin\\Entity\\Guardian', $id);
     //var_dump($guardian);
     if (!$guardian) {
         return $this->redirect()->toRoute('guardian', array('controller' => 'guardian', 'action' => 'view'));
     }
     $form = new WardForm($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');
             // var_dump($pre);
             $person->setStatus('Active');
             $person->getPerson()->setGuardian($guardian);
             $person->setCurrentclass($pre->getClass());
             $studentHistory->setStudent($pre);
             $studentHistory->setYear($pre->getYear());
             $studentHistory->setClass($pre->getClass());
             // $person->setStatus(1);
             $entityManager->persist($person);
             $entityManager->persist($studentHistory);
             $entityManager->flush();
             return $this->redirect()->toRoute('guardian', array('controller' => 'guardian', 'action' => 'view'));
         }
     }
     return new ViewModel(array('form' => $form));
 }