コード例 #1
1
 /**
  * @return \Zend\Http\Response|ViewModel
  *
  * @throws \Doctrine\ORM\ORMException
  */
 public function financialAction()
 {
     $affiliationService = $this->getAffiliationService()->setAffiliationId($this->getEvent()->getRouteMatch()->getParam('id'));
     if ($affiliationService->isEmpty()) {
         return $this->notFoundAction();
     }
     /** @var ProjectService $projectService */
     $projectService = $this->getProjectService()->setProject($affiliationService->getAffiliation()->getProject());
     if ($projectService->isEmpty()) {
         return $this->notFoundAction();
     }
     /** @var OrganisationService $organisationService */
     $organisationService = $this->getOrganisationService()->setOrganisation($affiliationService->getAffiliation()->getOrganisation());
     if ($organisationService->isEmpty()) {
         return $this->notFoundAction();
     }
     $formData = ['preferredDelivery' => \Organisation\Entity\Financial::EMAIL_DELIVERY, 'omitContact' => \Organisation\Entity\Financial::OMIT_CONTACT];
     $branch = null;
     $financialAddress = null;
     $organisationFinancial = null;
     if (!is_null($affiliationService->getAffiliation()->getFinancial())) {
         //We have a financial organisation, so populate the form with this data
         $organisationService = $this->getOrganisationService()->setOrganisation($affiliationService->getAffiliation()->getFinancial()->getOrganisation());
         $organisationFinancial = $affiliationService->getAffiliation()->getFinancial()->getOrganisation()->getFinancial();
         $branch = $affiliationService->getAffiliation()->getFinancial()->getBranch();
         $formData['attention'] = $affiliationService->getAffiliation()->getFinancial()->getContact()->getDisplayName();
         /** @var ContactService $contactService */
         $contactService = $this->getContactService()->setContact($affiliationService->getAffiliation()->getFinancial()->getContact());
         $formData['contact'] = $affiliationService->getAffiliation()->getFinancial()->getContact()->getId();
         if (!is_null($financialAddress = $contactService->getFinancialAddress())) {
             $financialAddress = $contactService->getFinancialAddress()->getAddress();
             $formData['address'] = $financialAddress->getAddress();
             $formData['zipCode'] = $financialAddress->getZipCode();
             $formData['city'] = $financialAddress->getCity();
             $formData['country'] = $financialAddress->getCountry()->getId();
         }
     }
     $formData['organisation'] = $organisationService->parseOrganisationWithBranch($branch);
     $formData['registeredCountry'] = $organisationService->getOrganisation()->getCountry()->getId();
     if (!is_null($organisationFinancial)) {
         $organisationFinancial = $affiliationService->getAffiliation()->getOrganisation()->getFinancial();
         $formData['preferredDelivery'] = $organisationFinancial->getEmail();
         $formData['vat'] = $organisationFinancial->getVat();
         $formData['omitContact'] = $organisationFinancial->getOmitContact();
     }
     $form = new FinancialForm($affiliationService, $this->getGeneralService());
     $form->setData($formData);
     if ($this->getRequest()->isPost() && $form->setData($_POST) && $form->isValid()) {
         $formData = $form->getData();
         //We need to find the organisation, first by tring the VAT, then via the name and country and then just create it
         $organisation = null;
         //Check if an organisation with the given VAT is already found
         $organisationFinancial = $this->getOrganisationService()->findFinancialOrganisationWithVAT($formData['vat']);
         //If the organisation is found, it has by default an organiation
         if (!is_null($organisationFinancial)) {
             $organisation = $organisationFinancial->getOrganisation();
         }
         //try to find the organisation based on te country and name
         if (is_null($organisation)) {
             $organisation = $this->getOrganisationService()->findOrganisationByNameCountry(trim($formData['organisation']), $this->getGeneralService()->findEntityById('Country', $formData['country']));
         }
         /**
          * If the organisation is still not found, create it
          */
         if (is_null($organisation)) {
             $organisation = new Organisation();
             $organisation->setOrganisation($formData['organisation']);
             $organisation->setCountry($this->getGeneralService()->findEntityById('Country', $formData['country']));
             /**
              * @var $organisationType Type
              */
             $organisationType = $this->getOrganisationService()->getEntityManager()->getReference('Organisation\\Entity\\Type', 0);
             $organisation->setType($organisationType);
         }
         /**
          *
          * Update the affiliationFinancial
          */
         $affiliationFinancial = $this->getAffiliationService()->getAffiliation()->getFinancial();
         if (is_null($affiliationFinancial)) {
             $affiliationFinancial = new Financial();
             $affiliationFinancial->setAffiliation($this->getAffiliationService()->getAffiliation());
         }
         $affiliationFinancial->setContact($this->getContactService()->setContactId($formData['contact'])->getContact());
         $affiliationFinancial->setOrganisation($organisation);
         $affiliationFinancial->setBranch(trim(substr($formData['organisation'], strlen($organisation->getOrganisation()))));
         $this->getAffiliationService()->updateEntity($affiliationFinancial);
         if (!is_null($affiliationService->getAffiliation()->getFinancial())) {
             $organisationFinancial = $affiliationService->getAffiliation()->getFinancial()->getOrganisation()->getFinancial();
         } else {
             $organisationFinancial = $affiliationService->getAffiliation()->getOrganisation()->getFinancial();
         }
         if (is_null($organisationFinancial)) {
             $organisationFinancial = new \Organisation\Entity\Financial();
         }
         $organisationFinancial->setOrganisation($organisation);
         /**
          * The presence of a VAT number triggers the creation of a financial organisation
          */
         if (!empty($formData['vat'])) {
             $organisationFinancial->setVat($formData['vat']);
             //Do an in-situ vat check
             $vies = new Vies();
             try {
                 $result = $vies->validateVat($organisationFinancial->getOrganisation()->getCountry()->getCd(), trim(str_replace($organisationFinancial->getOrganisation()->getCountry()->getCd(), '', $formData['vat'])));
                 if ($result->isValid()) {
                     $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-vat-number-is-valid"), $affiliationService->getAffiliation()));
                     //Update the financial
                     $organisationFinancial->setVatStatus(\Organisation\Entity\Financial::VAT_STATUS_VALID);
                     $organisationFinancial->setDateVat(new \DateTime());
                 } else {
                     //Update the financial
                     $organisationFinancial->setVatStatus(\Organisation\Entity\Financial::VAT_STATUS_INVALID);
                     $organisationFinancial->setDateVat(new \DateTime());
                     $this->flashMessenger()->setNamespace('error')->addMessage(sprintf($this->translate("txt-vat-number-is-invalid"), $affiliationService->getAffiliation()));
                 }
             } catch (\Exception $e) {
                 $this->flashMessenger()->setNamespace('danger')->addMessage(sprintf($this->translate("txt-vat-information-could-not-be-verified"), $affiliationService->getAffiliation()));
             }
         } else {
             $organisationFinancial->setVat(null);
         }
         $organisationFinancial->setEmail($formData['preferredDelivery']);
         $organisationFinancial->setOmitContact($formData['omitContact']);
         $this->getOrganisationService()->updateEntity($organisationFinancial);
         /*
          * save the financial address
          */
         $contactService = clone $this->getContactService()->setContact($affiliationFinancial->getContact());
         if (!is_null($contactService->getFinancialAddress())) {
             $financialAddress = $contactService->getFinancialAddress()->getAddress();
         } else {
             $financialAddress = new Address();
             $financialAddress->setContact($affiliationService->getAffiliation()->getFinancial()->getContact());
             /**
              * @var $addressType AddressType
              */
             $addressType = $this->getContactService()->getEntityManager()->getReference('Contact\\Entity\\AddressType', AddressType::ADDRESS_TYPE_FINANCIAL);
             $financialAddress->setType($addressType);
         }
         $financialAddress->setAddress($formData['address']);
         $financialAddress->setZipCode($formData['zipCode']);
         $financialAddress->setCity($formData['city']);
         /**
          * @var Country $country
          */
         $country = $this->getContactService()->getEntityManager()->getReference('General\\Entity\\Country', $formData['country']);
         $financialAddress->setCountry($country);
         $this->getContactService()->updateEntity($financialAddress);
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-affiliation-%s-has-successfully-been-updated"), $affiliationService->getAffiliation()));
         return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $affiliationService->getAffiliation()->getId()], ['fragment' => 'invoicing']);
     }
     return new ViewModel(['affiliationService' => $affiliationService, 'projectService' => $projectService, 'form' => $form]);
 }
