示例#1
0
 /**
  * Edit a affiliation
  *
  * @return ViewModel
  */
 public function affiliationAction()
 {
     $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();
     }
     $formData = [];
     $formData['affiliation'] = sprintf("%s|%s", $affiliationService->getAffiliation()->getOrganisation()->getId(), $affiliationService->getAffiliation()->getBranch());
     $formData['technical'] = $affiliationService->getAffiliation()->getContact()->getId();
     $formData['valueChain'] = $affiliationService->getAffiliation()->getValueChain();
     $formData['marketAccess'] = $affiliationService->getAffiliation()->getMarketAccess();
     $formData['mainContribution'] = $affiliationService->getAffiliation()->getMainContribution();
     /**
      * Check if the organisation has a financial contact
      */
     if (!is_null($affiliationService->getAffiliation()->getFinancial())) {
         $formData['financial'] = $affiliationService->getAffiliation()->getFinancial()->getContact()->getId();
     }
     $form = new AffiliationForm($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);
             //Update the rationale for public funding
             $this->getProjectService()->updateCountryRationaleByAffiliation($affiliation, ProjectService::AFFILIATION_DEACTIVATE);
             $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);
             //Update the rationale for public funding
             $this->getProjectService()->updateCountryRationaleByAffiliation($affiliation, ProjectService::AFFILIATION_REACTIVATE);
             $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']);
         $affiliation->setMainContribution($formData['mainContribution']);
         $affiliation->setMarketAccess($formData['marketAccess']);
         /**
          * Handle the financial organisation
          */
         if (is_null($financial = $affiliation->getFinancial())) {
             $financial = new Financial();
         }
         $financial->setOrganisation($organisation);
         $financial->setAffiliation($affiliation);
         $financial->setBranch($branch);
         $financial->setContact($this->getContactService()->setContactId($formData['financial'])->getContact());
         $this->getAffiliationService()->updateEntity($financial);
         $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]);
 }
 /**
  * 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]);
 }