/** * Generate first timetable for sessions * * @param boolean $considerTopics * @param integer $iterations * * @validate $iterations NumberRangeValidator(minimum = 1, maximum = 20) */ public function createTimeTableAction($considerTopics, $iterations) { // Generate Config Array // TODO: Extract to options or something else // Room and time slots $config['roomAndTimeData'][0]['timeSlots'] = 2; $config['roomAndTimeData'][0]['rooms'] = 6; $config['roomAndTimeData'][1]['timeSlots'] = 3; $config['roomAndTimeData'][1]['rooms'] = 6; $config['roomAndTimeData'][2]['timeSlots'] = 3; $config['roomAndTimeData'][2]['rooms'] = 6; $config['roomAndTimeData'][3]['timeSlots'] = 1; $config['roomAndTimeData'][3]['rooms'] = 6; // Begin and end of time slots $config['timeSlots'][0]['begin'] = "09:30"; $config['timeSlots'][0]['end'] = "11:00"; $config['timeSlots'][1]['begin'] = "14:00"; $config['timeSlots'][1]['end'] = "15:30"; $config['timeSlots'][2]['begin'] = "16:30"; $config['timeSlots'][2]['end'] = "18:00"; // Dates of the event $config['dates'][] = "01.09.2016"; $config['dates'][] = "02.09.2016"; $config['dates'][] = "03.09.2016"; $config['dates'][] = "04.09.2016"; // TODO: Alle ScheduledSessions umwandeln in AcceptedSessions // Get all sessions $sessions = $this->acceptedSessionRepository->getAllOrderByVoteCount()->toArray(); // Get all rooms $rooms = $this->roomRepository->findAllLimited(6)->toArray(); // Generate timetable with service $success = $this->createTimetableService->generateTimetable($config, $sessions, $rooms, $iterations, $considerTopics); $incompleteSessions = array(); if (!$success) { $incompleteSessions = $this->createTimetableService->getUnassignedSessions(); } // Save changes on sessions foreach ($this->createTimetableService->getAssignedSessions() as $assignedSession) { // TODO: Umwandeln aller zugewiesenen Sessions in ScheduledSessions /** * @var AcceptedSession $assignedSession */ $assignedSession->_setProperty('type', \TYPO3\Sessions\Domain\Model\ScheduledSession::class); $this->anySessionRepository->update($assignedSession); } $this->redirect('index', 'SessionModule', 'sessions', array('incompleteSessions' => $incompleteSessions, 'creationDone' => true)); }
/** * Generate first timetable for sessions * * @param boolean $considerTopics * @param integer $iterations * * @validate $iterations NumberRangeValidator(minimum = 1, maximum = 20) */ public function createTimeTableAction($considerTopics, $iterations) { // Generate Config Array // TODO: Extract to options or something else // Room and time slots $config['roomAndTimeData'][0]['timeSlots'] = 2; $config['roomAndTimeData'][0]['rooms'] = 6; $config['roomAndTimeData'][1]['timeSlots'] = 3; $config['roomAndTimeData'][1]['rooms'] = 6; $config['roomAndTimeData'][2]['timeSlots'] = 3; $config['roomAndTimeData'][2]['rooms'] = 6; $config['roomAndTimeData'][3]['timeSlots'] = 1; $config['roomAndTimeData'][3]['rooms'] = 6; // Begin and end of time slots $config['timeSlots'][0]['begin'] = "09:30"; $config['timeSlots'][0]['end'] = "11:00"; $config['timeSlots'][1]['begin'] = "14:00"; $config['timeSlots'][1]['end'] = "15:30"; $config['timeSlots'][2]['begin'] = "16:30"; $config['timeSlots'][2]['end'] = "18:00"; // Dates of the event $config['dates'][] = "01.09.2016"; $config['dates'][] = "02.09.2016"; $config['dates'][] = "03.09.2016"; $config['dates'][] = "04.09.2016"; // TODO: Alle ScheduledSessions umwandeln in AcceptedSessions // Get all sessions $sessions = $this->acceptedSessionRepository->getAllOrderByVoteCount()->toArray(); // Get all rooms $rooms = $this->roomRepository->findAllLimited(6)->toArray(); // Generate timetable with service $success = $this->createTimetableService->generateTimetable($config, $sessions, $rooms, $iterations, $considerTopics); $incompleteSessions = array(); if (!$success) { $incompleteSessions = $this->createTimetableService->getUnassignedSessions(); } /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */ $db = $GLOBALS['TYPO3_DB']; // Save changes on sessions /** @var AcceptedSession $assignedSession*/ foreach ($this->createTimetableService->getAssignedSessions() as $assignedSession) { $this->anySessionRepository->update($assignedSession, true); $db->exec_UPDATEquery('tx_sessions_domain_model_session', 'uid = ' . $assignedSession->getUid(), ['type' => ScheduledSession::class]); } $this->redirect('index', 'SessionModule', 'sessions', ['incompleteSessions' => $incompleteSessions, 'creationDone' => true]); }
/** * @param AbstractSession $session * @validate $session \TYPO3\Sessions\Domain\Validator\ActiveUserValidator * @validate $session \TYPO3\Sessions\Domain\Validator\SessionOwnerValidator * @return string */ public function updateAction(AbstractSession $session) { $this->sessionRepository->update($session); return json_encode($session); }
/** * Method checks whether the given session collides with an existing one. * Checks if an associated speaker is associated to another session which: * - starts during the given session * - ends during the given session * - start at the same time as the given session * - ends at the same time as the given session * - surrounds the given session completely * * @param AbstractSession $session * @param array $exclude array of uids which should be exluded in the check (the given session is excluded by default) * @return array|false colliding sessions or false if no session collides * @throws \InvalidArgumentException */ public function getCollidingSessions(AbstractSession $session, $exclude = []) { if (!is_array($exclude)) { throw new \InvalidArgumentException('$exclude is not of type array. should be an array of uids'); } $speakers = $session->getSpeakers(); // array holding named placeholder values $params = []; // helper in order to prepare a dynamic IN statement $inStmt = []; $i = 0; foreach ($speakers as $speaker) { /** @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $speaker */ // build unique placeholder name $placeholder = ':idref' . $i++; // assign the correct uid to the placeholder $params[$placeholder] = $speaker->getUid(); // "store" the dynamic placeholder $inStmt[] = $placeholder . ' '; } // flatten the dynamic placeholders for later IN statement use $inStmt = implode(',', $inStmt); // helper for dynamic NOT IN statement if (count($exclude) > 0) { $i = 0; $excludeUids = array_merge([$session->getUid()], $exclude); $excludeInStmt = []; foreach ($excludeUids as $eUid) { // build unique placeholder name $placeholder = ':excludessessions' . $i++; // assign the correct uid to the placeholder $params[$placeholder] = $eUid; // store the dynamic placeholder for later $excludeInStmt[] = $placeholder; } // flatten dynamic placeholders for usage in IN statement $excludeInStmt = implode(', ', $excludeInStmt); } // set the rest of param values (respect DMBS datetime format) $params[':start'] = $session->getBegin()->format($this->dbDateTimeFormat); $params[':end'] = $session->getEnd()->format($this->dbDateTimeFormat); $params[':excludedsession'] = $session->getUid(); $params[':scheduledtype'] = \TYPO3\Sessions\Domain\Model\ScheduledSession::class; $stmt = $this->db->prepare_SELECTquery(' DISTINCT tx_sessions_domain_model_session.uid AS uid ', ' tx_sessions_domain_model_session LEFT JOIN tx_sessions_session_record_mm AS srmm ON tx_sessions_domain_model_session.uid = srmm.uid_local AND srmm.tablenames = \'fe_users\' LEFT JOIN fe_users AS user ON srmm.uid_foreign = user.uid ', ' user.uid IN (' . $inStmt . ') AND ( /* this session starts while another session is running (start overlaps with other session) */ ( tx_sessions_domain_model_session.begin > :start AND tx_sessions_domain_model_session.begin < :end ) OR /* this session ends while another session is running (end overlaps with other session) */ ( tx_sessions_domain_model_session.end > :start AND tx_sessions_domain_model_session.end < :end ) OR /* this session starts at the same time */ tx_sessions_domain_model_session.begin = :start OR /* this session ends at the same time */ tx_sessions_domain_model_session.end = :end OR /* this session starts before and ends after */ (tx_sessions_domain_model_session.begin < :start AND tx_sessions_domain_model_session.end > :end) ) AND tx_sessions_domain_model_session.uid ' . (isset($excludeInStmt) ? 'NOT IN(' . $excludeInStmt . ')' : '<> :excludedsession') . ' AND tx_sessions_domain_model_session.type = :scheduledtype ' . \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_sessions_domain_model_session') . ' ', '', ' tx_sessions_domain_model_session.uid DESC ', '', $params); if ($stmt->execute() && $stmt->rowCount() > 0) { if ($stmt->rowCount() === 1) { $row = $stmt->fetch(); $stmt->free(); return [$this->sessionRepository->findByUid($row['uid'])]; } $uids = []; while ($row = $stmt->fetch()) { $uids[] = $row['uid']; } $stmt->free(); return $this->sessionRepository->findByUids($uids)->toArray(); } return false; }