/** * Action to replace an mis-uploaded DoA. * * @return ViewModel * * @throws \Zend\Form\Exception\InvalidArgumentException * @throws \InvalidArgumentException * @throws \Zend\Mvc\Exception\DomainException * @throws \Zend\Form\Exception\DomainException */ public function replaceAction() { /* * @var Doa */ $doa = $this->getAffiliationService()->findEntityById('Doa', $this->params('id')); $this->getAffiliationService()->setAffiliation($doa->getAffiliation()); if (is_null($doa) || sizeof($doa->getObject()) === 0) { return $this->notFoundAction(); } $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' => $doa->getAffiliation()->getId()], ['fragment' => 'details']); } if ($form->isValid()) { $fileData = $this->params()->fromFiles(); /* * Remove the current entity */ foreach ($doa->getObject() as $object) { $this->getAffiliationService()->removeEntity($object); } //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']); $doa->setSize($fileSizeValidator->size); $doa->setContact($this->zfcUserAuthentication()->getIdentity()); $doa->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type'])); $affiliationDoaObject->setDoa($doa); $this->getAffiliationService()->newEntity($affiliationDoaObject); $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-project-doa-for-organisation-%s-in-project-%s-has-been-replaced"), $doa->getAffiliation()->getOrganisation(), $doa->getAffiliation()->getProject())); return $this->redirect()->toRoute('community/affiliation/affiliation', ['id' => $doa->getAffiliation()->getId()], ['fragment' => 'details']); } } return new ViewModel(['affiliationService' => $this->getAffiliationService(), 'form' => $form]); }
/** * @return \Zend\View\Model\ViewModel */ public function editAction() { $doaService = $this->getDoaService()->setDoaId($this->params('id')); if (is_null($doaService)) { return $this->notFoundAction(); } $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $form = $this->getFormService()->prepare('doa', $doaService->getDoa(), $data); //Get contacts in an organisation $contactService = $this->getContactService(); $contactService->findContactsInAffiliation($doaService->getDoa()->getAffiliation()); $form->get('doa')->get('contact')->setValueOptions($contactService->toFormValueOptions())->setDisableInArrayValidator(true); /** * */ if ($this->getRequest()->isPost()) { if (isset($data['cancel'])) { return $this->redirect()->toRoute('zfcadmin/affiliation/doa/view', ['id' => $this->params('id')]); } if (isset($data['delete'])) { $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-project-doa-for-organisation-%s-in-project-%s-has-been-removed"), $doaService->getDoa()->getAffiliation()->getOrganisation(), $doaService->getDoa()->getAffiliation()->getProject())); $this->getDoaService()->removeEntity($doaService->getDoa()); return $this->redirect()->toRoute('zfcadmin/affiliation/doa/list'); } if ($form->isValid()) { /** @var $doa Doa */ $doa = $form->getData(); $fileData = $this->params()->fromFiles(); if ($fileData['doa']['file']['error'] === 0) { /* * Replace the content of the object */ if (!$doa->getObject()->isEmpty()) { $doa->getObject()->first()->setObject(file_get_contents($fileData['doa']['file']['tmp_name'])); } else { $doaObject = new DoaObject(); $doaObject->setObject(file_get_contents($fileData['doa']['file']['tmp_name'])); $doaObject->setDoa($doa); $this->getDoaService()->newEntity($doaObject); } //Create a article object element $fileSizeValidator = new FilesSize(PHP_INT_MAX); $fileSizeValidator->isValid($fileData['doa']['file']); $doa->setSize($fileSizeValidator->size); $doa->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['doa']['file']['type'])); } $this->getDoaService()->updateEntity($doa); $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-project-doa-for-organisation-%s-in-project-%s-has-been-updated"), $doa->getAffiliation()->getOrganisation(), $doa->getAffiliation()->getProject())); return $this->redirect()->toRoute('zfcadmin/affiliation/doa/view', ['id' => $doa->getId()]); } } return new ViewModel(['doa' => $doaService->getDoa(), 'form' => $form]); }