/** * @return array */ public function provider() { $dateTime = new \DateTime(); $dateStart = $dateTime->sub(new \DateInterval('P1Y')); $dateEnd = $dateTime->add(new \DateInterval('P4Y')); $dateTime = new \DateTime(); $dateStartActual = $dateTime->sub(new \DateInterval('P6M')); $dateEndActual = $dateTime->add(new \DateInterval('P3Y')); $contactTest = new ContactTest(); $callTest = new CallTest(); $project = new Project(); $project->setCall($callTest->provider()[0][0]); $project->setDateStart($dateStart); $project->setDateEnd($dateEnd); $project->setDateStartActual($dateStartActual); $project->setDateEndActual($dateEndActual); $project->setNumber(Rand::getString(4)); $project->setContact($contactTest->provider()[0][0]); $project->setSummary('This is the summary'); $project->setDescription('This is the description'); $versionType = new Type(); $versionType->setType('Type'); $versionType->setId(1); return [[$project, $versionType]]; }
/** * @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; }
public function testParseProjectVersion() { $date = new \DateTime(); $yesterday = $date->sub(new \DateInterval('P1D')); $date = new \DateTime(); $tomorrow = $date->add(new \DateInterval('P1D')); $project = new Project(); $call = new Call(); $call->setFppCloseDate($yesterday); $project->setCall($call); $this->projectService->setProject($project); $versionType = new Type(); $versionType->setId(Type::TYPE_PO); $version = new Version(); $version->setApproved(Version::STATUS_APPROVED); $version->setVersionType($versionType); $versionService = new VersionService(); $versionService->setVersion($version); $this->assertEquals('No FPP Submitted', $this->projectService->parseProjectVersion($versionService), 'Call close date is yesterday and version is approved'); $this->projectService->getProject()->getCall()->setFppCloseDate($tomorrow); $this->assertContains('PO', $this->projectService->parseProjectVersion($versionService), 'Call close date is tomorrow and version is approved'); $versionService->getVersion()->getVersionType()->setId(Type::TYPE_FPP); $versionService->getVersion()->getVersionType()->setType('fpp'); $this->assertContains('Labelled', $this->projectService->parseProjectVersion($versionService), 'FPP submitted and approved'); $versionService->getVersion()->getVersionType()->setId(Type::TYPE_CR); $this->projectService->getProject()->setDateStartActual($tomorrow); $this->assertEquals('Labelled', $this->projectService->parseProjectVersion($versionService), 'CR Project is labelled (will start)'); $this->projectService->getProject()->setDateStartActual($yesterday); $this->assertEquals('Running', $this->projectService->parseProjectVersion($versionService), 'CR Project is running'); $this->projectService->getProject()->setDateStartActual($yesterday); $this->projectService->getProject()->setDateEndActual($yesterday); $this->assertEquals('Completed', $this->projectService->parseProjectVersion($versionService), 'CR Project is completed'); $versionService->getVersion()->getVersionType()->setId(Type::TYPE_SR); $this->assertEquals('Cancelled', $this->projectService->parseProjectVersion($versionService), 'CR Project is cancelled'); $versionService->getVersion()->getVersionType()->setId('blaat'); $this->assertEquals('Cannot determine state.', $this->projectService->parseProjectVersion($versionService), 'Incomplete state'); }