/**
  * @return ViewModel
  */
 public function editAction()
 {
     $versionDocument = $this->getProjectService()->findEntityById('Version\\Document', $this->getEvent()->getRouteMatch()->getParam('id'));
     if (is_null($versionDocument)) {
         return $this->notFoundAction();
     }
     $projectService = $this->getProjectService()->setProject($versionDocument->getVersion()->getProject());
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new CreateVersionDocument($projectService, $entityManager);
     $form->bind($versionDocument);
     $form->getInputFilter()->get('file')->setRequired(false);
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         $document = $form->getData();
         /*
          * Remove the file if delete is pressed
          */
         if (isset($data['delete'])) {
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-version-document-%s-successfully-removed"), $document->parseFileName()));
             $this->getVersionService()->removeEntity($document);
             return $this->redirect()->toRoute('community/project/version/version', ['id' => $versionDocument->getVersion()->getId()]);
         }
         /*
          * Handle when
          */
         if (!isset($data['cancel'])) {
             $file = $form->get('file')->getValue();
             if (!empty($file['name']) && $file['error'] === 0) {
                 /*
                  * Update the document
                  */
                 $fileSizeValidator = new FilesSize(PHP_INT_MAX);
                 $fileSizeValidator->isValid($file);
                 $document->setSize($fileSizeValidator->size);
                 $document->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($file['type']));
                 /*
                  * Update the object
                  */
                 $documentObject = $document->getObject()->first();
                 if (!$documentObject) {
                     $documentObject = new DocumentObject();
                     $documentObject->setDocument($document);
                 }
                 $documentObject->setObject(file_get_contents($file['tmp_name']));
                 $this->getDocumentService()->updateEntity($documentObject);
             }
             $this->getVersionService()->updateEntity($document);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-version-document-%s-successfully-updated"), $document->parseFileName()));
         }
         return $this->redirect()->toRoute('community/project/version/document/document', ['id' => $document->getId()]);
     }
     return new ViewModel(['versionDocument' => $versionDocument, 'form' => $form]);
 }
Esempio n. 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]);
 }
