/** * 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; }
/** * @param AbstractSession $session */ protected function addCacheTags(AbstractSession $session) { $cacheTags = []; $cacheTags[] = 'tx_sessions_domain_model_session_' . $session->getUid(); $speakers = ObjectAccess::getProperty($session, 'speakers'); foreach ($speakers as $speaker) { /** @var FrontendUser $speaker */ $cacheTags[] = 'fe_users_' . $speaker->getUid(); } if ($session->getRoom()) { $cacheTags[] = 'tx_sessions_domain_model_room_' . $session->getRoom()->getUid(); } $this->getTypoScriptFrontendController()->addCacheTags($cacheTags); }
/** * @return array */ public function jsonSerialize() { return ['session' => $this->session->getUid()]; }