<?php require 'assets/php/models/TimeSlot.php'; $db_path = $_SERVER['DOCUMENT_ROOT'] . '/assets/database.sqlite'; $query_result; $wanted_slots; try { /*Setup SQL Interface*/ $pdo = new PDO('sqlite:' . $db_path); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*Prepare query*/ $query = $pdo->prepare("SELECT id, type, start_time, end_time, location FROM schedule NATURAL JOIN rooms WHERE type LIKE :type AND date(date) = date(:date) AND time(end_time) > time(:start_time) AND time(start_time) < time(:end_time)"); /** * QUERY DESCRIPTION : * Select all slots mathcing the date & room and where the time slot * is overllaping with the requested one. */ /*Execute query*/ $query->execute([ 'type' => $_GET['room_type'], 'date' => $_GET['date'], 'start_time' => $_GET['start_time'], 'end_time' => $_GET['end_time'] ]); $query_result = $query->fetchAll(PDO::FETCH_CLASS, 'TimeSlot'); /* Prepare wanted times slots in each room*/ $wanted_slots = array_map( /*Create new wanted slots for each unique room*/ function (Room $r): TimeSlot { $slot = new TimeSlot(); $slot->start_time = $_GET['start_time']; $slot->end_time = $_GET['end_time']; $slot->room = clone $r; return $slot; }, /*Construct an array of all unique rooms*/ array_unique(array_map( function (TimeSlot $x): Room { return $x->room; }, $query_result ), SORT_REGULAR) ); } catch (PDOException $exception) { echo var_dump($exception->getMessage()); } ?> <!DOCTYPE html> <html lang="en"> <head> <title>UFHOUR</title> <!-- Head --> <?php require("assets/php/head.php"); ?> <link rel="stylesheet" href="assets/css/search.css"> </head> <body> <main> <header> <h1>UFHOUR</h1> <p>Recherche de salles libres de l'UFR Math-Info</p> </header> <h2>Résultats de la recherche</h2> <hr> <section> <?php foreach ($query_result as $slot) $slot->display(); echo "WANTED SLOTS"; foreach ($wanted_slots as $slot) foreach ($query_result as $key => $value) { # code... } ?> </section> </main> <?php include "assets/php/cookies.php"; ?> <?php include "assets/php/nav.php"; ?> </body> </html>