Esempio n. 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()
 {
     /*
      * @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]);
 }
Esempio n. 5
0
 /**
  * Ensures that the validator returns size infos
  *
  * @return void
  */
 public function testFailureMessage()
 {
     $validator = new File\FilesSize(array('min' => 9999, 'max' => 10000));
     $this->assertFalse($validator->isValid(array(__DIR__ . '/_files/testsize.mo', __DIR__ . '/_files/testsize.mo', __DIR__ . '/_files/testsize2.mo')));
     $messages = $validator->getMessages();
     $this->assertContains('9.76kB', current($messages));
     $this->assertContains('1.55kB', current($messages));
     $validator = new File\FilesSize(array('min' => 9999, 'max' => 10000, 'useByteString' => false));
     $this->assertFalse($validator->isValid(array(__DIR__ . '/_files/testsize.mo', __DIR__ . '/_files/testsize.mo', __DIR__ . '/_files/testsize2.mo')));
     $messages = $validator->getMessages();
     $this->assertContains('9999', current($messages));
     $this->assertContains('1588', current($messages));
 }
 /**
  * @return ViewModel
  */
 public function calendarAction()
 {
     $calendarService = $this->getCalendarService()->setCalendarId($this->params('id'));
     if ($calendarService->isEmpty()) {
         return $this->notFoundAction();
     }
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $form = new CreateCalendarDocument($this->getEntityManager());
     $form->bind(new Document());
     //Add the missing form fields
     $data['calendar'] = $calendarService->getCalendar()->getId();
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         /** @var Document $document */
         $document = $form->getData();
         $document->setCalendar($calendarService->getCalendar());
         $document->setContact($this->zfcUserAuthentication()->getIdentity());
         /*
          * Add the file
          */
         $file = $data['file'];
         $fileSizeValidator = new FilesSize(PHP_INT_MAX);
         $fileSizeValidator->isValid($file);
         $document->setSize($fileSizeValidator->size);
         $document->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($file['type']));
         /** If no name is given, take the name of the file */
         if (empty($data['document'])) {
             $document->setDocument($file['name']);
         }
         $documentObject = new DocumentObject();
         $documentObject->setDocument($document);
         $documentObject->setObject(file_get_contents($file['tmp_name']));
         $this->getCalendarService()->updateEntity($documentObject);
         $this->flashMessenger()->addInfoMessage(sprintf($this->translate("txt-calendar-document-%s-for-calendar-%s-has-successfully-been-uploaded"), $document->getDocument(), $calendarService->getCalendar()->getCalendar()));
         /*
          * Document uploaded
          */
         return $this->redirect()->toRoute('community/calendar/calendar', ['id' => $calendarService->getCalendar()->getId()]);
     }
     /*
      * Add the resource on the fly because it is not triggered via the link Generator
      */
     $this->getCalendarService()->addResource($calendarService->getCalendar(), CalendarAssertion::class);
     if ($calendarService->getCalendar()->getProjectCalendar()) {
         $results = $this->getProjectService()->findResultsByProjectAndContact($calendarService->getCalendar()->getProjectCalendar()->getProject(), $this->zfcUserAuthentication()->getIdentity());
     } else {
         $results = null;
     }
     return new ViewModel(['calendarService' => $calendarService, 'workpackageService' => $this->getWorkpackageService(), 'form' => $form, 'results' => $results]);
 }
 /**
  * @return ViewModel
  */
 public function editAction()
 {
     /** @var Document $document */
     $document = $this->getCalendarService()->findEntityById('document', $this->params('id'));
     if (is_null($document)) {
         return $this->notFoundAction();
     }
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new CreateCalendarDocument($this->getEntityManager());
     $form->bind($document);
     $form->getInputFilter()->get('file')->setRequired(false);
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         /*
          * @var Document
          */
         $document = $form->getData();
         /*
          * Remove the file if delete is pressed
          */
         if (isset($data['delete'])) {
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-calendar-document-%s-successfully-removed"), $document->parseFileName()));
             $this->getCalendarService()->removeEntity($document);
             return $this->redirect()->toRoute('community/calendar/calendar', ['id' => $document->getCalendar()->getId()], ['fragment' => 'documents']);
         }
         /*
          * Handle when
          */
         if (!isset($data['cancel'])) {
             $file = $form->get('file')->getValue();
             if (!empty($file['name']) && $file['error'] === 0) {
                 /*
                  * Update the document
                  */
                 $fileSizeValidator = new FilesSize(PHP_INT_MAX);
                 $fileSizeValidator->isValid($file);
                 $document->setSize($fileSizeValidator->size);
                 $document->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($file['type']));
                 /*
                  * Update the object
                  */
                 $documentObject = $document->getObject()->first();
                 $documentObject->setObject(file_get_contents($file['tmp_name']));
                 $this->getCalendarService()->updateEntity($documentObject);
             }
             $this->getCalendarService()->updateEntity($document);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-calendar-document-%s-successfully-updated"), $document->parseFileName()));
         }
         return $this->redirect()->toRoute('community/calendar/document/document', ['id' => $document->getId()]);
     }
     return new ViewModel(['document' => $document, 'form' => $form]);
 }
 /**
  * @return ViewModel
  */
 public function calendarAction()
 {
     $calendarService = $this->getCalendarService()->setCalendarId($this->getEvent()->getRouteMatch()->getParam('id'));
     if (is_null($calendarService->getCalendar()->getId())) {
         return $this->notFoundAction();
     }
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $form = new CreateCalendarDocument($entityManager);
     $form->bind(new Document());
     //Add the missing form fields
     $data['calendar'] = $calendarService->getCalendar()->getId();
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         $document = $form->getData();
         $document->setCalendar($calendarService->getCalendar());
         $document->setContact($this->zfcUserAuthentication()->getIdentity());
         /**
          * Add the file
          */
         $file = $data['file'];
         $fileSizeValidator = new FilesSize(PHP_INT_MAX);
         $fileSizeValidator->isValid($file);
         $document->setSize($fileSizeValidator->size);
         $document->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($file['type']));
         $documentObject = new DocumentObject();
         $documentObject->setDocument($document);
         $documentObject->setObject(file_get_contents($file['tmp_name']));
         $this->getCalendarService()->updateEntity($documentObject);
         $this->flashMessenger()->addInfoMessage(sprintf($this->translate("txt-calendar-document-%s-for-calendar-%s-has-successfully-been-uploaded"), $document->getDocument(), $calendarService->getCalendar()->getCalendar()));
         /*
          * Document uploaded
          */
         return $this->redirect()->toRoute('zfcadmin/calendar-manager/calendar', ['id' => $calendarService->getCalendar()->getId()]);
     }
     return new ViewModel(['calendarService' => $calendarService, 'form' => $form]);
 }
 /**
  * Creating a new ambassador document.
  *
  * @return ViewModel
  */
 public function newAction()
 {
     $ambassador = $this->getAmbassadorService()->findAmbassadorByContact($this->zfcUserAuthentication()->getIdentity());
     //depends on whether the request was made via JSON
     if (is_null($ambassador)) {
         return $this->notFoundAction();
     }
     $document = new Document();
     $document->setAmbassador($ambassador);
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new CreateAmbassadorDocument($entityManager);
     $form->bind($document);
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         /*
          * Return when cancel is pressed
          */
         $document = $form->getData();
         $file = $form->get('file')->getValue();
         if (!empty($file['name']) && $file['error'] === 0) {
             /*
              * Update the document
              */
             $fileSizeValidator = new FilesSize(PHP_INT_MAX);
             $fileSizeValidator->isValid($file);
             $document->setSize($fileSizeValidator->size);
             $document->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($file['type']));
             $document = $this->getAmbassadorService()->newEntity($document);
             /*
              * Update the object
              */
             $documentObject = new Document\Object();
             $documentObject->setDocument($document);
             $documentObject->setObject(file_get_contents($file['tmp_name']));
             $this->getAmbassadorService()->newEntity($documentObject);
         }
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_('txt-ambassador-document-item-%s-has-been-created-successfully'), $document->getDocument()));
         $this->getAmbassadorService()->sendUpdateEmail();
         return $this->redirect()->toRoute('community/ambassador/ambassador');
     }
     return new ViewModel(['form' => $form]);
 }
