diff --git a/assets/css/search.css b/assets/css/search.css index 7290550bc49d12d45bda4b1627eeca9147bd9575..156a348ec05e73df7539e7c008f4381726ad977c 100644 --- a/assets/css/search.css +++ b/assets/css/search.css @@ -5,6 +5,7 @@ section { overflow:hidden; overflow-y:scroll; height: 55vh; width: 40rem; + border-radius: 10px; } h2 { diff --git a/assets/database.sqlite b/assets/database.sqlite index a261d9485895755000ef963a74c9d1c472888104..0023b829897185d52c3a41616f2dd6d40079f46f 100644 Binary files a/assets/database.sqlite and b/assets/database.sqlite differ diff --git a/assets/php/models/TimeSlot.php b/assets/php/models/TimeSlot.php index dc93b4106987ef70f3abf06525302c54dc661262..bbcedb2ac04402fad7521a4e23017ab588b7c896 100644 --- a/assets/php/models/TimeSlot.php +++ b/assets/php/models/TimeSlot.php @@ -68,6 +68,10 @@ class TimeSlot public function cut(TimeSlot $slot): array { + // Early return : nothing to cut / no overlap + if ($slot->start >= $this->end || $slot->end <= $this->start) + return [$this]; + $cutout = []; $ss_diff = $this->start->diff($slot->start); @@ -94,8 +98,6 @@ class TimeSlot $pre->end->add($es_diff); $post->start->add($se_diff); array_push($cutout, $pre, $post); - } elseif (!($ss_diff->invert && !$ee_diff->invert)) { - array_push($cutout, $this); } return array_filter($cutout, function (TimeSlot $e) { diff --git a/search.php b/search.php index 178adaa314453815d3ec1ab97b1449624b1940d9..5ba400806d95f7cdf95a646f005663a6f5d16b7e 100644 --- a/search.php +++ b/search.php @@ -17,7 +17,8 @@ try { $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)"); + AND time(end_time) > time(:start_time) AND time(start_time) < time(:end_time) + ORDER BY start_time"); /** * QUERY DESCRIPTION : @@ -78,9 +79,8 @@ try { <h2>Résultats de la recherche</h2> <hr> <section> - <?php - $final_results = []; + $results = []; foreach ($wanted_slots as $span) { $scissors = array_filter( $query_result, @@ -89,51 +89,24 @@ try { } ); + foreach ($scissors as $b) { + $b->display(); + } + $strips = [$span]; foreach ($scissors as $blade) { $cuts = []; foreach ($strips as $sub_span) - { - echo "Strip"; - foreach ($sub_span->cut($blade) as $x) { - $x->display(); - } $cuts = array_merge($cuts, $sub_span->cut($blade)); - } - - $strips = $cuts; + + $strips = $cuts; } - $final_results = array_merge($final_results, $strips); + $results = array_merge($results, $strips); } - foreach ($final_results as $slot) + foreach ($results as $slot) $slot->display(); - - // echo "test"; - // $test_room = new Room(); - // $test_room->id = "UWU"; - // $test_room->location = 10; - // $test_room->type = "tp"; - - // $test_span = new TimeSlot(); - // $test_span->start_time = "09:00"; - // $test_span->end_time = "15:00"; - // $test_span->room = $test_room; - - // $test_cut = new TimeSlot(); - // $test_cut->start_time = "13:00"; - // $test_cut->end_time = "15:00"; - // $test_cut->room = $test_room; - - - // $res = $test_span->cut($test_cut); - // foreach ($res as $x) { - // $x->display(); - // } ?> - - - </section> </main> <?php include "assets/php/cookies.php"; ?>