/** * Upload a DOA 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 UploadDoa(); $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 $affiliationDoaObject = new Entity\DoaObject(); $affiliationDoaObject->setObject(file_get_contents($fileData['file']['tmp_name'])); $fileSizeValidator = new FilesSize(PHP_INT_MAX); $fileSizeValidator->isValid($fileData['file']); $affiliationDoa = new Entity\Doa(); $affiliationDoa->setSize($fileSizeValidator->size); $affiliationDoa->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type'])); $affiliationDoa->setContact($this->zfcUserAuthentication()->getIdentity()); $affiliationDoa->setAffiliation($affiliationService->getAffiliation()); $affiliationDoaObject->setDoa($affiliationDoa); $this->getAffiliationService()->newEntity($affiliationDoaObject); $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-project-doa-for-organisation-%s-in-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]); }