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