/**
  * Load the Project
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $rationale = new Rationale();
     $rationale->setCountry($manager->find("General\\Entity\\Country", 1));
     $rationale->setContact($manager->find("Contact\\Entity\\Contact", 1));
     $rationale->setProject($manager->find("Project\\Entity\\Project", 1));
     $rationale->setRationale('This is the rationale');
     $manager->persist($rationale);
     $manager->flush();
 }
Beispiel #2
0
 /**
  * @param Project $project
  *
  * Temporary function to fill up the rationale for public function table with the relevant data.
  * We will go over each project and find the countries
  */
 public function generateCountryRationaleByProject(Project $project)
 {
     //Get the current (already) present $rationale
     $countriesCollected = new ArrayCollection();
     foreach ($project->getRationale() as $rationale) {
         $countriesCollected->add($rationale->getCountry()->getId());
     }
     $affiliations = $this->getAffiliationService()->findAffiliationByProjectAndWhich($project);
     //Produce an array with unique countries
     foreach ($affiliations as $affiliation) {
         if ($affiliation->getAffiliation()->getOrganisation()->getCountry()->getId() === 0 || $countriesCollected->contains($affiliation->getAffiliation()->getOrganisation()->getCountry()->getId())) {
             continue;
         }
         //Create a new $rationale
         $rationale = new Rationale();
         $rationale->setContact($affiliation->getAffiliation()->getContact());
         $rationale->setCountry($affiliation->getAffiliation()->getOrganisation()->getCountry());
         $rationale->setProject($project);
         $rationale->setRationale(null);
         $this->getEntityManager()->persist($rationale);
         $this->getEntityManager()->flush();
         $countriesCollected->add($affiliation->getAffiliation()->getOrganisation()->getCountry()->getId());
     }
 }
Beispiel #3
0
 /**
  * @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;
 }