/** * @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]]; }
/** * {@inheritDoc} */ public function setUp() { $this->serviceManager = Bootstrap::getServiceManager(); $this->versionService = $this->serviceManager->get(VersionService::class); $version = new Version(); $version->setId(1); $versionType = new Type(); $versionType->setDescription('This is the description'); $version->setVersionType($versionType); $this->versionService->setVersion($version); $project = new Project(); $project->setProject('This is the project'); $this->projectService = $this->serviceManager->get(ProjectService::class); // $this->projectService->setProject($project); $this->projectService->setProjectId(1); $this->versionService->getVersion()->setProject($this->projectService->getProject()); $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock(); $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $viewHelperManager = $this->serviceManager->get('viewhelpermanager'); $viewHelperManager->setService('isAllowed', $authorizeServiceMock); $urlViewHelperMock = $this->getMockBuilder(Url::class)->disableOriginalConstructor()->getMock(); $urlViewHelperMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $viewHelperManager->setService('url', $urlViewHelperMock); $this->versionLink = $viewHelperManager->get('versionlink'); }
/** * Go over the required document types. */ public function checkDocumentTypes() { /* * Documents */ $documentsTypesNotFound = []; foreach ($this->versionType->getDocumentType() as $requiredDocumentType) { $documentTypeFound = false; foreach ($this->getProjectService()->getProject()->getDocument() as $document) { if ($document->getType()->getId() === $requiredDocumentType->getId()) { $documentTypeFound = true; } } if (!$documentTypeFound) { $documentsTypesNotFound[] = $requiredDocumentType->getType(); } } switch (true) { case sizeof($documentsTypesNotFound) === 1: $this->errors[self::CHECKLIST_DOCUMENTS] = sprintf('The required document of type ‘%s’ is missing in your %s', implode(', ', $documentsTypesNotFound), $this->getProjectLink('management', 'proposal documents section')); break; case sizeof($documentsTypesNotFound) > 1: $this->errors[self::CHECKLIST_DOCUMENTS] = sprintf('The required documents of types ‘%s’ is missing in your %s', implode(', ', $documentsTypesNotFound), $this->getProjectLink('management', 'proposal documents section')); break; } }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $versionType = new Type(); $versionType->setType(Type::TYPE_PO); $versionType->setDescription('This is a project outline'); $manager->persist($versionType); $versionType = new Type(); $versionType->setType(Type::TYPE_FPP); $versionType->setDescription('This is a full project proposal'); $manager->persist($versionType); $versionType = new Type(); $versionType->setType(Type::TYPE_CR); $versionType->setDescription('This is a change request'); $manager->persist($versionType); $versionType = new Type(); $versionType->setType(Type::TYPE_SR); $versionType->setDescription('This is a stop request'); $manager->persist($versionType); $manager->flush(); }
/** * @param ProjectService $projectService * @param Type $type */ public function __construct(ProjectService $projectService, Type $type) { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('class', 'form-horizontal'); $this->type = $type; $this->projectService = $projectService; /* * Create an array of required documents */ $versionDocuments = []; if (sizeof($type->getDocumentType()) > 0 && sizeof($projectService->getProject()->getDocument()) > 0) { foreach ($type->getDocumentType() as $requiredDocumentType) { foreach ($projectService->getProject()->getDocument() as $document) { if ($document->getType()->getId() === $requiredDocumentType->getId()) { $versionDocuments[$document->getId()] = sprintf(_("Document: %s (%s)"), $document->getDocument(), $document->getType()); } } } } $this->add(['type' => 'Zend\\Form\\Element\\MultiCheckbox', 'name' => 'versionDocuments', 'options' => ['label' => _("txt-version-documents"), 'help-block' => _("txt-select-version-documents"), 'value_options' => $versionDocuments]]); $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'create', 'attributes' => ['class' => "btn btn-primary", 'value' => sprintf(_("Submit %s"), $type)]]); }
public function testParseStatus() { $version = new Version(); $versionType = new Type(); $versionType->setType(Type::TYPE_PO); $version->setVersionType($versionType); $this->versionService->setVersion($version); $this->assertEquals('Unsubmitted', $this->versionService->parseStatus()); $this->versionService->getVersion()->setDateSubmitted(new \DateTime()); $this->versionService->getVersion()->setDateReviewed(null); $this->assertEquals('Decision Pending', $this->versionService->parseStatus()); $this->versionService->getVersion()->setDateReviewed(new \DateTime()); $this->versionService->getVersion()->setApproved(Version::STATUS_REJECTED); $this->assertEquals('Rejected', $this->versionService->parseStatus()); $this->versionService->getVersion()->setApproved(Version::STATUS_APPROVED); $this->assertEquals('Approved', $this->versionService->parseStatus()); $this->versionService->getVersion()->setApproved(Version::STATUS_SELECTED); $this->assertEquals('Selected', $this->versionService->parseStatus()); $this->versionService->getVersion()->setApproved(Version::STATUS_RESUBMIT); $this->assertEquals('Resubmit', $this->versionService->parseStatus()); }
public function testHasProjectTypeDescriptionArray() { $type = new Type(); $this->assertTrue(is_array($type->getTypeDescription())); }
/** * @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; }
/** * Return true when the call is open specified for the given type * * @param $type ; * * @return bool */ public function isOpen(Type $type) { switch ($type->getId()) { case Type::TYPE_PO: return in_array($this->getCallStatus()->result, [self::PO_GRACE, self::PO_OPEN]); case Type::TYPE_FPP: return in_array($this->getCallStatus()->result, [self::FPP_OPEN, self::FPP_GRACE]); default: return true; } }
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'); }