Пример #1
0
 public function departmentAction()
 {
     $department = new Application_Model_DbTable_Department();
     $employee = new Application_Model_DbTable_Employee();
     $form = new Application_Form_Department();
     $form->setAction('index/department');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         $form->isValid($formData);
         if ($form->isValid($formData) && $form->save->isChecked()) {
             $id = (int) $form->getValue('id');
             $name = $form->getValue('name');
             $errorMessage = $department->updateDepartment($id, $name);
             if ($errorMessage != "") {
                 echo $errorMessage;
             } else {
                 $this->_helper->redirector('department', 'index', null, array('id' => $id));
             }
         } else {
             if ($form->cut->isChecked()) {
                 $id = (int) $form->getValue('id');
                 $employee->cutDepartment($id);
                 $this->_helper->redirector('department', 'index', null, array('id' => $id));
             } else {
                 if ($form->selectDepartment->isChecked()) {
                     $depId = (int) $form->getValue('departments');
                     $this->_helper->redirector('department', 'index', null, array('id' => $depId));
                 } else {
                     if ($form->selectEmployee->isChecked()) {
                         $empId = (int) $form->getValue('employees');
                         $this->_helper->redirector('employee', 'index', null, array('id' => $empId));
                     } else {
                         if ($form->edit->isChecked()) {
                             $empId = (int) $form->getValue('managerId');
                             $this->_helper->redirector('employee', 'index', null, array('id' => $empId));
                         } else {
                             if ($form->back->isChecked()) {
                                 $id = (int) $form->getValue('id');
                                 $depTemp = $department->getDepartment($id);
                                 if ($depTemp[did] == null) {
                                     $this->_helper->redirector('index');
                                 } else {
                                     $this->_helper->redirector('department', 'index', null, array('id' => $depTemp[did]));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $id = $this->_getParam('id', 0);
         $d = $department->getDepartment($id);
         $manager = $employee->getManagerForDepartment($id);
         $d[manager] = $manager[name];
         $d[managerId] = $manager[id];
         $d[total] = $employee->getTotalForDepartment($id);
         $form->populate($d);
         $form->fillLists($id);
     }
 }
Пример #2
0
 public function editDepartmentAction()
 {
     $id = $this->_getParam('id');
     $this->view->user_id = $id;
     $model1 = new Application_Model_Department();
     $model = $model1->find($id);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/departments'));
     }
     $options['title'] = $model->getTitle();
     $options['type'] = $model->getType();
     $options['departmentHeadId'] = $model->getDepartmentHeadId();
     $request = $this->getRequest();
     $form = new Application_Form_Department();
     $form->populate($options);
     $options = $request->getPost();
     if ($request->isPost()) {
         /*---- email validation ----*/
         if ($options['title'] == $model->getTitle()) {
             $form->getElement('title')->removeValidator("Db_NoRecordExists");
         }
         /*-------------------------*/
         if ($form->isValid($options)) {
             $model->setOptions($options);
             $model->save();
             $this->_flashMessenger->addMessage(array('success' => 'Department title has been updated successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/edit-department/id/' . $id));
         } else {
             $this->_flashMessenger->addMessage(array('error' => 'Unable to save the data. Please provide valid inputs and try again.'));
             $form->reset();
             $form->populate($options);
         }
     }
     $this->view->form = $form;
 }