Esempio n. 1
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;
 }
Esempio n. 2
0
 /**
  * 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]);
 }
 /**
  * @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]);
 }