Add getClassesInTime API method

This API method allows for a client to get the classes which took/will
take place at a specific time.

commit c69382ea8fe906d9d5ca783adb9e955163f4098e
Author: Sergi Soler 'fraret <fraretblauet@gmail.com>
Date:   Sun Oct 4 12:50:57 2020 +0200

    Changed getClasses in time to POST and fixed very minor issues with latest commit

commit 19f9688a16fe1de667f02c0f33b7375b51356d13
Author: Sergi Soler 'fraret <fraretblauet@gmail.com>
Date:   Sat Oct 3 14:54:24 2020 +0200

    Added option to get Classes at specific time

Close #1

Co-authored-by: Sergi Soler 'fraret <fraretblauet@gmail.com>
diff --git a/inc/Classes.php b/inc/Classes.php
index 6bfa0c8..c1ee0b3 100644
--- a/inc/Classes.php
+++ b/inc/Classes.php
@@ -4,17 +4,22 @@
 class Classes {
   // Marge en segons per seguir retornant una assignatura abans o després que
   // acabi, quan s'obtenen les classes actuals.
-  const MARGIN_BEGINS = 5*60;
-  const MARGIN_ENDS = 5*60;
+  const CURRENT_MARGIN_BEGINS = 5*60;
+  const CURRENT_MARGIN_ENDS = 5*60;
 
-  public static function getCurrentClasses() {
+  const INTIME_MARGIN_BEGINS = 0*60;
+  const INTIME_MARGIN_ENDS = 0*60;
+
+
+  public static function getClasses(int $unix_time = NULL) {
     global $con;
 
     $isSignedIn = Users::isSignedIn();
 
-    $sentence = 'SELECT c.id, c.calendar_name, c.room, c.begins, c.ends, c.calendar_name, s.id subject_id, s.friendly_name'.($isSignedIn ? ', u_s.id user_subject_id' : '').',
+    $sentence = 'SELECT c.id, c.calendar_name, c.room, c.begins, c.ends, c.calendar_name, s.id subject_id, s.friendly_name
+      '.($isSignedIn ? ', u_s.id user_subject_id' : '').',
           CASE
-            WHEN c.begins > UNIX_TIMESTAMP() OR c.ends < UNIX_TIMESTAMP()
+            WHEN c.begins > :unix_time OR c.ends < :unix_time
               THEN 0
               ELSE 1
           END is_current
@@ -25,8 +30,8 @@
           ON s.id = u_s.subject_id
         ' : '').
         'WHERE
-          c.begins - '.self::MARGIN_BEGINS.' <= UNIX_TIMESTAMP() AND
-          c.ends + '.self::MARGIN_ENDS.' >= UNIX_TIMESTAMP()'.($isSignedIn ? ' AND
+          c.begins - '.($unix_time ? self::CURRENT_MARGIN_BEGINS : self::INTIME_MARGIN_BEGINS).' <= :unix_time AND
+          c.ends + '.($unix_time ? self::CURRENT_MARGIN_ENDS: self::INTIME_MARGIN_ENDS).' >= :unix_time'.($isSignedIn ? ' AND
           (
             u_s.user_id = :user_id OR
             u_s.subject_id IS NULL
@@ -37,10 +42,13 @@
           '.($isSignedIn ? 'u_s.subject_id IS NULL,
           ' : '').'s.friendly_name ASC';
     $query = $con->prepare($sentence);
-    
-    if (!$query->execute(($isSignedIn ? ['user_id' => Users::getUserId()] : [])))
-      return false;
 
+    if (!$unix_time) $unix_time = time();
+
+    $query_params = ['unix_time' => $unix_time];
+    if ($isSignedIn) $query_params['user_id'] = Users::getUserId();
+
+    if (!$query->execute($query_params)) return false;
     $classes = $query->fetchAll(\PDO::FETCH_ASSOC);
 
     foreach ($classes as &$class) {