コード例 #1
0
ファイル: EvaluationLink.php プロジェクト: debranova/project
 /**
  * @return Evaluation
  */
 public function getEvaluation()
 {
     /*
      * If the evaluation is null, create it
      */
     if (is_null($this->evaluation)) {
         /*
          * $projectService, $evaluationType, $country cannot be null when we want to create a new evaluation
          */
         if (is_null($this->projectService)) {
             throw new \InvalidArgumentException(sprintf("ProjectService cannot be null to give evaluation in %s", $this->getAction(), __CLASS__));
         }
         if (is_null($this->evaluationType)) {
             throw new \InvalidArgumentException(sprintf("Evaluation type cannot be null to give evaluation in %s", $this->getAction(), __CLASS__));
         }
         if (is_null($this->country)) {
             throw new \InvalidArgumentException(sprintf("The country cannot be null to give evaluation in %s", $this->getAction(), __CLASS__));
         }
         $this->evaluation = new Evaluation();
         $this->evaluation->setProject($this->projectService->getProject());
         $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
         $this->evaluation->setContact($auth->getIdentity());
         $this->evaluation->setType($this->evaluationType);
         $this->evaluation->setCountry($this->country);
     }
     return $this->evaluation;
 }
コード例 #2
0
 /**
  * @return ViewModel
  */
 public function evaluateProjectAction()
 {
     $routeMatch = $this->getEvent()->getRouteMatch();
     $country = $this->getGeneralService()->findEntityById('country', $routeMatch->getParam('country'));
     $evaluationType = $this->getProjectService()->findEntityById('Evaluation\\Type', $routeMatch->getParam('type'));
     $projectService = $this->getProjectService()->setProjectId($routeMatch->getParam('project'));
     $evaluationTypes = $this->getProjectService()->findAll('Evaluation\\Type');
     /*
      * The evaluation can be there, or be null, then we need to create it.
      */
     $evaluation = $this->getEvaluationService()->findEvaluationByCountryAndTypeAndProject($country, $evaluationType, $projectService->getProject());
     if (is_null($evaluation)) {
         $evaluation = new Evaluation();
         $evaluation->setProject($projectService->getProject());
         $evaluation->setContact($this->zfcUserAuthentication()->getIdentity());
         $evaluation->setType($evaluationType);
         $evaluation->setCountry($country);
     }
     $form = $this->getFormService()->prepare($evaluation->get('underscore_entity_name'), $evaluation, $_POST);
     $form->setAttribute('class', 'form-horizontal');
     if ($this->getRequest()->isPost() && $form->isValid()) {
         if (!isset($_POST['cancel'])) {
             $this->getProjectService()->updateEntity($form->getData());
         }
         return $this->redirect()->toRoute('community/evaluation/overview-project', ['country' => $country->getId(), 'type' => $evaluationType->getId(), 'project' => $projectService->getProject()->getId()]);
     }
     /*
      * Check to see if we have an active version
      */
     $versionType = $this->getVersionService()->findEntityById('Version\\Type', $evaluationType->getVersionType());
     $version = $this->getVersionService()->findLatestVersionByType($projectService->getProject(), $versionType);
     return new ViewModel(['evaluation' => $evaluation, 'evaluationType' => $evaluationType, 'evaluationTypes' => $evaluationTypes, 'version' => $version, 'form' => $form]);
 }