Ejemplo n.º 1
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  * @param RationaleEntity         $rationale
  */
 public function __construct(ServiceLocatorInterface $serviceLocator, RationaleEntity $rationale)
 {
     $projectService = $serviceLocator->get(ProjectService::class);
     $contactService = clone $serviceLocator->get('contact_contact_service');
     parent::__construct();
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'form-horizontal');
     $this->add(['type' => 'Zend\\Form\\Element\\Textarea', 'name' => 'rationale', 'options' => ['label' => _("txt-rationale"), 'help-block' => _("txt-detailed-rationale-explanation")], 'attributes' => ['class' => 'form-control', 'rows' => 12]]);
     $contactsInProject = [];
     /*
      * A form element for a contact (project leader) is only needed when a projectService has already a project
      * So when we are editing a project. If not, simply replace it with the currently logged in user
      */
     if (!is_null($projectService->getProject())) {
         /*
          * @var Contact[]
          */
         $contactsInProject = $contactService->findContactsInProject($projectService);
     }
     $valueOptions = [];
     foreach ($contactsInProject as $contact) {
         /*
          * Filter the contacts based on the country
          */
         if (!is_null($contact->getContactOrganisation()) && $contact->getContactOrganisation()->getOrganisation()->getCountry()->getId() === $rationale->getCountry()->getId()) {
             $valueOptions[$contact->getId()] = $contact->getDisplayName();
         }
     }
     asort($valueOptions);
     $this->add(['type' => 'Zend\\Form\\Element\\Select', 'name' => 'contact', 'options' => ['value_options' => $valueOptions, 'label' => _("txt-nationale-coordinator")], 'attributes' => ['class' => 'form-control', 'required' => true]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-update-rationale")]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]);
 }
Ejemplo n.º 2
0
 /**
  * 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();
 }
Ejemplo n.º 3
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());
     }
 }
Ejemplo n.º 4
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;
 }