/** * {@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 Project $project * @param string $emailAddress * * @return bool */ public function inviteViaEmailAddress(Project $project, $emailAddress) { /* * Try to find the contact based on the email address provided */ $contact = $this->getContactService()->findContactByEmail($emailAddress); $projectService = $this->getProjectService()->setProject($project); /* * Create a new invite */ $invite = new Invite(); $invite->setInvite($this->generateInviteKey()); $dateExpire = new \DateTime(); $dateExpire->add(new \DateInterval("P1M")); $invite->setDateExpire($dateExpire); $invite->setProject($projectService->getProject()); $email = $this->getEmailService()->create(); if (is_null($contact)) { //The contact cannot be found. Create a custom deep link $target = $this->getDeeplinkService()->createTargetFromRoute('contact/profile-edit'); $deeplink = $this->getDeeplinkService()->createDeeplink($target, null, $emailAddress); //Set the contact for the email $this->getEmailService()->setTemplate("/project/invite:mail_new"); $email->addTo($emailAddress); } elseif (is_null($contact->getContactOrganisation())) { //The contact can be found. But we forward him to the profile-edit $target = $this->getDeeplinkService()->createTargetFromRoute('contact/profile-edit'); $deeplink = $this->getDeeplinkService()->createDeeplink($target, $contact); //Send the email to an existing contact $this->getEmailService()->setTemplate("/project/invite:mail_existing_no_organisation"); $email->addTo($contact); } else { $target = $this->getDeeplinkService()->createTargetFromRoute('community/project/invite/accept'); $deeplink = $this->getDeeplinkService()->createDeeplink($target, $contact, null, $invite->getInvite()); //Send the email to an existing contact $this->getEmailService()->setTemplate("/project/invite:mail_existing"); $email->addTo($contact); } $invite->setDeeplink($deeplink); $invite->setContact($this->getServiceLocator()->get('zfcuser_auth_service')->getIdentity()); $this->newEntity($invite); /* * @var DeeplinkLink */ $deeplinkLink = $this->getServiceLocator()->get('viewhelpermanager')->get('deeplinkLink'); $email->setCode($invite->getInvite()); $email->setUrl($deeplinkLink($deeplink, 'view', 'target')); $email->setProject($projectService->parseFullName()); /* * Produce a contactService Object */ $contactService = clone $this->getContactService()->setContact($projectService->getProject()->getContact()); $email->setProjectLeader($contactService->parseFullName()); $email->setProjectLeaderOrganisation($contactService->parseOrganisation()); $email->setProjectLeaderEmail($contactService->getContact()->getEmail()); $this->getEmailService()->send($email); return true; }