コード例 #2
0
 /**
  * @return \Zend\Http\Response|ViewModel
  * @throws \Doctrine\ORM\ORMException
  */
 public function financialAction()
 {
     $affiliationService = $this->getAffiliationService()->setAffiliationId($this->getEvent()->getRouteMatch()->getParam('id'));
     if ($affiliationService->isEmpty()) {
         return $this->notFoundAction();
     }
     $projectService = $this->getProjectService()->setProject($affiliationService->getAffiliation()->getProject());
     if ($projectService->isEmpty()) {
         return $this->notFoundAction();
     }
     $organisationService = $this->getOrganisationService()->setOrganisation($affiliationService->getAffiliation()->getOrganisation());
     if ($organisationService->isEmpty()) {
         return $this->notFoundAction();
     }
     $formData = [];
     $branch = null;
     $financialAddress = null;
     if (!is_null($affiliationService->getAffiliation()->getFinancial())) {
         $branch = $affiliationService->getAffiliation()->getFinancial()->getBranch();
         $formData['attention'] = $affiliationService->getAffiliation()->getFinancial()->getContact()->getDisplayName();
         $contactService = clone $this->getContactService()->setContact($affiliationService->getAffiliation()->getFinancial()->getContact());
         $formData['contact'] = $affiliationService->getAffiliation()->getFinancial()->getContact()->getId();
         if (!is_null($financialAddress = $contactService->getFinancialAddress())) {
             $financialAddress = $contactService->getFinancialAddress()->getAddress();
             $formData['address'] = $financialAddress->getAddress();
             $formData['zipCode'] = $financialAddress->getZipCode();
             $formData['city'] = $financialAddress->getCity();
             $formData['country'] = $financialAddress->getCountry()->getId();
         }
     }
     $formData['organisation'] = $organisationService->parseOrganisationWithBranch($branch);
     $formData['registeredCountry'] = $organisationService->getOrganisation()->getCountry()->getId();
     if (!is_null($organisationFinancial = $affiliationService->getAffiliation()->getOrganisation()->getFinancial())) {
         $formData['preferredDelivery'] = $organisationFinancial->getEmail();
         $formData['vat'] = $organisationFinancial->getVat();
         $formData['omitContact'] = $organisationFinancial->getOmitContact();
     }
     $form = new FinancialForm($affiliationService, $this->getGeneralService());
     $form->setData($formData);
     if ($this->getRequest()->isPost() && $form->setData($_POST) && $form->isValid()) {
         $formData = $form->getData();
         /**
          * This form is a aggregation of multiple form elements, so we treat it step by step
          */
         /**
          * If the organisation or country has changed or is not set, find the new
          */
         if ($formData['organisation'] !== $organisationService->parseOrganisationWithBranch($branch) || is_null($financialAddress) || intval($formData['country']) !== $financialAddress->getCountry()->getId() || intval($formData['contact']) !== $financialAddress->getContact()->getId()) {
             /**
              * The organisation, or country has changed, so try to find this country in the database
              */
             $organisation = $this->getOrganisationService()->findOrganisationByNameCountry(trim($formData['organisation']), $this->getGeneralService()->findEntityById('Country', $formData['country']));
             /**
              * If the organisation is not found, create it
              */
             if (is_null($organisation)) {
                 $organisation = new Organisation();
                 $organisation->setOrganisation($formData['organisation']);
                 $organisation->setCountry($this->getGeneralService()->findEntityById('Country', $formData['country']));
                 /**
                  * @var $organisationType OrganisationType
                  */
                 $organisationType = $this->getOrganisationService()->getEntityManager()->getReference('Organisation\\Entity\\Type', 0);
                 $organisation->setType($organisationType);
             }
             $affiliationFinancial = $this->getAffiliationService()->getAffiliation()->getFinancial();
             if (is_null($affiliationFinancial)) {
                 $affiliationFinancial = new Financial();
                 $affiliationFinancial->setAffiliation($this->getAffiliationService()->getAffiliation());
             }
             $affiliationFinancial->setContact($this->getContactService()->setContactId($formData['contact'])->getContact());
             $affiliationFinancial->setOrganisation($organisation);
             $affiliationFinancial->setBranch(trim(substr($formData['organisation'], strlen($organisation->getOrganisation()))));
             $this->getAffiliationService()->updateEntity($affiliationFinancial);
         } else {
             $affiliationFinancial = $this->getAffiliationService()->getAffiliation()->getFinancial();
         }
         /**
          * The presence of a VAT number triggers the creation of a financial organisation
          */
         if (!empty($formData['vat'])) {
             if (is_null($affiliationService->getAffiliation()->getOrganisation()->getFinancial())) {
                 $organisationFinancial = new \Organisation\Entity\Financial();
             } else {
                 $organisationFinancial = $affiliationService->getAffiliation()->getOrganisation()->getFinancial();
             }
             $organisationFinancial->setOrganisation($affiliationService->getAffiliation()->getOrganisation());
             $organisationFinancial->setVat($formData['vat']);
             $organisationFinancial->setEmail($formData['preferredDelivery']);
             $organisationFinancial->setOmitContact($formData['omitContact']);
             $this->getOrganisationService()->updateEntity($organisationFinancial);
         }
         /**
          * save the financial address
          */
         $contactService = clone $this->getContactService()->setContact($affiliationFinancial->getContact());
         if (!is_null($contactService->getFinancialAddress())) {
             $financialAddress = $contactService->getFinancialAddress()->getAddress();
         } else {
             $financialAddress = new Address();
             $financialAddress->setContact($affiliationService->getAffiliation()->getFinancial()->getContact());
             /**
              * @var $addressType AddressType
              */
             $addressType = $this->getContactService()->getEntityManager()->getReference('Contact\\Entity\\AddressType', AddressType::ADDRESS_TYPE_FINANCIAL);
             $financialAddress->setType($addressType);
         }
         $financialAddress->setAddress($formData['address']);
         $financialAddress->setZipCode($formData['zipCode']);
         $financialAddress->setCity($formData['city']);
         /**
          * @var $country Country
          */
         $country = $this->getContactService()->getEntityManager()->getReference('General\\Entity\\Country', $formData['country']);
         $financialAddress->setCountry($country);
         $this->getContactService()->updateEntity($financialAddress);
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-affiliation-%s-has-successfully-been-updated"), $affiliationService->getAffiliation()));
         return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $affiliationService->getAffiliation()->getId()]);
     }
     return new ViewModel(['affiliationService' => $affiliationService, 'projectService' => $projectService, 'form' => $form]);
 }
