예제 #1
0
 private function setModel($row)
 {
     $model = new Application_Model_ProjectUser();
     $model->setId($row->id)->setProjectId($row->project_id)->setUserId($row->user_id)->setStatus($row->status)->setAddedon($row->addedon)->setUpdatedon($row->updatedon);
     return $model;
 }
예제 #2
0
 private function setModel($row)
 {
     $model = new Application_Model_Project();
     $model->setId($row->id)->setTitle($row->title)->setDescription($row->description)->setClientInfo($row->client_info)->setStartDate($row->start_date)->setEndDate($row->end_date)->setStatus($row->status)->setProjectManagerId($row->project_manager_id)->setTeamLeaderId($row->team_leader_id)->setAddedon($row->addedon)->setUpdatedon($row->updatedon);
     /*find project resource*/
     //            $projectUser=$row->findManyToManyRowset('Application_Model_DbTable_User','Application_Model_DbTable_ProjectUser');
     //            $user=new Application_Model_User();
     //            $arrUser=array();
     //            foreach($projectUser as $_user)
     //            {
     //                $arrUser[]=$user->setModel($_user);
     //
     //            }
     //            $model->setUsers($arrUser);
     $projectUser = new Application_Model_ProjectUser();
     $table = $projectUser->getMapper()->getDbTable();
     $select = $table->select()->setIntegrityCheck(false)->from(array("pu" => 'project_user'), array('pustatus' => 'status', 'user_id'))->join(array("u" => 'user'), 'u.id=pu.user_id', array('first_name', 'last_name', 'middle_name', 'employee_code'))->join(array("p" => 'project'), 'p.id=pu.project_id')->where("pu.project_id='{$row->id}'");
     $model->setProjectUsers($table->fetchAll($select));
     /*------------------------*/
     return $model;
 }
예제 #3
0
 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;
 }