Esempio n. 10
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]);
 }
Esempio n. 11
0
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     $validator = new File\FilesSize(0);
     $this->assertFalse($validator->isValid(''));
     $this->assertArrayHasKey(File\FilesSize::NOT_READABLE, $validator->getMessages());
     $filesArray = array('name' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'type' => '');
     $this->assertFalse($validator->isValid($filesArray));
     $this->assertArrayHasKey(File\FilesSize::NOT_READABLE, $validator->getMessages());
 }
Esempio n. 12
0
 /**
  * Create a new project.
  *
  * @return ViewModel
  */
 public function createAction()
 {
     $projectService = $this->getProjectService()->setProjectId($this->getEvent()->getRouteMatch()->getParam('project'));
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $today = new \DateTime();
     $currentPeriod = $this->getReportService()->getPeriod($today);
     $data['period'] = sprintf("%s-%s", $today->format("Y"), $currentPeriod->semester);
     $form = new CreateReport($projectService);
     $form->setInputFilter(new FilterCreateReport());
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         $formData = $form->getData();
         /*
          * Create the period
          */
         $period = $this->getReportService()->getDateFromPeriod($formData['period']);
         /*
          * Check first if we have already a report for this project and period
          */
         $report = $this->getReportService()->findReportByProjectAndPeriod($projectService->getProject(), $period);
         /*
          * Create a new report if no report is found
          */
         if (is_null($report)) {
             $report = new Report();
             $report->setDatePeriod($period);
             $report->setContact($this->zfcUserAuthentication()->getIdentity());
             $report->setProject($projectService->getProject());
         }
         /*
          * Create the item
          * when no name is given, take the name of the uploaded file
          */
         $item = new Item();
         if (empty($formData['item'])) {
             $item->setItem($formData['file']['name']);
         } else {
             $item->setItem($formData['item']);
         }
         $item->setReport($report);
         $item->setContact($this->zfcUserAuthentication()->getIdentity());
         $fileSizeValidator = new FilesSize(PHP_INT_MAX);
         $fileSizeValidator->isValid($formData['file']);
         $item->setSize($fileSizeValidator->size);
         $item->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($formData['file']['type']));
         /*
          * Save the object
          */
         $reportItemObject = new ItemObject();
         $reportItemObject->setObject(file_get_contents($formData['file']['tmp_name']));
         $reportItemObject->setItem($item);
         $this->getReportService()->newEntity($reportItemObject);
         /*
          * Send the email tot he consortium
          */
         $email = $this->getEmailService()->create();
         $this->getEmailService()->setTemplate("/project/report-item/submit:mail");
         $email->addSelection($this->getContactService()->findEntityById('selection', 219), $this->getContactService());
         $email->setDocumentName($item);
         $email->setProject($report->getProject());
         $email->setSubmitter($report->getContact());
         $email->setContentType($item->getContentType()->getDescription());
         $this->getEmailService()->send($email);
         $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_("txt-report-%s-for-project-%s-has-successfully-been-created"), $report->parseName(), $projectService->parseFullName()));
         return $this->redirect()->toRoute('community/project/report/report', ['id' => $reportItemObject->getItem()->getReport()->getId()]);
     }
     return new ViewModel(['projectService' => $projectService, 'form' => $form]);
 }