コード例 #3
0
 /**
  * Edit a affiliation.
  *
  * @return ViewModel
  */
 public function editAction()
 {
     $affiliationService = $this->getAffiliationService()->setAffiliationId($this->params('id'));
     if ($affiliationService->isEmpty()) {
         return $this->notFoundAction();
     }
     $projectService = $this->getProjectService()->setProject($affiliationService->getAffiliation()->getProject());
     if ($projectService->isEmpty()) {
         return $this->notFoundAction();
     }
     $formData = [];
     $formData['affiliation'] = sprintf("%s|%s", $affiliationService->getAffiliation()->getOrganisation()->getId(), $affiliationService->getAffiliation()->getBranch());
     $formData['contact'] = $affiliationService->getAffiliation()->getContact()->getId();
     $formData['branch'] = $affiliationService->getAffiliation()->getBranch();
     $formData['valueChain'] = $affiliationService->getAffiliation()->getValueChain();
     $formData['marketAccess'] = $affiliationService->getAffiliation()->getMarketAccess();
     $formData['mainContribution'] = $affiliationService->getAffiliation()->getMainContribution();
     if (!is_null($affiliationService->getAffiliation()->getDateEnd())) {
         $formData['dateEnd'] = $affiliationService->getAffiliation()->getDateEnd()->format('Y-m-d');
     }
     if (!is_null($affiliationService->getAffiliation()->getDateSelfFunded()) || $affiliationService->getAffiliation()->getSelfFunded() == Affiliation::SELF_FUNDED) {
         if (is_null($affiliationService->getAffiliation()->getDateSelfFunded())) {
             $formData['dateSelfFunded'] = date('Y-m-d');
         } else {
             $formData['dateSelfFunded'] = $affiliationService->getAffiliation()->getDateSelfFunded()->format('Y-m-d');
         }
     }
     /**
      * Only fill the formData of the finanicalOrganisation when this is known
      */
     if (!is_null($financial = $affiliationService->getAffiliation()->getFinancial())) {
         $formData['financialOrganisation'] = $financial->getOrganisation()->getId();
         $formData['financialBranch'] = $financial->getBranch();
         $formData['financialContact'] = $financial->getContact()->getId();
         $formData['emailCC'] = $financial->getEmailCC();
     }
     $form = new AdminAffiliation($affiliationService, $this->getOrganisationService());
     $form->setData($formData);
     $form->get('contact')->setDisableInArrayValidator(true);
     $form->get('organisation')->setDisableInArrayValidator(true);
     $form->get('financialOrganisation')->setDisableInArrayValidator(true);
     $form->get('financialContact')->setDisableInArrayValidator(true);
     if ($this->getRequest()->isPost() && $form->setData($_POST) && $form->isValid()) {
         $formData = $form->getData();
         $affiliation = $affiliationService->getAffiliation();
         /**
          * Update the affiliation based on the form information
          */
         $affiliation->setContact($this->getContactService()->setContactId($formData['contact'])->getContact());
         $affiliation->setOrganisation($this->getOrganisationService()->setOrganisationId($formData['organisation'])->getOrganisation());
         $affiliation->setBranch($formData['branch']);
         if (empty($formData['dateSelfFunded'])) {
             $affiliation->setSelfFunded(Affiliation::NOT_SELF_FUNDED);
             $affiliation->setDateSelfFunded(null);
         } else {
             $affiliation->setSelfFunded(Affiliation::SELF_FUNDED);
             $affiliation->setDateSelfFunded(\DateTime::createFromFormat('Y-m-d', $formData['dateSelfFunded']));
         }
         if (empty($formData['dateEnd'])) {
             $affiliation->setDateEnd(null);
         } else {
             $affiliation->setDateEnd(\DateTime::createFromFormat('Y-m-d', $formData['dateEnd']));
         }
         $affiliation->setValueChain($formData['valueChain']);
         $affiliation->setMainContribution($formData['mainContribution']);
         $affiliation->setMarketAccess($formData['marketAccess']);
         $this->getAffiliationService()->updateEntity($affiliation);
         //Only update the financial when an financial organisation is chosen
         if (!empty($formData['financialOrganisation'])) {
             if (is_null($financial = $affiliation->getFinancial())) {
                 $financial = new Financial();
                 $financial->setAffiliation($affiliation);
             }
             $financial->setOrganisation($this->getOrganisationService()->setOrganisationId($formData['financialOrganisation'])->getOrganisation());
             $financial->setContact($this->getContactService()->setContactId($formData['financialContact'])->getContact());
             $financial->setBranch($formData['financialBranch']);
             if (!empty($formData['emailCC'])) {
                 $financial->setEmailCC($formData['emailCC']);
             }
             $this->getAffiliationService()->updateEntity($financial);
         }
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-affiliation-%s-has-successfully-been-updated"), $affiliationService->getAffiliation()));
         return $this->redirect()->toRoute('zfcadmin/affiliation/view', ['id' => $affiliationService->getAffiliation()->getId()]);
     }
     return new ViewModel(['affiliationService' => $affiliationService, 'projectService' => $projectService, 'form' => $form]);
 }
