From 7c18add7708dee37fbd16faa569c6ef8c14bdcbc Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 3 Dec 2015 10:05:20 +0100 Subject: [PATCH] added getEventsByDateAndCategories --- getEvents.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/getEvents.php b/getEvents.php index e60f680..ca0e47b 100755 --- a/getEvents.php +++ b/getEvents.php @@ -96,6 +96,34 @@ function getEventsByDate($db, $date) } } +/** + * @brief queries the database for the events on a certain date, where the categories are matched + * @param $db: the PDO connection to the database + * @param $date: the date to search for + * @param $categories: an array containing the IDs of the categories + * @return a list of all the events of the different categories at the date $date + */ +function getEventsByDateAndCategories($db, $date, $categories) +{ + try + { + $request = $db->prepare('SELECT events.id, events.titre, events.localisation, events.dtstart, events.dtend, events.description FROM events, categorie WHERE events.categorie = categorie.id AND (dtstart <= :date AND dtend >= :date) AND events.categorie IN :categories'); + $request->execute(array( + 'date'=>date("Y-m-d",$date), + 'categories'=>implode(',', array_map('intval', $categories)) + )); + $result = $request->fetchAll(); + $request->closeCursor(); + return $result; + } + catch(PDOException $e) + { + //NOTE: change $e->getMessage() by an error message before going to production + echo($e->getMessage()); + die(); + } +} + /** * @brief queries the database for the events after a certain date * @param $db: the PDO connection to the database