From 55b53ef30a849f3b7f01d3dbd249d743ec7b28b6 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Wed, 31 Jul 2024 21:54:30 +0300 Subject: [PATCH] Adds participants to monthly stats widget --- public_html/classes/conference.php | 4 ++-- public_html/classes/participant.php | 24 ++++++++++++++++++++++++ public_html/classes/queries.php | 14 +++++++++++++- public_html/pages/front.php | 23 ++++++++++++++++------- public_html/templates/widget-monthly.php | 10 +++++++++- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/public_html/classes/conference.php b/public_html/classes/conference.php index d9aaba4..c87fb34 100644 --- a/public_html/classes/conference.php +++ b/public_html/classes/conference.php @@ -85,7 +85,7 @@ class Conference { } // number of conferences - public function conferencesNumber($from_time, $until_time) { + public function conferenceNumber($from_time, $until_time) { // time period drill-down // FIXME make it similar to the bash version @@ -99,7 +99,7 @@ class Conference { // this is needed for compatibility with the bash version, so we use '%s' placeholders $from_time = htmlspecialchars(strip_tags($from_time)); $until_time = htmlspecialchars(strip_tags($until_time)); - $sql = $this->queries['conferences_number']; + $sql = $this->queries['conference_number']; $sql = sprintf($sql, $from_time, $until_time); $query = $this->db->prepare($sql); diff --git a/public_html/classes/participant.php b/public_html/classes/participant.php index bf68ff8..f23e2b5 100644 --- a/public_html/classes/participant.php +++ b/public_html/classes/participant.php @@ -109,6 +109,30 @@ class Participant { return $query->fetchAll(PDO::FETCH_ASSOC); } + // number of conferences + public function participantNumber($from_time, $until_time) { + + // time period drill-down + // FIXME make it similar to the bash version + if (empty($from_time)) { + $from_time = '0000-01-01'; + } + if (empty($until_time)) { + $until_time = '9999-12-31'; + } + + // this is needed for compatibility with the bash version, so we use '%s' placeholders + $from_time = htmlspecialchars(strip_tags($from_time)); + $until_time = htmlspecialchars(strip_tags($until_time)); + $sql = $this->queries['participant_number']; + $sql = sprintf($sql, $from_time, $until_time); + + $query = $this->db->prepare($sql); + $query->execute(); + + return $query->fetchAll(PDO::FETCH_ASSOC); + } + } diff --git a/public_html/classes/queries.php b/public_html/classes/queries.php index e781508..6d71180 100644 --- a/public_html/classes/queries.php +++ b/public_html/classes/queries.php @@ -5,7 +5,7 @@ return [ // number of conferences for time period (if given) - 'conferences_number' => " + 'conference_number' => " SELECT COUNT(c.conference_id) as conferences FROM conferences c @@ -201,6 +201,18 @@ ORDER BY pe.time;", + // number of participants for time period (if given) + 'participant_number' => " +SELECT COUNT(p.endpoint_id) as participants +FROM + participants p +LEFT JOIN + participant_events pe ON p.endpoint_id = pe.participant_id +WHERE + (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59') +AND pe.event_type = 'pair selected'", + + // list all participants 'participants_all' => " SELECT DISTINCT diff --git a/public_html/pages/front.php b/public_html/pages/front.php index 75df76b..5961a20 100644 --- a/public_html/pages/front.php +++ b/public_html/pages/front.php @@ -2,6 +2,7 @@ require_once 'classes/database.php'; require 'classes/conference.php'; +require 'classes/participant.php'; // connect to database try { @@ -20,6 +21,7 @@ try { //// // monthly usage $conference = new Conference($db); +$participant = new Participant($db); // monthly conferences for the last year $fromMonth = (new DateTime())->sub(new DateInterval('P1Y')); @@ -29,7 +31,8 @@ $from_time = $fromMonth->format('Y-m-d'); $until_time = $thisMonth->format('Y-m-d'); $widget['table_headers'] = array(); -$widget['table_records'] = array(); +$widget['table_records_conferences'] = array(); +$widget['table_records_participants'] = array(); // loop 1 year in the past while ($fromMonth < $thisMonth) { @@ -37,17 +40,23 @@ while ($fromMonth < $thisMonth) { $untilMonth = clone $fromMonth; $untilMonth->modify('last day of this month'); - $search = $conference->conferencesNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d')); + $searchConferenceNumber = $conference->conferenceNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d')); + $searchParticipantNumber = $participant->participantNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d')); // pretty format for displaying the month in the widget $month = $fromMonth->format('F Y'); // populate the table array_push($widget['table_headers'], $month); - if (isset($search[0]['conferences'])) { - array_push($widget['table_records'], $search[0]['conferences']); + if (isset($searchConferenceNumber[0]['conferences'])) { + array_push($widget['table_records_conferences'], $searchConferenceNumber[0]['conferences']); } else { - array_push($widget['table_records'], '0'); + array_push($widget['table_records_conferences'], '0'); + } + if (isset($searchParticipantNumber[0]['participants'])) { + array_push($widget['table_records_participants'], $searchParticipantNumber[0]['participants']); + } else { + array_push($widget['table_records_participants'], '0'); } // move everything one month in future @@ -60,11 +69,11 @@ $time_range_specified = true; // prepare the widget $widget['full'] = false; $widget['name'] = 'LastYearMonths'; -$widget['title'] = 'Conferences monthly number for the last year'; +$widget['title'] = 'Conferences monthly stats for the last year'; $widget['collapsible'] = true; $widget['collapsed'] = false; $widget['filter'] = false; -if (!empty($search)) { +if (!empty($searchConferenceNumber) && !empty($searchParticipantNumber)) { $widget['full'] = true; } diff --git a/public_html/templates/widget-monthly.php b/public_html/templates/widget-monthly.php index 020fec5..4ab369b 100644 --- a/public_html/templates/widget-monthly.php +++ b/public_html/templates/widget-monthly.php @@ -24,6 +24,7 @@ + @@ -31,7 +32,14 @@ - + + + + + + + +
conferences
participants