コード例 #4
0
ファイル: InviteService.php プロジェクト: debranova/project
 /**
  * @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;
 }
コード例 #5
0
 /**
  * Edit a affiliation
  *
  * @return ViewModel
  */
 public function editAction()
 {
     $affiliationService = $this->getAffiliationService()->setAffiliationId($this->getEvent()->getRouteMatch()->getParam('id'));
     $projectService = $this->getProjectService()->setProject($affiliationService->getAffiliation()->getProject());
     $formData = [];
     $formData['affiliation'] = sprintf("%s|%s", $affiliationService->getAffiliation()->getOrganisation()->getId(), $affiliationService->getAffiliation()->getBranch());
     $formData['technical'] = $affiliationService->getAffiliation()->getContact()->getId();
     $formData['valueChain'] = $affiliationService->getAffiliation()->getValueChain();
     /**
      * Check if the organisation has a financial contact
      */
     if (!is_null($affiliationService->getAffiliation()->getOrganisation()->getFinancial())) {
         $formData['preferredDelivery'] = $affiliationService->getAffiliation()->getOrganisation()->getFinancial()->getEmail();
     }
     /**
      * Check if the organisation has a financial contact
      */
     if (!is_null($affiliationService->getAffiliation()->getFinancial())) {
         $formData['financial'] = $affiliationService->getAffiliation()->getFinancial()->getContact()->getId();
     }
     $form = new Affiliation($affiliationService);
     $form->setData($formData);
     if ($this->getRequest()->isPost() && $form->setData($_POST) && $form->isValid()) {
         $formData = $form->getData();
         $affiliation = $affiliationService->getAffiliation();
         /**
          * When the deactivate button is pressed, handle this in the service layer
          */
         if (!is_null($formData['deactivate'])) {
             $this->getAffiliationService()->deactivateAffiliation($affiliation);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-affiliation-%s-has-successfully-been-deactivated"), $affiliationService->getAffiliation()));
             return $this->redirect()->toRoute('community/project/project/partners', ['docRef' => $projectService->getProject()->getDocRef()]);
         }
         /**
          * When the deactivate button is pressed, handle this in the service layer
          */
         if (!is_null($formData['reactivate'])) {
             $this->getAffiliationService()->reactivateAffiliation($affiliation);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-affiliation-%s-has-successfully-been-reactivated"), $affiliationService->getAffiliation()));
             return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $affiliationService->getAffiliation()->getId()]);
         }
         /**
          * Parse the organisation and branch
          */
         list($organisationId, $branch) = explode('|', $formData['affiliation']);
         $organisation = $this->getOrganisationService()->setOrganisationId($organisationId)->getOrganisation();
         $affiliation->setOrganisation($organisation);
         $affiliation->setContact($this->getContactService()->setContactId($formData['technical'])->getContact());
         $affiliation->setBranch($branch);
         $this->getAffiliationService()->updateEntity($affiliation);
         $affiliation->setValueChain($formData['valueChain']);
         /**
          * Handle the financial organisation
          */
         if (is_null($financial = $affiliation->getFinancial())) {
             $financial = new Entity\Financial();
         }
         $financial->setOrganisation($organisation);
         $financial->setAffiliation($affiliation);
         $financial->setBranch($branch);
         $financial->setContact($this->getContactService()->setContactId($formData['financial'])->getContact());
         $this->getAffiliationService()->updateEntity($financial);
         /**
          * Handle the preferred delivery for the organisation (OrganisationFinancial)
          */
         if (is_null($organisationFinancial = $affiliation->getOrganisation()->getFinancial())) {
             $organisationFinancial = new \Organisation\Entity\Financial();
             $organisationFinancial->setOrganisation($affiliation->getOrganisation());
         }
         $organisationFinancial->setEmail((bool) $formData['preferredDelivery']);
         $this->getOrganisationService()->updateEntity($organisationFinancial);
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-affiliation-%s-has-successfully-been-updated"), $affiliationService->getAffiliation()));
         return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $affiliationService->getAffiliation()->getId()]);
     }
     return new ViewModel(['affiliationService' => $affiliationService, 'projectService' => $projectService, 'form' => $form]);
 }