Esempio n. 13
0
 /**
  * @return ViewModel
  */
 public function editAction()
 {
     $documentService = $this->getDocumentService()->setDocumentId($this->getEvent()->getRouteMatch()->getParam('id'));
     if ($documentService->isEmpty()) {
         return $this->notFoundAction();
     }
     $ambassadorService = $this->getAmbassadorService()->setAmbassador($documentService->getDocument()->getAmbassador());
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new CreateDocument($ambassadorService, $entityManager);
     $form->bind($documentService->getDocument());
     $form->getInputFilter()->get('file')->setRequired(false);
     $form->getInputFilter()->get('contact')->setRequired(false);
     $form->getInputFilter()->get('project')->setRequired(false);
     $form->setData($data);
     if ($this->getRequest()->isPost()) {
         /*
          * Remove the file if delete is pressed
          */
         if (isset($data['cancel'])) {
             $this->flashMessenger()->setNamespace('info')->addMessage(sprintf(_('txt-edit-a-document-%s-in-project-%s-has-been-cancelled'), $documentService->getDocument()->parseFileName(), $ambassadorService->parseFullName()));
             return $this->redirect()->toRoute('community/ambassador/document/document', ['id' => $documentService->getDocument()->getId()]);
         }
         /*
          * Remove the file if delete is pressed
          */
         if (isset($data['delete'])) {
             $document = $documentService->getDocument();
             $this->getAmbassadorService()->removeEntity($document);
             $this->flashMessenger()->setNamespace('info')->addMessage(sprintf(_('txt-ambassador-document-%s-for-ambassador-%s-has-been-removed'), $documentService->getDocument()->parseFileName(), $ambassadorService->parseFullName()));
             return $this->redirect()->toRoute('community/ambassador/ambassador', ['docRef' => $this->getAmbassador()->getAmbassador()->getDocRef()]);
         }
         if ($form->isValid()) {
             $document = $form->getData();
             /*
              * Remove the file if delete is pressed
              */
             if (isset($data['delete'])) {
                 $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_('txt-document-%s-successfully-removed'), $document->parseFileName()));
                 $this->getDocumentService()->removeEntity($document);
                 return $this->redirect()->toRoute('community/ambassador/ambassador/management', ['docRef' => $document->getProject()->getDocRef()]);
             }
             /*
              * Handle when
              */
             $file = $form->get('file')->getValue();
             if (!empty($file['name']) && $file['error'] === 0) {
                 /*
                  * Update the document
                  */
                 $fileSizeValidator = new FilesSize(PHP_INT_MAX);
                 $fileSizeValidator->isValid($file);
                 $document->setSize($fileSizeValidator->size);
                 $document->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($file['type']));
                 /*
                  * Update the object
                  */
                 $documentObject = $document->getObject()->first();
                 if (!$documentObject) {
                     $documentObject = new Object();
                     $documentObject->setDocument($document);
                 }
                 $documentObject->setObject(file_get_contents($file['tmp_name']));
                 $this->getDocumentService()->updateEntity($documentObject);
             }
             $this->getDocumentService()->updateEntity($document);
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf(_('txt-document-%s-successfully-updated'), $document->parseFileName()));
             return $this->redirect()->toRoute('community/ambassador/document/document', ['id' => $document->getId()]);
         }
     }
     return new ViewModel(['documentService' => $documentService, 'form' => $form]);
 }
