/** * @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->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 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]); }