diff --git a/includes/class-DailyEvents.php b/includes/class-DailyEvents.php --- a/includes/class-DailyEvents.php +++ b/includes/class-DailyEvents.php @@ -1,6 +1,6 @@ getConferenceID(); $chapter_ID = $chapter->getChapterID(); - $events = FullEvent::factoryByConferenceChapter( $conference_ID, $chapter_ID ) + // prepare the query + $events_query = ( new QueryEvent() ) + ->joinTrack() + ->joinChapter() + ->joinRoom() + ->whereConferenceID( $conference_ID ) + ->whereChapterID( $chapter_ID ) ->select( $fields ) ->orderBy( Event::START ) - ->orderBy( Track::ORDER ) - ->queryResults(); + ->orderBy( Track::ORDER ); + + // check if we should apply additional conditions + if( $additional_conditions ) { + $additional_conditions( $events_query ); + } + // query all the Events in an array + $events = $events_query->queryResults(); + + // index all the Events $incremental_hour = 0; $last_hour = -1; $last_event_ID = -1; foreach( $events as $i => $event ) { - // Remember that it's a JOIN with duplicates + + // Remember that it's a JOIN with duplicates (TODO: untrue now I think) if( $last_event_ID === $event->getEventID() ) { unset( $events[ $i ] ); continue; @@ -66,7 +84,8 @@ // Fill `->hour` $event->hour = $incremental_hour; - $last_event_ID = $event->event_ID; + // (TODO: remove, should work) + $last_event_ID = $event->getEventID(); $last_hour = $hour; } diff --git a/includes/class-QueryChapter.php b/includes/class-QueryChapter.php new file mode 100644 --- /dev/null +++ b/includes/class-QueryChapter.php @@ -0,0 +1,82 @@ +. + +/** + * Methods related to a QueryChapter class + */ +trait QueryChapterTrait { + + /** + * Where the Chapter is... + * + * @param object $event Chapter + * @return self + */ + public function whereChapter( $event ) { + return $this->whereChapterID( $event->getChapterID() ); + } + + /** + * Where the Chapter ID is... + * + * @param int $id Chapter ID + * @return self + */ + public function whereChapterID( $id ) { + return $this->whereInt( $this->CHAPTER_ID, $id ); + } + + /** + * Join a generic table with the Chapter table + * + * @param string $type Join type + * @return self + */ + public function joinChapter( $type = 'INNER' ) { + + // build the: + // INNER JOIN chapter ON (chapter.chapter_ID = chapter_ID) + return $this->joinOn( $type, Chapter::T, Chapter::ID_, $this->CHAPTER_ID ); + } + +} + +/** + * Utility used to Query a Chapter. + */ +class QueryChapter { + + use QueryChapterTrait; + + /** + * Full name of the column of the Chapter ID + */ + protected $CHAPTER_ID = 'chapter_ID'; + + /** + * Constructor + */ + public function __construct() { + + parent::__construct(); + + $this->from( Chapter::T ); + + $this->defaultClass( Chapter::class ); + } + +} diff --git a/includes/class-QueryEvent.php b/includes/class-QueryEvent.php --- a/includes/class-QueryEvent.php +++ b/includes/class-QueryEvent.php @@ -1,6 +1,6 @@ whereInt( EventUser::USER_, $user->getUserID() ); } - /** - * Join a table with the Chapter table - * - * @param string $type Join type - * @return self - */ - public function joinChapter( $type = 'INNER' ) { - return $this->joinOn( $type, 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID ); - } - /** * Join a table with the Track table * diff --git a/includes/class-QueryRoom.php b/includes/class-QueryRoom.php new file mode 100644 --- /dev/null +++ b/includes/class-QueryRoom.php @@ -0,0 +1,82 @@ +. + +/** + * Methods related to a QueryRoom class + */ +trait QueryRoomTrait { + + /** + * Where the Room is... + * + * @param object $event Room + * @return self + */ + public function whereRoom( $event ) { + return $this->whereRoomID( $event->getRoomID() ); + } + + /** + * Where the Room ID is... + * + * @param int $id Room ID + * @return self + */ + public function whereRoomID( $id ) { + return $this->whereInt( $this->ROOM_ID, $id ); + } + + /** + * Join a generic table with the Room table + * + * @param string $type Join type + * @return self + */ + public function joinRoom( $type = 'INNER' ) { + + // build the: + // INNER JOIN room ON (room.room_ID = room_ID) + return $this->joinOn( $type, Room::T, Room::ID_, $this->ROOM_ID ); + } + +} + +/** + * Utility used to Query a Room. + */ +class QueryRoom { + + use QueryRoomTrait; + + /** + * Full name of the column of the Room ID + */ + protected $ROOM_ID = 'room_ID'; + + /** + * Constructor + */ + public function __construct() { + + parent::__construct(); + + $this->from( Room::T ); + + $this->defaultClass( Room::class ); + } + +} diff --git a/includes/class-QueryTrack.php b/includes/class-QueryTrack.php new file mode 100644 --- /dev/null +++ b/includes/class-QueryTrack.php @@ -0,0 +1,82 @@ +. + +/** + * Methods related to a QueryTrack class + */ +trait QueryTrackTrait { + + /** + * Where the Track is... + * + * @param object $event Track + * @return self + */ + public function whereTrack( $event ) { + return $this->whereTrackID( $event->getTrackID() ); + } + + /** + * Where the Track ID is... + * + * @param int $id Track ID + * @return self + */ + public function whereTrackID( $id ) { + return $this->whereInt( $this->TRACK_ID, $id ); + } + + /** + * Join a generic table with the Track table + * + * @param string $type Join type + * @return self + */ + public function joinTrack( $type = 'INNER' ) { + + // build the: + // INNER JOIN track ON (track.track_ID = track_ID) + return $this->joinOn( $type, Track::T, Track::ID_, $this->TRACK_ID ); + } + +} + +/** + * Utility used to Query a Track. + */ +class QueryTrack { + + use QueryTrackTrait; + + /** + * Full name of the column of the Track ID + */ + protected $TRACK_ID = 'track_ID'; + + /** + * Constructor + */ + public function __construct() { + + parent::__construct(); + + $this->from( Track::T ); + + $this->defaultClass( Track::class ); + } + +}