Esempio n. 14
0
 /**
  * @param Idea $idea
  * @param      $fileData
  * @param null $alternativeName
  */
 public function addFileToIdea(Idea $idea, $fileData, $alternativeName = null)
 {
     //Parse first the type of file to see in which table it should be stored
     $mimeType = new MimeType();
     $mimeType->isValid($fileData);
     /*
      * Use the fileSize validator to validate the size
      */
     $fileSize = new FilesSize(PHP_INT_MAX);
     $fileSize->isValid($fileData);
     $contentType = $this->getGeneralService()->findContentTypeByContentTypeName($fileData['type']);
     switch ($mimeType->type) {
         case 'application/pdf':
             //All treated as document
         //All treated as document
         case 'application/msword':
             //All treated as document
         //All treated as document
         case 'application/vnd.ms-excel':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
             $ideaDocument = new Document();
             $ideaDocument->setIdea($idea);
             $ideaDocument->setFilename($fileData['name']);
             $ideaDocument->setSize($fileSize->size);
             if (is_null($alternativeName)) {
                 $ideaDocument->setDocument($fileData['name']);
             } else {
                 $ideaDocument->setDocument($alternativeName);
             }
             $ideaDocumentObject = new DocumentObject();
             $ideaDocumentObject->setObject(file_get_contents($fileData['tmp_name']));
             $ideaDocument->setContentType($contentType);
             $ideaDocumentObject->setDocument($ideaDocument);
             $this->newEntity($ideaDocumentObject);
             break;
         case 'image/jpeg':
         case 'image/png':
             $ideaImage = new Image();
             $ideaImage->setIdea($idea);
             if (is_null($alternativeName)) {
                 $ideaImage->setImage($fileData['name']);
             } else {
                 $ideaImage->setImage($alternativeName);
             }
             $ideaImage->setSize($fileSize->size);
             $ideaImage->setContentType($contentType);
             $ideaImageObject = new ImageObject();
             $ideaImageObject->setObject(file_get_contents($fileData['tmp_name']));
             $thumb = new GD($fileData['tmp_name']);
             $thumb->resize(200);
             $ideaImageObject->setThumb($thumb->getImageAsString());
             $ideaImageObject->setImage($ideaImage);
             $this->newEntity($ideaImageObject);
             break;
     }
 }