Exemple #1
0
 /**
  * Upload a DOA for a program (based on the affiliation, to be sure that the organisation is
  * active in at least a project in the database)
  *
  * @return ViewModel
  */
 public function uploadAction()
 {
     $organisationService = $this->getOrganisationService()->setOrganisationId($this->getEvent()->getRouteMatch()->getParam('organisation-id'));
     $program = $this->getProgramService()->findEntityById('Program', $this->getEvent()->getRouteMatch()->getParam('program-id'));
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new UploadDoa();
     $form->setData($data);
     if ($this->getRequest()->isPost()) {
         if (isset($data['cancel'])) {
             return $this->redirect()->toRoute('community');
         }
         if ($form->isValid()) {
             $fileData = $this->params()->fromFiles();
             //Create a article object element
             $doaObject = new Entity\DoaObject();
             $doaObject->setObject(file_get_contents($fileData['file']['tmp_name']));
             $fileSizeValidator = new FilesSize(PHP_INT_MAX);
             $fileSizeValidator->isValid($fileData['file']);
             $doa = new Entity\Doa();
             $doa->setSize($fileSizeValidator->size);
             $doa->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type']));
             $doa->setContact($this->zfcUserAuthentication()->getIdentity());
             $doa->setOrganisation($organisationService->getOrganisation());
             $doa->setProgram($program);
             $doaObject->setDoa($doa);
             $this->getProgramService()->newEntity($doaObject);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-doa-for-organisation-%s-in-program-%s-has-been-uploaded"), $organisationService->getOrganisation(), $program));
             return $this->redirect()->toRoute('community/program/doa/view', ['id' => $doaObject->getDoa()->getId()]);
         }
     }
     return new ViewModel(['organisationService' => $organisationService, 'program' => $program, 'form' => $form]);
 }