예제 #1
0
 /**
  * Upload a NDA to the system and store it for the user
  *
  * @param array   $file
  * @param Contact $contact
  * @param Call    $call
  *
  * @return NdaObject
  */
 public function uploadNda(array $file, Contact $contact, Call $call = null)
 {
     $ndaObject = new NdaObject();
     $ndaObject->setObject(file_get_contents($file['tmp_name']));
     $nda = new Nda();
     $nda->setContact($contact);
     if (!is_null($call)) {
         $nda->setCall([$call]);
     }
     $nda->setSize($file['size']);
     $contentType = $this->getGeneralService()->findContentTypeByContentTypeName($file['type']);
     if (is_null($contentType)) {
         $contentType = $this->getGeneralService()->findEntityById('ContentType', 0);
     }
     $nda->setContentType($contentType);
     $ndaObject->setNda($nda);
     $this->newEntity($ndaObject);
     return $ndaObject->getNda();
 }
예제 #2
0
 /**
  * @return \Zend\View\Model\ViewModel
  */
 public function editAction()
 {
     $nda = $this->getCallService()->findEntityById('nda', $this->getEvent()->getRouteMatch()->getParam('id'));
     if (is_null($nda)) {
         return $this->notFoundAction();
     }
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = $this->getFormService()->prepare('nda', $nda, $data);
     $form->get('nda')->get('contact')->setValueOptions([$nda->getContact()->getId() => $nda->getContact()->getFormName()]);
     $form->get('nda')->get('programCall')->setValue($nda->getCall());
     //Get contacts in an organisation
     if ($this->getRequest()->isPost() && $form->isValid()) {
         /**
          * @var $nda Nda
          */
         $nda = $form->getData();
         if (isset($data['cancel'])) {
             return $this->redirect()->toRoute('zfcadmin/nda-manager/nda/view', ['id' => $nda->getId()]);
         }
         if (isset($data['delete'])) {
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-nda-for-contact-%s-has-been-removed"), $nda->getContact()->getDisplayName()));
             $this->getCallService()->removeEntity($nda);
             return $this->redirect()->toRoute('zfcadmin/nda-manager/approval');
         }
         $fileData = $this->params()->fromFiles();
         if ($fileData['nda']['file']['error'] === 0) {
             /**
              * Replace the content of the object
              */
             if (!$nda->getObject()->isEmpty()) {
                 $nda->getObject()->first()->setObject(file_get_contents($fileData['nda']['file']['tmp_name']));
             } else {
                 $ndaObject = new NdaObject();
                 $ndaObject->setObject(file_get_contents($fileData['nda']['file']['tmp_name']));
                 $ndaObject->setNda($nda);
                 $this->getCallService()->newEntity($ndaObject);
             }
             //Create a article object element
             $fileSizeValidator = new FilesSize(PHP_INT_MAX);
             $fileSizeValidator->isValid($fileData['nda']['file']);
             $nda->setSize($fileSizeValidator->size);
             $nda->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['nda']['file']['type']));
         }
         /**
          * The programme call needs to have a dedicated treatment
          */
         if (!empty($data['nda']['programCall'])) {
             $nda->setCall([$this->getCallService()->setCallId($data['nda']['programCall'])->getCall()]);
         } else {
             $nda->setCall([]);
         }
         $this->getCallService()->updateEntity($nda);
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-nda-for-contact-%s-has-been-updated"), $nda->getContact()->getDisplayName()));
         return $this->redirect()->toRoute('zfcadmin/nda-manager/view', ['id' => $nda->getId()]);
     }
     return new ViewModel(['nda' => $nda, 'form' => $form]);
 }
예제 #3
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()
 {
     $nda = $this->getProgramService()->findEntityById('Nda', $this->params('id'));
     if (is_null($nda) || sizeof($nda->getObject()) === 0) {
         return $this->notFoundAction();
     }
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new UploadNda();
     $form->setData($data);
     if ($this->getRequest()->isPost()) {
         if (!isset($data['cancel']) && $form->isValid()) {
             $fileData = $this->params()->fromFiles();
             /*
              * Remove the current entity
              */
             foreach ($nda->getObject() as $object) {
                 $this->getProgramService()->removeEntity($object);
             }
             //Create a article object element
             $ndaObject = new NdaObject();
             $ndaObject->setObject(file_get_contents($fileData['file']['tmp_name']));
             $fileSizeValidator = new FilesSize(PHP_INT_MAX);
             $fileSizeValidator->isValid($fileData['file']);
             $nda->setSize($fileSizeValidator->size);
             $nda->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type']));
             $ndaObject->setNda($nda);
             $this->getProgramService()->newEntity($ndaObject);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-nda-has-been-replaced-successfully")));
             return $this->redirect()->toRoute('program/nda/view', ['id' => $nda->getId()]);
         }
         if (isset($data['cancel'])) {
             $this->flashMessenger()->setNamespace('info')->addMessage(sprintf(_("txt-action-has-been-cancelled")));
             return $this->redirect()->toRoute('program/nda/view', ['id' => $nda->getId()]);
         }
     }
     return new ViewModel(['nda' => $nda, 'form' => $form]);
 }