@@ -107,6 +107,42 @@ public static function get_all_slots(): array {
107107 return $ slotsobj ;
108108 }
109109
110+ /**
111+ * Returns a list of all slots relevant for a vintage and range of weekdays.
112+ *
113+ * @param string $vintage the vintage to filter for
114+ * @param int $today the starting day to filter for
115+ * @param int $range the range in days
116+ * @return slot[] An array of the slots.
117+ */
118+ public static function get_vintage_time_slots (string $ vintage , int $ today , int $ range ): array {
119+ global $ DB ;
120+
121+ if ($ range < 7 ) {
122+ $ valid = [];
123+ for ($ i = $ today ; $ i < ($ today + $ range ); $ i ++) {
124+ array_push ($ valid , (($ i - 1 ) % 7 ) + 1 );
125+ }
126+ $ insert = " AND slot.weekday IN ( " . implode (', ' , $ valid ) . ") " ;
127+ } else {
128+ $ insert = '' ;
129+ }
130+
131+ $ slots = $ DB ->get_records_sql (
132+ 'SELECT slot.* FROM { ' . self ::TABLE_SLOTS . '} as slot ' .
133+ 'INNER JOIN { ' . self ::TABLE_SLOT_FILTERS . '} as filter ON slot.id=filter.slotid ' .
134+ 'WHERE (filter.vintage=? OR filter.vintage=NULL) ' . $ insert ,
135+ [$ vintage ]
136+ );
137+
138+ $ slotsobj = [];
139+ foreach ($ slots as $ slot ) {
140+ array_push ($ slotsobj , slot::from_db ($ slot ));
141+ }
142+
143+ return $ slotsobj ;
144+ }
145+
110146 /**
111147 * Returns a list of all slots belonging to a supervisor.
112148 * @param int $supervisorid userid of the supervisor in question
@@ -306,6 +342,9 @@ public static function filter_slots_for_user(array $allslots, \stdClass $user):
306342 * @return slot[] the filtered slot array
307343 */
308344 public static function filter_slots_for_time (array $ allslots , int $ range ): array {
345+ if ($ range === 7 ) {
346+ return $ allslots ;
347+ }
309348 $ utctz = new DateTimeZone ('UTC ' );
310349 $ now = new DateTimeImmutable ('now ' , $ utctz );
311350 $ slots = [];
0 commit comments