コード例 #1
0
ファイル: PmController.php プロジェクト: riteshsahu1981/we
 public function editProjectAction()
 {
     $id = $this->_getParam('id');
     $this->view->user_id = $id;
     $model1 = new Application_Model_Project();
     $model = $model1->find($id);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/pm/projects'));
     }
     $options['title'] = $model->getTitle();
     $options['description'] = $model->getDescription();
     $options['startDate'] = $model->getStartDate();
     $options['endDate'] = $model->getEndDate();
     $options['status'] = $model->getStatus();
     $options['projectManagerId'] = $model->getProjectManagerId();
     $options['teamLeaderId'] = $model->getTeamLeaderId();
     $options['clientInfo'] = $model->getClientInfo();
     $arr_resource_value = array();
     $arr_resource_text = array();
     foreach ($model->getProjectUsers() as $_projectUser) {
         if ($_projectUser->pustatus == "active") {
             $arr_resource_value[] = $_projectUser->user_id;
             $arr_resource_text[] = $_projectUser->first_name . " " . $_projectUser->last_name . " - [ Code:" . $_projectUser->employee_code . " ]";
         }
     }
     $this->view->resource_value = $arr_resource_value;
     $this->view->resource_text = $arr_resource_text;
     $request = $this->getRequest();
     $form = new Application_Form_Project();
     $elements = $form->getElements();
     $form->clearDecorators();
     foreach ($elements as $element) {
         $element->removeDecorator('label');
         $element->removeDecorator('HtmlTag');
         $element->removeDecorator('tr');
         $element->removeDecorator('td');
         $element->removeDecorator('row');
         $element->removeDecorator('data');
     }
     $form->populate($options);
     $options = $request->getPost();
     if ($request->isPost()) {
         $options = $request->getPost();
         if (isset($options['resource_value'])) {
             $this->view->resource_value = $options['resource_value'];
             $this->view->resource_text = $options['resource_text'];
         }
         $projectUser = new Application_Model_ProjectUser();
         $projectUser = $projectUser->fetchAll("project_id='{$id}'");
         foreach ($projectUser as $pu) {
             $pu->setStatus('inactive');
             $pu->save();
         }
         /*----- Add/update project Resource -----*/
         if (isset($options['resource_value'])) {
             foreach ($options['resource_value'] as $value) {
                 $projectUser = new Application_Model_ProjectUser();
                 $projectUser = $projectUser->fetchRow("project_id='{$id}' and user_id='{$value}'");
                 if (false === $projectUser) {
                     $projectUser = new Application_Model_ProjectUser();
                     $projectUser->setProjectId($id);
                     $projectUser->setUserId($value);
                     $projectUser->setStatus('active');
                     $projectUser->save();
                 } else {
                     $projectUser->setStatus('active');
                     $projectUser->save();
                 }
             }
         }
         /*----- Add/update project Resource -----*/
         if ($model->getTitle() != $options['title']) {
             $form->getElement('title')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'project', 'field' => 'title', 'messages' => 'Project with the same title is already exist.'))));
         }
         if ($form->isValid($options)) {
             $model->setOptions($options);
             $model->save();
             $this->_flashMessenger->addMessage(array('success' => 'Project has been updated successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/pm/edit-project/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;
 }