Esempio n. 1
0
 public function editAction()
 {
     $entityManager = $this->getOM();
     $viewmodel = new ViewModel();
     $ud = $this->zfcUserAuthentication()->getIdentity()->getId();
     $staff = $this->getOM()->getRepository('Admin\\Entity\\Staff')->findOneBy(array('user' => $ud));
     $id = $staff->getId();
     if (!$id) {
         return $this->redirect()->toRoute('teachers', array('controller' => 'teachers', 'action' => 'dashboard'));
     }
     $image = $staff->getImage();
     $form = new StaffForm($entityManager);
     $form->bind($staff);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $dataForm = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($dataForm);
         //exclude section and year from being validated
         $form->setValidationGroup(array('staff' => array('fname', 'lname', 'mname', 'mobile1', 'mobile2', 'twitter', 'facebook', 'paddress', 'raddress', 'country', 'email', 'state', 'lga', 'image', 'dob', 'sex', 'religion', 'nokName', 'nokRel', 'nokMobile')));
         if ($form->isValid()) {
             $data = $form->getData('staff')->getImage();
             if (!$data) {
                 $staff->setImage($image);
             }
             $entityManager->persist($staff);
             $entityManager->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('teachers', array('controller' => 'students', 'action' => 'dashboard'));
         }
     }
     $viewmodel->setVariables(array('form' => $form, 'id' => $id, 'image' => $image));
     return $viewmodel;
 }
Esempio n. 2
0
 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));
 }