Пример #1
0
 public function testUploadDoaFormHasCorrectInputFilter()
 {
     $uploadDoaForm = new UploadDoa();
     $inputFilter = $uploadDoaForm->getInputFilterSpecification();
     $this->assertTrue(is_array($inputFilter));
     $this->assertArrayHasKey('file', $inputFilter);
 }
Пример #2
0
 /**
  * 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()
 {
     $doa = $this->getProgramService()->findEntityById('Doa', $this->getEvent()->getRouteMatch()->getParam('id'));
     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('program/doa/view', ['id' => $doa->getId()]);
         }
         if ($form->isValid()) {
             $fileData = $this->params()->fromFiles();
             /**
              * Remove the current entity
              */
             foreach ($doa->getObject() as $object) {
                 $this->getProgramService()->removeEntity($object);
             }
             //Create a article object element
             $programDoaObject = new Entity\DoaObject();
             $programDoaObject->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']));
             $programDoaObject->setDoa($doa);
             $this->getProgramService()->newEntity($programDoaObject);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-doa-for-organisation-%s-in-program-%s-has-been-uploaded"), $doa->getOrganisation(), $doa->getProgram()));
             return $this->redirect()->toRoute('program/doa/view', ['id' => $doa->getId()]);
         }
     }
     return new ViewModel(['doa' => $doa, 'form' => $form]);
 }