/** * Export a Collecticiel. * * @param Workspace $workspace * @param array $files * @param Dropzone $dropzone * * @return array */ public function export(Workspace $workspace, array &$files, Dropzone $dropzone) { $data = []; $uid = uniqid() . '.txt'; $tmpPath = $this->ch->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . $uid; file_put_contents($tmpPath, $dropzone->getInstruction()); $files[$uid] = $tmpPath; $data['instruction'] = $uid; $data['allow_workspace_resource'] = $dropzone->getAllowWorkspaceResource(); $data['allow_upload'] = $dropzone->getAllowUpload(); $data['allow_url'] = $dropzone->getAllowUrl(); $data['allow_rich_text'] = $dropzone->getAllowRichText(); $data['manual_planning'] = $dropzone->getManualPlanning(); $data['manual_state'] = $dropzone->getManualState(); $startDate = $dropzone->getStartAllowDrop(); if (!empty($startDate)) { $data['start_allow_drop'] = $startDate->format('Y-m-d H:i:s'); } $endDate = $dropzone->getEndAllowDrop(); if (!empty($endDate)) { $data['end_allow_drop'] = $endDate->format('Y-m-d H:i:s'); } return $data; }
/** * Test to detect the incorrect input. * * @param Form $form form to control * @param Dropzone $dropzone dropzone to update * * @return form */ public function handleFormErrors($form, Dropzone $dropzone) { if (!$dropzone->getAllowWorkspaceResource() && !$dropzone->getAllowUpload() && !$dropzone->getAllowUrl() && !$dropzone->getAllowRichText()) { $form->get('allowWorkspaceResource')->addError(new FormError('Choose at least one type of document')); $form->get('allowUpload')->addError(new FormError('Choose at least one type of document')); $form->get('allowUrl')->addError(new FormError('Choose at least one type of document')); $form->get('allowRichText')->addError(new FormError('Choose at least one type of document')); } if (!$dropzone->getManualPlanning()) { if ($dropzone->getStartAllowDrop() === null) { $form->get('startAllowDrop')->addError(new FormError('Choose a date')); } if ($dropzone->getEndAllowDrop() === null) { $form->get('endAllowDrop')->addError(new FormError('Choose a date')); } if ($dropzone->getStartAllowDrop() !== null && $dropzone->getEndAllowDrop() !== null) { if ($dropzone->getStartAllowDrop()->getTimestamp() > $dropzone->getEndAllowDrop()->getTimestamp()) { $form->get('startAllowDrop')->addError(new FormError('Must be before end allow drop')); $form->get('endAllowDrop')->addError(new FormError('Must be after start allow drop')); } } } return $form; }
/** * Handle events when modifying dropzone * Delete useless events (if manualPlanning) & update/create (if datePlanning) * @param Dropzone $dropzone * @return bool */ public function handleEvents(Dropzone $dropzone, User $user) { $agendaManager = $this->container->get('claroline.manager.agenda_manager'); $workspace = $dropzone->getResourceNode()->getWorkspace(); if ($dropzone->getManualPlanning()) { if ($dropzone->getEventDrop() != null) { $event = $dropzone->getEventDrop(); $agendaManager->deleteEvent($event); $dropzone->setEventDrop(null); } if ($dropzone->getEventCorrection() != null) { $event = $dropzone->getEventCorrection(); $agendaManager->deleteEvent($event); $dropzone->setEventCorrection(null); } } elseif ($dropzone->getStartAllowDrop() != NULL && $dropzone->getEndAllowDrop() != NULL) { if ($dropzone->getEventDrop() != null) { // update event $eventDrop = $dropzone->getEventDrop(); $eventDrop->setStart($dropzone->getStartAllowDrop()); $eventDrop->setEnd($dropzone->getEndAllowDrop()); $agendaManager->updateEvent($eventDrop); } else { // create event $eventDrop = $this->createAgendaEventDrop($user, $dropzone); // event creation + link to workspace $agendaManager->addEvent($eventDrop, $workspace); // link btween the event and the dropzone $dropzone->setEventDrop($eventDrop); } } return $dropzone; }
/** * Check if dropzone options are ok in order to autoclose Drops * @param Dropzone $dropzone * @return bool */ private function isDropzoneDropTimeIsUp(Dropzone $dropzone) { $dropDatePassed = false; if ($dropzone->getAutoCloseOpenedDropsWhenTimeIsUp() && $dropzone->getManualPlanning() == false) { $now = new \DateTime(); $dropDatePassed = $now->getTimestamp() > $dropzone->getEndAllowDrop()->getTimeStamp(); } return $dropDatePassed; }