/** * Produce a form element. * * @param Affiliation $affiliation * @param ProjectService $projectService */ public function __construct(Affiliation $affiliation, ProjectService $projectService) { parent::__construct($affiliation->getId()); foreach ($projectService->parseEditYearRange() as $year) { $fieldSet = new Fieldset($year); $fieldSet->add(['type' => 'Zend\\Form\\Element\\Text', 'name' => 'cost', 'attributes' => ['class' => 'form-control cost-input year-' . $year, 'label' => 'cost', 'placeholder' => _("txt-cost")]]); $this->add($fieldSet); } }
/** * @param Project $project * * @dataProvider provider */ public function testCanCreateFieldset(Project $project) { /** * @var $projectService ProjectService */ $projectService = $this->serviceManager->get(ProjectService::class); $projectService->setProject($project); $affiliation = new Affiliation(); $affiliation->setId(1); $form = new CostPerAffiliationFieldset($affiliation, $projectService); $this->assertInstanceOf("Zend\\Form\\Fieldset", $form); $this->assertInstanceOf("Zend\\InputFilter\\InputFilterProviderInterface", $form); $inputFilter = $form->getInputFilterSpecification(); $this->assertTrue(is_array($inputFilter)); }
/** * */ public function testCanSetAffiliations() { $service = new AffiliationService(); // Create a dummy user entity $affiliation = new Affiliation(); $affiliation->setId(1); // Create a dummy user entity $affiliation2 = new Affiliation(); $affiliation2->setId(2); // Mock the repository, disabling the constructor $userRepositoryMock = $this->getMockBuilder(\Affiliation\Repository\Affiliation::class)->disableOriginalConstructor()->getMock(); $userRepositoryMock->expects($this->once())->method('findAll')->will($this->returnValue([$affiliation, $affiliation2])); // Mock the entity manager $emMock = $this->getMock('EntityManager', ['getRepository'], [], '', false); $emMock->expects($this->any())->method('getRepository')->will($this->returnValue($userRepositoryMock)); $service->setEntityManager($emMock); $this->assertEquals(2, sizeof($service->findAll('affiliation'))); }
/** * @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'); $affiliation = new Affiliation(); $affiliation->setId(1); return [[$project, $affiliation]]; }
/** * Action for the creation of a new project. * * @return ViewModel */ public function createAction() { $project = new Entity\Project(); $data = array_merge_recursive($this->getRequest()->getPost()->toArray()); $data['contact'] = $this->zfcUserAuthentication()->getIdentity()->getId(); $form = new ProjectBasics($this->getServiceLocator(), $project); $form->setInputFilter($this->getServiceLocator()->get('project_project_form_filter')); $form->bind($project); $form->setData($data); $call = $this->getCallService()->findOpenCall(Entity\Version\Type::TYPE_PO); if ($this->getRequest()->isPost() && $form->isValid()) { $project = $form->getData(); //Set the project leader to the logged in user $projectChallenge = new Entity\Challenge(); $projectChallenge->setProject($project); $projectChallenge->setChallenge($this->getGeneralService()->findChallengeById($data['projectChallenge'])); $arrayCollection = new ArrayCollection([$projectChallenge]); $project->addProjectChallenge($arrayCollection); $project->setNumber($this->getProjectService()->findNextProjectNumberInCall($call)); $project->setCall($call); $project = $this->getProjectService()->newEntity($project); //Reload the project to have the docRef /* * We need the contactService to add the contact and organisation in the affiliation */ $contactService = clone $this->getContactService(); $contactService->setContact($this->zfcUserAuthentication()->getIdentity()); //Create the affiliation $affiliation = new Affiliation(); $affiliation->setProject($project); $affiliation->setContact($contactService->getContact()); $affiliation->setOrganisation($contactService->findOrganisationService()->getOrganisation()); $this->getAffiliationService()->newEntity($affiliation); $project = $this->getProjectService()->findEntityById('project', $project->getId()); return $this->redirect()->toRoute('community/project/project/basics', ['docRef' => $project->getDocRef()]); } return new ViewModel(['form' => $form, 'call' => $call]); }
/** * @param Affiliation $affiliation * @param $year * @param $period * * @return AffiliationPdf * @throws \Exception */ public function render(Affiliation $affiliation, $year, $period) { /** @var ProjectService $projectService */ $projectService = $this->getProjectService()->setProject($affiliation->getProject()); $latestVersion = $projectService->getLatestProjectVersion(); $versionService = $this->getVersionService()->setVersion($latestVersion); $contactService = clone $this->getContactService()->setContact($affiliation->getContact()); if (!is_null($this->getAffiliationService()->getFinancialContact($affiliation))) { $financialContactService = clone $this->getContactService()->setContact($this->getAffiliationService()->getFinancialContact($affiliation)); } else { $financialContactService = null; } $affiliationService = $this->getAffiliationService()->setAffiliation($affiliation); $versionContributionInformation = $versionService->getProjectVersionContributionInformation($affiliation, $latestVersion, $year); $invoiceMethod = $this->getInvoiceService()->findInvoiceMethod($projectService->getProject()->getCall()->getProgram()); $pdf = new AffiliationPdf(); $pdf->setTemplate($this->getModuleOptions()->getPaymentSheetTemplate()); $pdf->addPage(); $pdf->SetFontSize(9); $pdf->SetTopMargin(55); $pdf->writeHTMLCell(0, 0, '', '', '<h1 style="color: #00a651">' . sprintf($this->translate("txt-payment-sheet-year-%s-period-%s"), $year, $period) . '</h1>', 0, 1, 0, true, '', true); $pdf->Ln(); $pdf->Line(10, 65, 190, 65, ['color' => [0, 166, 81]]); //Project information $pdf->writeHTMLCell(0, 0, '', '', sprintf("<h3>%s</h3>", $this->translate("txt-project-details")), 0, 1, 0, true, '', true); $projectDetails = [[$this->translate("txt-project-number"), $projectService->getProject()->getNumber()], [$this->translate("txt-project-name"), $projectService->getProject()->getProject()], [$this->translate("txt-start-date"), $projectService->parseOfficialDateStart()->format('d-m-Y')], [$this->translate("txt-start-end"), $projectService->parseOfficialDateEnd()->format('d-m-Y')], [$this->translate("txt-version-name"), $versionService->getVersion()->getVersionType()], [$this->translate("txt-version-status"), $versionService->parseStatus()], [$this->translate("txt-version-date"), !is_null($versionService->getVersion()->getDateReviewed()) ? $versionService->getVersion()->getDateReviewed()->format("d-m-Y") : '']]; $pdf->coloredTable([], $projectDetails, [55, 130]); //Partner information $pdf->writeHTMLCell(0, 0, '', '', sprintf("<h3>%s</h3>", $this->translate("txt-project-partner")), 0, 1, 0, true, '', true); $partnersDetails = [[$this->translate("txt-organisation"), $affiliationService->getAffiliation()->getOrganisation()], [$this->translate("txt-organisation-type"), $affiliationService->getAffiliation()->getOrganisation()->getType()], [$this->translate("txt-country"), $affiliationService->getAffiliation()->getOrganisation()->getCountry()], [$this->translate("txt-total-person-years"), $this->parseEffort($versionContributionInformation->totalEffort)], [$this->translate("txt-total-costs"), $this->parseKiloCost($versionContributionInformation->totalCost)], [$this->translate("txt-average-cost"), ($versionContributionInformation->totalEffort > 0 ? $this->parseKiloCost($versionContributionInformation->totalCost / $versionContributionInformation->totalEffort) : '-') . '/PY']]; $pdf->coloredTable([], $partnersDetails, [55, 130]); //Technical contact $pdf->writeHTMLCell(0, 0, '', '', sprintf("<h3>%s</h3>", $this->translate("txt-technical-contact")), 0, 1, 0, true, '', true); $partnersDetails = [[$this->translate("txt-name"), trim($contactService->parseAttention() . ' ' . $contactService->parseFullName())], [$this->translate("txt-email"), $contactService->getContact()->getEmail()]]; $pdf->coloredTable([], $partnersDetails, [55, 130]); if (!is_null($financialContactService)) { //Financial contact $pdf->writeHTMLCell(0, 0, '', '', sprintf("<h3>%s</h3>", $this->translate("txt-financial-contact")), 0, 1, 0, true, '', true); $financialAddress = $financialContactService->getFinancialAddress(); $financialDetails = [[$this->translate("txt-name"), trim($financialContactService->parseAttention() . ' ' . $financialContactService->parseFullName())], [$this->translate("txt-email"), $financialContactService->getContact()->getEmail()], [$this->translate("txt-vat-number"), $affiliationService->parseVatNumber($affiliationService->getAffiliation())], [$this->translate("txt-billing-address"), !is_null($financialAddress) ? sprintf("%s \n %s\n%s\n%s %s\n%s", $this->getOrganisationService()->parseOrganisationWithBranch($affiliationService->getAffiliation()->getFinancial()->getBranch(), $affiliationService->getAffiliation()->getFinancial()->getOrganisation()), trim($financialContactService->parseAttention() . ' ' . $financialContactService->parseFullName()), $financialAddress->getAddress()->getAddress(), $financialAddress->getAddress()->getZipCode(), $financialAddress->getAddress()->getCity(), strtoupper($financialAddress->getAddress()->getCountry())) : "No billing address could be found"], [$this->translate("txt-preferred-delivery"), is_null($affiliationService->getAffiliation()->getFinancial()) || is_null($affiliationService->getAffiliation()->getFinancial()->getOrganisation()->getFinancial()) ? 'No billing organisation known' : ($affiliationService->getAffiliation()->getFinancial()->getOrganisation()->getFinancial()->getEmail() === Financial::EMAIL_DELIVERY ? sprintf($this->translate("txt-by-email-to-%s"), $financialContactService->getContact()->getEmail()) : $this->translate("txt-by-postal-mail"))]]; $pdf->coloredTable([], $financialDetails, [55, 130]); } $pdf->addPage(); $pdf->writeHTMLCell(0, 0, '', '', '<h3>' . $this->translate("txt-contribution-overview") . '</h3>', 0, 1, 0, true, '', true); $pdf->Ln(); //Funding information $header = [$this->translate("txt-period"), $this->translate("txt-funding-status"), $this->translate("txt-costs"), $this->translate("txt-fee-percentage"), $this->translate("txt-contribution"), $this->translate("txt-due"), $this->translate("txt-amount-due")]; $fundingDetails = []; $totalDueBasedOnProjectData = 0; foreach ($projectService->parseYearRange(false, $affiliation) as $projectYear) { $dueFactor = $affiliationService->parseContributionFactorDue($projectYear, $year, $period); $yearData = []; $yearData[] = $projectYear; if ($affiliationService->isSelfFunded()) { $yearData[] = $this->translate("txt-self-funded"); } elseif (!is_null($affiliationService->getFundingInYear($projectYear))) { $yearData[] = $affiliationService->getFundingInYear($projectYear)->getStatus()->getStatus(); } else { $yearData[] = "-"; } if ($invoiceMethod->getId() === Method::METHOD_PERCENTAGE) { if (array_key_exists($projectYear, $versionContributionInformation->cost)) { $dueInYear = $versionContributionInformation->cost[$projectYear] / 100 * $projectService->findProjectFeeByYear($projectYear)->getPercentage(); $yearData[] = $this->parseCost($versionContributionInformation->cost[$projectYear]); } else { $dueInYear = 0; $yearData[] = $this->parseCost(0); } if ($affiliationService->isFundedInYear($projectYear)) { $yearData[] = $this->parsePercent($projectService->findProjectFeeByYear($projectYear)->getPercentage()); } else { $yearData[] = $this->parsePercent(0); } } else { if (array_key_exists($projectYear, $versionContributionInformation->cost)) { $dueInYear = $versionContributionInformation->effort[$projectYear] * $projectService->findProjectFeeByYear($projectYear)->getContribution(); $yearData[] = $this->parseEffort($versionContributionInformation->effort[$projectYear]); } else { $dueInYear = 0; $yearData[] = 0; } if ($affiliationService->isFundedInYear($projectYear)) { $yearData[] = $this->parseCost($projectService->findProjectFeeByYear($projectYear)->getContribution()); } else { $yearData[] = $this->parseCost(0); } } if ($affiliationService->isFundedInYear($projectYear)) { $yearData[] = $this->parseCost($dueInYear); } else { $yearData[] = $this->parseCost(0); } $yearData[] = $this->parsePercent($dueFactor * 100); $yearData[] = $this->parseCost($dueInYear * $dueFactor); $totalDueBasedOnProjectData += $dueInYear * $dueFactor; $fundingDetails[] = $yearData; } //Add the total column $totalColumn = ['', '', '', '', '', $this->translate("txt-total"), $this->parseCost($totalDueBasedOnProjectData)]; $fundingDetails[] = $totalColumn; $pdf->coloredTable($header, $fundingDetails, [15, 25, 35, 25, 25, 25, 35], true); $contributionDue = $affiliationService->parseContributionDue($versionService->getVersion(), $year, $period); $contributionPaid = $affiliationService->parseContributionPaid($year, $period); $balance = $affiliationService->parseBalance($versionService->getVersion(), $year, $period); $total = $affiliationService->parseTotal($versionService->getVersion(), $year, $period); $contribution = $affiliationService->parseContribution($versionService->getVersion(), $year, $period); $pdf->writeHTMLCell(0, 0, '', '', '<h3>' . sprintf($this->translate("txt-already-sent-invoices-upto-year-%s-period-%s"), $year, $period) . '</h3>', 0, 1, 0, true, '', true); $pdf->Ln(); //Funding information $header = [$this->translate("txt-invoice"), $this->translate("txt-period"), $this->translate("txt-date"), $this->translate("txt-contribution"), $this->translate("txt-paid"), $this->translate("txt-invoiced")]; //Old Invoices $previousInvoices = []; foreach ($affiliation->getInvoice() as $affiliationInvoice) { if (!is_null($affiliationInvoice->getInvoice()->getDayBookNumber()) && ($affiliationInvoice->getYear() < $year || $affiliationInvoice->getYear() === $year && $affiliationInvoice->getPeriod() < $period)) { $previousInvoices[] = $affiliationInvoice; } } $currentInvoiceDetails = []; if (sizeof($previousInvoices) === 0) { $currentInvoiceDetails[] = [$this->translate("txt-no-invoices-found")]; } else { /** * @var $affiliationInvoice AffiliationInvoice */ foreach ($previousInvoices as $affiliationInvoice) { $this->getInvoiceService()->setInvoice($affiliationInvoice->getInvoice()); $currentInvoiceDetails[] = [$affiliationInvoice->getInvoice()->getInvoiceNr(), sprintf("%s-%s", $affiliationInvoice->getYear(), $affiliationInvoice->getPeriod()), $affiliationInvoice->getInvoice()->getDateSent()->format('d-m-Y'), $this->parseCost($this->getInvoiceService()->parseSumAmount()), !is_null($affiliationInvoice->getInvoice()->getBookingDate()) ? $affiliationInvoice->getInvoice()->getBookingDate()->format('d-m-Y') : '', $this->parseCost($this->getInvoiceService()->parseTotal())]; } } //Add the total column $currentInvoiceDetails[] = ['', '', $this->translate("txt-total"), $this->parseCost($contributionPaid), '', '']; $pdf->coloredTable($header, $currentInvoiceDetails, [40, 35, 25, 25, 25, 35], true); $pdf->writeHTMLCell(0, 0, '', '', '<h3>' . $this->translate("txt-correction-calculation") . '</h3>', 0, 1, 0, true, '', true); $correctionDetails = [[sprintf($this->translate("txt-total-contribution-invoiced-upto-year-%s-period-%s"), $year, $period), $this->parseCost($contributionPaid)], [sprintf($this->translate("txt-total-contribution-amount-due-upto-year-%s-period-%s"), $year, $period), $this->parseCost($contributionDue)], [$this->translate("txt-correction"), $this->parseCost($balance)]]; $pdf->coloredTable([], $correctionDetails, [95, 85], true); $pdf->writeHTMLCell(0, 0, '', '', '<h3>' . sprintf($this->translate("txt-invoice-for-year-%s-period-%s"), $year, $period) . '</h3>', 0, 1, 0, true, '', true); $pdf->Ln(); //Partner information $header = [$this->translate("txt-period"), $this->translate("txt-contribution"), $this->translate("txt-amount")]; $upcomingDetails = [[sprintf("%s-%s", $year, $period), sprintf($this->translate("txt-%s-contribution-for-%s"), $this->parsePercent($affiliationService->parseContributionFactor($year, $period) * 100), $year), $this->parseCost($contribution)], ['', $this->translate("txt-correction"), $this->parseCost($balance)], ['', $this->translate("txt-total"), $this->parseCost($total)]]; $pdf->coloredTable($header, $upcomingDetails, [25, 70, 85], true); //Funding information $header = [$this->translate("txt-invoice-number"), $this->translate("txt-period"), $this->translate("txt-date"), $this->translate("txt-paid"), $this->translate("txt-total-excl-vat"), $this->translate("txt-total")]; //Old Invoices $upcomingInvoices = []; foreach ($affiliation->getInvoice() as $affiliationInvoice) { if ($affiliationInvoice->getYear() > $year or $affiliationInvoice->getYear() === $year and $affiliationInvoice->getPeriod() > $period) { if (!is_null($affiliationInvoice->getInvoice()->getDateSent())) { $upcomingInvoices[] = $affiliationInvoice; } } } $upcomingInvoiceDetails = []; if (sizeof($upcomingInvoices) > 0) { $pdf->writeHTMLCell(0, 0, '', '', '<h3>' . sprintf($this->translate("txt-already-sent-invoices-after-year-%s-period-%s") . '</h3>', $year, $period), 0, 1, 0, true, '', true); $pdf->Ln(); /** * @var $affiliationInvoice AffiliationInvoice */ foreach ($upcomingInvoices as $affiliationInvoice) { $this->getInvoiceService()->setInvoice($affiliationInvoice->getInvoice()); $upcomingInvoiceDetails[] = [$affiliationInvoice->getInvoice()->getInvoiceNr(), sprintf("%s-%s", $affiliationInvoice->getYear(), $affiliationInvoice->getPeriod()), $affiliationInvoice->getInvoice()->getDateSent()->format('d-m-Y'), !is_null($affiliationInvoice->getInvoice()->getBookingDate()) ? $affiliationInvoice->getInvoice()->getBookingDate()->format('d-m-Y') : '', $this->parseCost($this->getInvoiceService()->parseSumAmount()), $this->parseCost($this->getInvoiceService()->parseTotal())]; } $pdf->coloredTable($header, $upcomingInvoiceDetails, [45, 25, 25, 25, 25, 35], true); } return $pdf; }
/** * @param Affiliation $affiliation * @param string $action */ public function updateCountryRationaleByAffiliation(Affiliation $affiliation, $action) { switch ($action) { case self::AFFILIATION_DEACTIVATE: $rationale = $this->findRationaleByProjectAndCountry($affiliation->getProject(), $affiliation->getOrganisation()->getCountry()); //We need to check the rationale and maybe delete or update the contact persons. if (!is_null($rationale) && $rationale->getContact()->getId() === $affiliation->getContact()->getId()) { //There is only 1 rationale, and our partner is contact person, so we need to update the contact //or delete the rationale if there are no other countries available for the project $countryFound = false; //The country is still active in the project, we need to assign a new rationale responsible foreach ($this->getAffiliationService()->findAffiliationByProjectAndCountryAndWhich($affiliation->getProject(), $affiliation->getOrganisation()->getCountry()) as $affiliationService) { //Give the country rationale to the first contact in the affiliation $rationale->setContact($affiliationService->getAffiliation()->getContact()); $this->updateEntity($rationale); break 2; } if (!$countryFound) { $this->removeEntity($rationale); } } break; case self::AFFILIATION_REACTIVATE: //Simply use this function as a proxy to the generate function $this->generateCountryRationaleByProject($affiliation->getProject()); break; } }
/** * Reactivate an affiliation * * @param Affiliation $affiliation */ public function reactivateAffiliation(Affiliation $affiliation) { $affiliation->setDateEnd(null); $this->updateEntity($affiliation); }
/** * @param Affiliation $affiliation * * @return array */ public function findContactsInAffiliation(Affiliation $affiliation) { $contacts = []; $contactRole = []; /* * Add the technical contact */ $contacts[$affiliation->getContact()->getId()] = $affiliation->getContact(); $contactRole[$affiliation->getContact()->getId()][] = 'Technical Contact'; /* * Add the financial contact */ if (!is_null($affiliation->getFinancial())) { $contacts[$affiliation->getFinancial()->getContact()->getId()] = $affiliation->getFinancial()->getContact(); $contactRole[$affiliation->getFinancial()->getContact()->getId()][] = 'Financial Contact'; } /* * Add the associates */ foreach ($affiliation->getAssociate() as $associate) { /* * Add the associates */ $contacts[$associate->getId()] = $associate; $contactRole[$associate->getId()][] = 'Associate'; } /* * Add the workpackage leaders */ foreach ($affiliation->getProject()->getWorkpackage() as $workpackage) { /* * Add the work package leaders */ if (!is_null($workpackage->getContact()->getContactOrganisation()) && $workpackage->getContact()->getContactOrganisation()->getOrganisation()->getId() === $affiliation->getOrganisation()->getId()) { $contacts[$workpackage->getContact()->getId()] = $workpackage->getContact(); $contactRole[$workpackage->getContact()->getId()][] = 'Workpackage leader'; } } $contactRole = array_map('array_unique', $contactRole); //Store the values local for the use of the toArray function $this->contacts = $contacts; return ['contacts' => $contacts, 'contactRole' => $contactRole]; }
/** * @param Invite $invite * @param Contact $contact * @param $joinMethod * * @return bool * * @throws \Exception */ public function acceptInvitation(Invite $invite, Contact $contact, $joinMethod) { $contactService = clone $this->getContactService(); $contactService->setContact($contact); /* * Introduce an extra instance of the contactService */ $projectContactService = clone $this->getContactService(); $projectContactService->setContact($invite->getProject()->getContact()); if (!$contactService->hasOrganisation()) { throw new \Exception("An organisation is needed to accept an invitation"); } /* * The contact-organisation is already in the project. Find the affiliation and create the join */ $affiliation = $this->getAffiliationService()->findAffiliationByProjectAndContactAndWhich($invite->getProject(), $contact, AffiliationService::WHICH_ALL); switch ($joinMethod) { case InviteAccept::OPTION_NEW_PARTNER: //new: txt-new-partner /* * Send an email to the project leader */ $email = $this->getEmailService()->create(); $this->getEmailService()->setTemplate("/project/invite/accepted"); //Set the contactService to the emailService to have the correct parameters present $this->getEmailService()->setContactService($contactService); $email->addTo($invite->getProject()->getContact()); $email->setProject($invite->getProject()); $email->setProjectLeader($projectContactService->parseFullName()); $email->setAcceptor($contactService->parseFullName()); $email->setAcceptorOrganisation($contactService->parseOrganisation()); $email->setAcceptorCountry($contactService->parseCountry()); $this->getEmailService()->send(); /* * Send an email tot he acceptor */ $email = $this->getEmailService()->create(); $this->getEmailService()->setTemplate("/project/invite/confirmed"); $this->getEmailService()->setContactService($contactService); $email->addTo($contactService->getContact()); $email->setProject($invite->getProject()); $email->setProjectLeader($projectContactService->parseFullName()); $email->setProjectLeaderOrganisation($projectContactService->parseOrganisation()); $email->setProjectLeaderCountry($projectContactService->parseCountry()); $email->setProjectLeaderEmail($projectContactService->getContact()->getEmail()); $this->getEmailService()->send(); /* * Update the technical contact for the organisation */ /* * If the Affiliation is null, create a new one else, update the current one */ $affiliation = new Affiliation(); $affiliation->setOrganisation($contactService->getContact()->getContactOrganisation()->getOrganisation()); $affiliation->setBranch($contactService->getContact()->getContactOrganisation()->getBranch()); $affiliation->setProject($invite->getProject()); $affiliation->setContact($contactService->getContact()); $this->getAffiliationService()->newEntity($affiliation); //Update the rationale if not already set if (is_null($this->getProjectService()->findRationaleByProjectAndCountry($invite->getProject(), $contactService->parseCountry()))) { $rationale = new Rationale(); $rationale->setContact($contactService->getContact()); $rationale->setProject($invite->getProject()); $rationale->setCountry($contactService->parseCountry()); $rationale->setRationale(null); $this->getProjectService()->newEntity($rationale); } break; case InviteAccept::OPTION_FINANCIAL_CONTACT: //financial: txt-financial-contact if (is_null($affiliation)) { throw new \Exception("An affiliation is needed to accept an invitation"); } $financial = $affiliation->getFinancial(); if (is_null($financial)) { $financial = new Financial(); $financial->setAffiliation($affiliation); $financial->setContact($contactService->getContact()); $financial->setOrganisation($contactService->getContact()->getContactOrganisation()->getOrganisation()); $this->getAffiliationService()->newEntity($financial); } else { $financial->setContact($contactService->getContact()); $financial->setOrganisation($contactService->getContact()->getContactOrganisation()->getOrganisation()); $this->getAffiliationService()->updateEntity($financial); } //No break //No break case InviteAccept::OPTION_ADDITIONAL_CONTACT: //associate: txt-additional-contact $affiliation->setAssociate([$contactService->getContact()]); $affiliation->setDateEnd(null); //Remove the dateEnd (if not already done) $this->getAffiliationService()->updateEntity($affiliation); break; case InviteAccept::OPTION_MAIN_TECHNICAL_CONTACT: //new: txt-main-technical-contact if (is_null($affiliation)) { throw new \Exception("An affiliation is needed to accept an invitation"); } $affiliation->setContact($contactService->getContact()); $this->getAffiliationService()->updateEntity($affiliation); break; } $invite->setInviteContact([$contactService->getContact()]); $this->updateEntity($invite); //Refresh the permissions of the project return true; }
/** * @return ViewModel */ public function addAffiliationAction() { $organisationService = $this->getOrganisationService()->setOrganisationId($this->params('id')); $data = array_merge($this->getRequest()->getPost()->toArray()); $form = new AddAffiliation($this->getOrganisationService(), $this->getProjectService()); $form->setData($data); if ($this->getRequest()->isPost()) { if (isset($data['cancel'])) { return $this->redirect()->toRoute('zfcadmin/organisation/view', ['id' => $organisationService->getOrganisation()->getId()], ['fragment' => 'project']); } if ($form->isValid()) { $formData = $form->getData(); $project = $this->getProjectService()->setProjectId((int) $formData['project'])->getProject(); $contact = $this->getContactService()->findEntityById('contact', (int) $formData['contact']); $branch = $formData['branch']; $affiliation = new Affiliation(); $affiliation->setProject($project); $affiliation->setOrganisation($organisationService->getOrganisation()); if (!empty($branch)) { $affiliation->setBranch($branch); } $affiliation->setContact($contact); $this->getAffiliationService()->newEntity($affiliation); $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-organisation-%s-has-successfully-been-added-to-project-%s"), $organisationService->getOrganisation(), $project)); return $this->redirect()->toRoute('zfcadmin/organisation/view', ['id' => $organisationService->getOrganisation()->getId()], ['fragment' => 'project']); } } return new ViewModel(['organisationService' => $organisationService, 'form' => $form]); }
/** * @param Affiliation $affiliation * * @return array */ private function parseExtendedAffiliationOverview(Affiliation $affiliation) { $rows = []; $cols = []; $organisationService = $this->getOrganisationService()->setOrganisation($affiliation->getOrganisation()); $contactService = clone $this->getContactService(); $contactService->setContact($affiliation->getContact()); $cols['dt'] = ['width' => 2000, 'align' => '']; $cols['dd'] = ['width' => $this->tableWidth - 2000, 'align' => '']; $rows[] = ['dt' => $affiliation->getOrganisation()->getCountry()->getCountry(), 'dd' => $organisationService->parseOrganisationWithBranch($affiliation->getBranch())]; if ($affiliation->getDescription()->count() > 0) { $rows[] = ['dt' => 'Description', 'dd' => $this->cleanHTML($affiliation->getDescription()->first()->getDescription())]; } $rows[] = ['dt' => 'Type', 'dd' => $organisationService->getOrganisation()->getType()->getDescription()]; $rows[] = ['dt' => 'Contact Person', 'dd' => $contactService->parseAttention() . ' ' . $contactService->parseFullname()]; $rows[] = ['dt' => 'Email Address', 'dd' => $contactService->getContact()->getEmail()]; $rows[] = ['dt' => 'Main role and added-value for the project', 'dd' => $affiliation->getMainContribution()]; $rows[] = ['dt' => 'Market access', 'dd' => $affiliation->getMarketAccess()]; return ['cols' => $cols, 'rows' => $rows]; }