/** * {@inheritDoc} */ public function setUp() { $this->serviceManager = Bootstrap::getServiceManager(); $this->invite = new Invite(); $this->invite->setId(1); $this->invite->setInvite('This is the invite'); $deeplink = new Deeplink(); $custom = new Custom(); $custom->setEmail('*****@*****.**'); $deeplink->setCustom($custom); $this->invite->setDeeplink($deeplink); $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->inviteLink = $viewHelperManager->get('invitelink'); }
/** * Load the Project * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $invite = new Invite(); $invite->setContact($manager->find("Contact\\Entity\\Contact", 1)); $dateExpire = new \DateTime(); $dateExpire->add(new \DateInterval('P3M')); $invite->setDateExpire($dateExpire); $invite->setDeeplink($manager->find("Deeplink\\Entity\\Deeplink", 1)); $invite->setProject($manager->find("Project\\Entity\\Project", 1)); $invite->setInviteContact([$manager->find("Contact\\Entity\\Contact", 1)]); $invite->setInvite('ABCDEF'); $manager->persist($invite); $manager->flush(); }
/** * @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; }