Example #1
0
 /**
  * Load the Document
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $document = new Document();
     $document->setContentType($manager->find("General\\Entity\\ContentType", 2));
     $document->setSize(1000);
     $document->setDocument('This is the testdocument for the merge');
     $document->setContact($manager->find("Contact\\Entity\\Contact", 1));
     $document->setProject($manager->find("Project\\Entity\\Project", 1));
     $document->setType($manager->find("Project\\Entity\\Document\\Type", 1));
     $documentObject = new Object();
     $documentObject->setObject(file_get_contents(__DIR__ . '/../../assets/doc/ITEA3_PO_Annex_template_Call1.docx'));
     $documentObject->setDocument($document);
     $manager->persist($documentObject);
     $manager->flush();
 }
Example #2
0
 /**
  * @return ViewModel
  */
 public function editAction()
 {
     $documentService = $this->getDocumentService()->setDocumentId($this->getEvent()->getRouteMatch()->getParam('id'));
     if ($documentService->isEmpty()) {
         return $this->notFoundAction();
     }
     $projectService = $this->getProjectService()->setProject($documentService->getDocument()->getProject());
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new CreateDocument($projectService, $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-project-document-%s-in-project-%s-has-been-cancelled"), $documentService->getDocument()->parseFileName(), $projectService->parseFullName()));
             return $this->redirect()->toRoute('community/project/document/document', ['id' => $documentService->getDocument()->getId()]);
         }
         /*
          * Remove the file if delete is pressed
          */
         if (isset($data['delete'])) {
             $document = $documentService->getDocument();
             $this->getProjectService()->removeEntity($document);
             $this->flashMessenger()->setNamespace('info')->addMessage(sprintf(_("txt-project-document-%s-in-project-%s-has-been-removed"), $documentService->getDocument()->parseFileName(), $projectService->parseFullName()));
             return $this->redirect()->toRoute('community/project/project/management', ['docRef' => $this->getProjectService()->getProject()->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/project/project/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/project/document/document', ['id' => $document->getId()]);
         }
     }
     return new ViewModel(['documentService' => $documentService, 'form' => $form]);
 }