Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
 /**
  * Returns true if and only if the assertion conditions are met.
  *
  * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
  * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
  * privileges, respectively.
  *
  * @param Acl               $acl
  * @param RoleInterface     $role
  * @param ResourceInterface $resource
  * @param null              $privilege
  *
  * @return boolean|null
  *
  * @throws \InvalidArgumentException
  */
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     $countryId = $this->getRouteMatch()->getParam('country');
     $evaluationTypeId = $this->getRouteMatch()->getParam('type');
     $projectId = $this->getRouteMatch()->getParam('project');
     /*
      * When the privilege is null, we need to grab it from the routeMatch
      */
     if (is_null($privilege)) {
         $privilege = $this->getRouteMatch()->getParam('privilege');
     }
     return true;
     /*
      * You need to be a funder, to see the overview. Return null if this ia not the case
      */
     if (in_array($privilege, ['overview', 'overview-project', 'download-overview'])) {
         if (!$this->rolesHaveAccess(['funder', 'office'])) {
             return false;
         } else {
             //Stop the script here as we do not need to to know the rest of the evaluation
             return true;
         }
     }
     if (!$resource instanceof EvaluationEntity) {
         if (is_null($countryId) || is_null($evaluationTypeId) || is_null($projectId)) {
             throw new \InvalidArgumentException('The countryId, evaluationTypeId or projectId cannot be null');
         }
         $country = $this->getGeneralService()->findEntityById('country', $countryId);
         $evaluationType = $this->getEvaluationService()->findEntityById('Evaluation\\Type', $evaluationTypeId);
         $project = $this->getProjectService()->setProjectId($projectId);
         if (is_null($country) || is_null($evaluationType) || is_null($project)) {
             throw new \InvalidArgumentException('The country, evaluationType or project cannot be null');
         }
         $resource = new EvaluationEntity();
         $resource->setCountry($country);
         $resource->setType($evaluationType);
         $resource->setProject($project->getProject());
     }
     /*
      * Feed the project to the projectService to grab the information from the array
      */
     $this->getProjectService()->setProject($resource->getProject());
     //Give no access when no access to the project itself
     if (!$this->getProjectAssert()->assert($acl, $role, $resource->getProject(), 'view-community')) {
         return false;
     }
     switch ($privilege) {
         case 'download-version-documents':
             return $this->hasContact();
         case 'evaluate-project':
             switch ($resource->getType()->getId()) {
                 case EvaluationType::TYPE_PO_EVALUATION:
                     /*
                      * Check first of the project has a correct version
                      */
                     $poClosedDate = $resource->getProject()->getCall()->getPoCloseDate();
                     if ($poClosedDate->add(new \DateInterval('P1M')) < new \DateTime()) {
                         return false;
                     }
                     break;
                 case EvaluationType::TYPE_FPP_EVALUATION:
                     $fppClosedDate = $resource->getProject()->getCall()->getFppCloseDate();
                     if ($fppClosedDate->add(new \DateInterval('P1M')) < new \DateTime()) {
                         return false;
                     }
                     break;
                 case EvaluationType::TYPE_FUNDING_STATUS:
                     /*
                      * Funding status is office only, the call cannot be open
                      */
                     break;
             }
             /*
              * Check to see if we have an active version
              */
             $versionType = $this->getVersionService()->findEntityById('Version\\Type', $resource->getType()->getVersionType());
             $version = $this->getVersionService()->findLatestVersionByType($resource->getProject(), $versionType);
             if (is_null($version)) {
                 return false;
             }
             /*
              * Now return only true when the contact/country is participating in the project
              */
             $contactActiveInCountry = false;
             $contactCountry = $this->getContactService()->parseCountry();
             $countries = $this->getGeneralService()->findCountryByProject($resource->getProject());
             foreach ($countries as $country) {
                 if (!$contactActiveInCountry && !is_null($contactCountry) && $contactCountry->getId() === $country->getId()) {
                     $contactActiveInCountry = true;
                 }
             }
             /*
              * When the contact is not active in the country, return false because we do not allow evaluation
              */
             if (!$contactActiveInCountry) {
                 return false;
             }
             /*
              * No errors found, return true
              */
             return true;
         case 'overview-project':
         case 'download-project':
             if ($this->rolesHaveAccess([strtolower(Access::ACCESS_OFFICE)])) {
                 return true;
             }
             /*
              * Now return only true when the contact/country is participating in the project
              */
             $contactActiveInCountry = false;
             $contactCountry = $this->getContactService()->parseCountry();
             $countries = $this->getGeneralService()->findCountryByProject($resource->getProject());
             foreach ($countries as $country) {
                 if (!$contactActiveInCountry && !is_null($contactCountry) && $contactCountry->getId() === $country->getId()) {
                     $contactActiveInCountry = true;
                 }
             }
             /*
              * When the contact is not active in the country, return false because we do not allow evaluation
              */
             if (!$contactActiveInCountry) {
                 return false;
             }
             /*
              * Check to see if we have an active version
              */
             $versionType = $this->getVersionService()->findEntityById('Version\\Type', $resource->getType()->getVersionType());
             $version = $this->getVersionService()->findLatestVersionByType($resource->getProject(), $versionType);
             if (is_null($version)) {
                 return false;
             }
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Incorrect privilege (%s) requested', $privilege));
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @param Project[] $projects
  * @param Type      $evaluationType
  * @param int       $display
  * @param int       $source
  *
  * @return array
  */
 public function create(array $projects, Type $evaluationType, $display, $source)
 {
     $evaluationResult = [];
     foreach ($projects as $project) {
         $countries = $this->getGeneralService()->findCountryByProject($project, AffiliationService::WHICH_ONLY_ACTIVE);
         foreach ($countries as $country) {
             /*
              * Create an array of countries to serialize it normally
              */
             $this->countries[$country->getIso3()] = ['id' => $country->getId(), 'country' => $country->getCountry(), 'iso3' => ucwords($country->getIso3())];
             $evaluation = $this->getEvaluationService()->findEvaluationByCountryAndTypeAndProject($country, $evaluationType, $project);
             /*
              * Create a default status for not findable statuses
              */
             if (is_null($evaluation)) {
                 $evaluation = new Evaluation();
                 /*
                  * @var Status
                  */
                 $evaluationStatus = $this->getProjectService()->findEntityById('Funding\\Status', 8);
                 $evaluation->setStatus($evaluationStatus);
             } else {
                 /*
                  * Remove the unwanted coupled entities from the object to avoid problems with serialization
                  * and to keep the evaluation-object small. The relevant information is already stored
                  * in the array and is not needed anymore in the evaluation object itself
                  */
                 $evaluation = clone $evaluation;
                 $evaluation->setContact(null);
                 $evaluation->setProject(null);
                 $evaluation->setCountry(null);
             }
             //Find the latest version
             $versionType = new VersionType();
             $versionType->setId($evaluationType->getId());
             /*
              * This goes wrong for the funding-status because the VersionType === 3 matches the CR which is of course
              * not always present
              */
             if ($this->getEvaluationService()->isEvaluation($evaluationType)) {
                 $version = $this->getVersionService()->findLatestVersionByType($project, $versionType);
             } else {
                 $this->getProjectService()->setProject($project);
                 $version = $this->getProjectService()->getLatestProjectVersion();
             }
             /*
              * We save the country locally to avoid very long calls.
              * The country is also needed as separator
              */
             $evalByProjectAndCountry = [];
             $evalByProjectAndCountry['evaluation'] = $evaluation;
             $evalByProjectAndCountry['result'] = ['id' => $evaluation->getStatus()->getId(), 'cssName' => $evaluation->getStatus()->parseCssName(), 'title' => $this->getEvaluationService()->isEvaluation($evaluationType) ? $evaluation->getStatus()->getStatusEvaluation() : $evaluation->getStatus()->getStatusFunding(), 'description' => $evaluation->getDescription()];
             /*
              * Add a boolean extra to indicate the PL.
              *
              * @var Country
              */
             $countryOfProjectLeader = $this->getGeneralService()->findCountryOfProjectContact($project);
             $evalByProjectAndCountry['isProjectLeader'] = !is_null($countryOfProjectLeader) && $countryOfProjectLeader->getId() === $country->getId();
             $value = $this->getValueFromDisplay($display, $source, $version, $project, $country);
             $evalByProjectAndCountry['value'] = $value;
             /*
              * The evaluation is now an array which contains the evaluation object as first element (with 0 as index)
              * and partners etc as secondary objects
              */
             $evaluationResult[$country->getId()][$project->getId()] = $evalByProjectAndCountry;
         }
     }
     ksort($this->countries);
     $evaluationResult['countries'] = $this->countries;
     return $evaluationResult;
 }
Esempio n. 4
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]);
 }
Esempio n. 5
0
 /**
  * @param Evaluation $evaluation
  *
  * @return bool
  */
 public function isFundingDecisionGiven(Evaluation $evaluation)
 {
     return in_array($evaluation->getStatus()->getId(), [Status::STATUS_ALL_GOOD, Status::STATUS_FAILED, Status::STATUS_SELF_FUNDED]);
 }