コード例 #1
0
 /**
  * Upload the LOI for a project (based on the affiliation).
  *
  * @return ViewModel
  */
 public function uploadAction()
 {
     $affiliationService = $this->getAffiliationService()->setAffiliationId($this->params('affiliation-id'));
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new UploadLoi();
     $form->setData($data);
     if ($this->getRequest()->isPost()) {
         if (isset($data['cancel'])) {
             return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $affiliationService->getAffiliation()->getId()], ['fragment' => 'details']);
         }
         if ($form->isValid()) {
             $fileData = $this->params()->fromFiles();
             //Create a article object element
             $loiObject = new Entity\LoiObject();
             $loiObject->setObject(file_get_contents($fileData['file']['tmp_name']));
             $fileSizeValidator = new FilesSize(PHP_INT_MAX);
             $fileSizeValidator->isValid($fileData['file']);
             $loi = new Entity\Loi();
             $loi->setSize($fileSizeValidator->size);
             $loi->setDateSigned(new \DateTime());
             $loi->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type']));
             $loi->setContact($this->zfcUserAuthentication()->getIdentity());
             $loi->setAffiliation($affiliationService->getAffiliation());
             $loiObject->setLoi($loi);
             $this->getAffiliationService()->newEntity($loiObject);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-loi-for-organisation-%s-project-%s-has-been-uploaded"), $affiliationService->getAffiliation()->getOrganisation(), $affiliationService->getAffiliation()->getProject()));
             return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $affiliationService->getAffiliation()->getId()], ['fragment' => 'details']);
         }
     }
     return new ViewModel(['affiliationService' => $affiliationService, 'form' => $form]);
 }