Adds widget for monthly conferences number

main
Yasen Pramatarov 2024-07-30 12:54:29 +03:00
parent c0c072884f
commit 42f9738128
16 changed files with 271 additions and 101 deletions

View File

@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
### Added ### Added
- Added collapsible front page widgets - Added collapsible front page widgets
- Added widgets to conferences, participants and components pages - Added widgets to conferences, participants and components pages
- Added front page widget for monthly conferences number
### Changed ### Changed
- MVC design - models(classes folder), views(templates folder) and controllers(pages folder) - MVC design - models(classes folder), views(templates folder) and controllers(pages folder)

View File

@ -84,6 +84,30 @@ class Conference {
return $query->fetchAll(PDO::FETCH_ASSOC); return $query->fetchAll(PDO::FETCH_ASSOC);
} }
// number of conferences
public function conferencesNumber($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['conferences_number'];
$sql = sprintf($sql, $from_time, $until_time);
$query = $this->db->prepare($sql);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
} }

View File

@ -4,6 +4,64 @@
return [ return [
// number of conferences for time period (if given)
'conferences_number' => "
SELECT COUNT(c.conference_id) as conferences
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE (ce.time >= '%s 00:00:00' AND ce.time <= '%s 23:59:59')",
// search for a conference by its ID for a time period (if given)
'conference_by_id' => "
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_id = '%s'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
c.conference_id = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;",
// list of conferences for time period (if given) // list of conferences for time period (if given)
// fields: component, duration, conference ID, conference name, number of participants, name count (the conf name is found), conference host // fields: component, duration, conference ID, conference name, number of participants, name count (the conf name is found), conference host
'conferences_all_formatted' => " 'conferences_all_formatted' => "

View File

@ -83,27 +83,27 @@ if (in_array($page, $allowed_urls)) {
setcookie('username', "", time() - 100, $config['folder'], $config['domain'], isset($_SERVER['HTTPS']), true); setcookie('username', "", time() - 100, $config['folder'], $config['domain'], isset($_SERVER['HTTPS']), true);
$notice = "You were logged out.<br />You can log in again."; $notice = "You were logged out.<br />You can log in again.";
include 'templates/header.php'; include 'templates/page-header.php';
include 'templates/menu.php'; include 'templates/page-menu.php';
include 'templates/message.php'; include 'templates/block-message.php';
include 'pages/login.php'; include 'pages/login.php';
// all other normal pages // all other normal pages
} else { } else {
include 'templates/header.php'; include 'templates/page-header.php';
include 'templates/menu.php'; include 'templates/page-menu.php';
include 'templates/message.php'; include 'templates/block-message.php';
include "pages/{$page}.php"; include "pages/{$page}.php";
} }
// the page is not in allowed urls, loading front page // the page is not in allowed urls, loading front page
} else { } else {
include 'templates/header.php'; include 'templates/page-header.php';
include 'templates/menu.php'; include 'templates/page-menu.php';
include 'templates/message.php'; include 'templates/block-message.php';
include 'pages/front.php'; include 'pages/front.php';
} }
include 'templates/footer.php'; include 'templates/page-footer.php';
// clear errors and notices before next page just in case // clear errors and notices before next page just in case
unset($_SESSION['error']); unset($_SESSION['error']);

View File

@ -37,7 +37,7 @@ try {
$db = new Database($config['jilo_database']); $db = new Database($config['jilo_database']);
} catch (Exception $e) { } catch (Exception $e) {
$error = 'Error: ' . $e->getMessage(); $error = 'Error: ' . $e->getMessage();
include 'templates/message.php'; include 'templates/block-message.php';
exit(); exit();
} }

View File

@ -38,7 +38,7 @@ try {
$db = new Database($config['jilo_database']); $db = new Database($config['jilo_database']);
} catch (Exception $e) { } catch (Exception $e) {
$error = 'Error: ' . $e->getMessage(); $error = 'Error: ' . $e->getMessage();
include 'templates/message.php'; include 'templates/block-message.php';
exit(); exit();
} }

View File

@ -8,7 +8,7 @@ try {
$db = new Database($config['jilo_database']); $db = new Database($config['jilo_database']);
} catch (Exception $e) { } catch (Exception $e) {
$error = 'Error: ' . $e->getMessage(); $error = 'Error: ' . $e->getMessage();
include 'templates/message.php'; include 'templates/block-message.php';
exit(); exit();
} }
@ -16,52 +16,102 @@ try {
// dashboard widget listings // dashboard widget listings
// //
// conferences in last 7 days
try {
$conference = new Conference($db);
// conferences for last 2 days ////
$from_time = date('Y-m-d', time() - 60 * 60 * 24 * 2); // monthly usage
$until_time = date('Y-m-d', time()); $conference = new Conference($db);
$time_range_specified = true;
// prepare the result // monthly conferences for the last year
$search = $conference->conferencesAllFormatted($from_time, $until_time); $fromMonth = (new DateTime())->sub(new DateInterval('P1Y'));
$fromMonth->modify('first day of this month');
$thisMonth = new DateTime();
$from_time = $fromMonth->format('Y-m-d');
$until_time = $thisMonth->format('Y-m-d');
if (!empty($search)) { $widget['table_headers'] = array();
$conferences = array(); $widget['table_records'] = array();
$conferences['records'] = array();
foreach ($search as $item) { // loop 1 year in the past
extract($item); while ($fromMonth < $thisMonth) {
// we don't have duration field, so we calculate it $untilMonth = clone $fromMonth;
if (!empty($start) && !empty($end)) { $untilMonth->modify('last day of this month');
$duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
} else { $search = $conference->conferencesNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
$duration = '';
} // pretty format for displaying the month in the widget
$conference_record = array( $month = $fromMonth->format('F Y');
// assign title to the field in the array record
'component' => $jitsi_component, // populate the table
'start' => $start, array_push($widget['table_headers'], $month);
'end' => $end, if (isset($search[0]['conferences'])) {
'duration' => $duration, array_push($widget['table_records'], $search[0]['conferences']);
'conference ID' => $conference_id, } else {
'conference name' => $conference_name, array_push($widget['table_records'], '0');
'participants' => $participants,
'name count' => $name_count,
'conference host' => $conference_host
);
// populate the result array
array_push($conferences['records'], $conference_record);
}
} }
} catch (Exception $e) { // move everything one month in future
$error = 'Error: ' . $e->getMessage(); $untilMonth->add(new DateInterval('P1M'));
include 'templates/message.php'; $fromMonth->add(new DateInterval('P1M'));
exit(); }
$time_range_specified = true;
// prepare the widget
$widget['full'] = false;
$widget['name'] = 'LastYearMonths';
$widget['title'] = 'Conferences monthly number for the last year';
$widget['collapsible'] = true;
$widget['collapsed'] = false;
$widget['filter'] = false;
if (!empty($search)) {
$widget['full'] = true;
}
// display the widget
include('templates/widget-monthly.php');
////
// conferences in last 2 days
$conference = new Conference($db);
// time range limit
$from_time = date('Y-m-d', time() - 60 * 60 * 24 * 2);
$until_time = date('Y-m-d', time());
$time_range_specified = true;
// prepare the result
$search = $conference->conferencesAllFormatted($from_time, $until_time);
if (!empty($search)) {
$conferences = array();
$conferences['records'] = array();
foreach ($search as $item) {
extract($item);
// we don't have duration field, so we calculate it
if (!empty($start) && !empty($end)) {
$duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
} else {
$duration = '';
}
$conference_record = array(
// assign title to the field in the array record
'component' => $jitsi_component,
'start' => $start,
'end' => $end,
'duration' => $duration,
'conference ID' => $conference_id,
'conference name' => $conference_name,
'participants' => $participants,
'name count' => $name_count,
'conference host' => $conference_host
);
// populate the result array
array_push($conferences['records'], $conference_record);
}
} }
// prepare the widget // prepare the widget
@ -81,59 +131,53 @@ if (!empty($conferences['records'])) {
include('templates/widget.php'); include('templates/widget.php');
////
// last 10 conferences // last 10 conferences
try { $conference = new Conference($db);
$conference = new Conference($db);
// all time // all time
$from_time = '0000-01-01'; $from_time = '0000-01-01';
$until_time = '9999-12-31'; $until_time = '9999-12-31';
$time_range_specified = false; $time_range_specified = false;
// number of conferences to show // number of conferences to show
$conference_number = 10; $conference_number = 10;
// prepare the result // prepare the result
$search = $conference->conferencesAllFormatted($from_time, $until_time); $search = $conference->conferencesAllFormatted($from_time, $until_time);
if (!empty($search)) { if (!empty($search)) {
$conferences = array(); $conferences = array();
$conferences['records'] = array(); $conferences['records'] = array();
$i = 0; $i = 0;
foreach ($search as $item) { foreach ($search as $item) {
extract($item); extract($item);
// we don't have duration field, so we calculate it // we don't have duration field, so we calculate it
if (!empty($start) && !empty($end)) { if (!empty($start) && !empty($end)) {
$duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start))); $duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
} else { } else {
$duration = ''; $duration = '';
}
$conference_record = array(
// assign title to the field in the array record
'component' => $jitsi_component,
'start' => $start,
'end' => $end,
'duration' => $duration,
'conference ID' => $conference_id,
'conference name' => $conference_name,
'participants' => $participants,
'name count' => $name_count,
'conference host' => $conference_host
);
// populate the result array
array_push($conferences['records'], $conference_record);
// we only take the first 10 results
$i++;
if ($i == 10) break;
} }
} $conference_record = array(
// assign title to the field in the array record
'component' => $jitsi_component,
'start' => $start,
'end' => $end,
'duration' => $duration,
'conference ID' => $conference_id,
'conference name' => $conference_name,
'participants' => $participants,
'name count' => $name_count,
'conference host' => $conference_host
);
// populate the result array
array_push($conferences['records'], $conference_record);
} catch (Exception $e) { // we only take the first 10 results
$error = 'Error: ' . $e->getMessage(); $i++;
include 'templates/message.php'; if ($i == 10) break;
exit(); }
} }
// prepare the widget // prepare the widget

View File

@ -42,7 +42,7 @@ try {
$db = new Database($config['jilo_database']); $db = new Database($config['jilo_database']);
} catch (Exception $e) { } catch (Exception $e) {
$error = 'Error: ' . $e->getMessage(); $error = 'Error: ' . $e->getMessage();
include 'templates/message.php'; include 'templates/block-message.php';
exit(); exit();
} }

View File

@ -28,7 +28,7 @@ try {
$error = $e->getMessage(); $error = $e->getMessage();
} }
include 'templates/message.php'; include 'templates/block-message.php';
include 'templates/form-register.php'; include 'templates/form-register.php';
?> ?>

View File

@ -0,0 +1,44 @@
<div class="row">
<?php if ($widget['collapsible'] === true) { ?>
<a style="text-decoration: none;" data-toggle="collapse" href="#collapse<?= $widget['name'] ?>" role="button" aria-expanded="true" aria-controls="collapse<?= $widget['name'] ?>">
<div class="card w-auto bg-light card-body" style="flex-direction: row;"><?= $widget['title'] ?></div>
<?php } else { ?>
<div class="card w-auto bg-light border-light card-body" style="flex-direction: row;"><?= $widget['title'] ?></div>
<?php } ?>
<?php if ($widget['filter'] === true) {
include('templates/block-results-filter.php'); } ?>
<?php if ($widget['collapsible'] === true) { ?>
</a>
<?php } ?>
</div>
<div class="collapse show" id="collapse<?= $widget['name'] ?>">
<?php if ($time_range_specified) { ?>
<p class="m-3">time period: <strong><?= $from_time ?> - <?= $until_time ?></strong></p>
<?php } ?>
<div class="mb-5">
<?php if ($widget['full'] === true) { ?>
<table class="table table-striped table-hover table-bordered">
<thead class="thead-dark">
<tr>
<?php foreach ($widget['table_headers'] as $header) { ?>
<th scope="col"><?= htmlspecialchars($header) ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($widget['table_records'] as $row) { ?>
<td><?= htmlspecialchars($row ?? '') ?></td>
<?php } ?>
</tr>
</tbody>
</table>
<?php } else { ?>
<p class="m-3">No matching records found.</p>
<?php } ?>
</div>
</div>

View File

@ -8,8 +8,7 @@
<div class="card w-auto bg-light border-light card-body" style="flex-direction: row;"><?= $widget['title'] ?></div> <div class="card w-auto bg-light border-light card-body" style="flex-direction: row;"><?= $widget['title'] ?></div>
<?php } ?> <?php } ?>
<?php if ($widget['filter'] === true) { <?php if ($widget['filter'] === true) {
include('templates/results-filter.php'); include('templates/block-results-filter.php'); } ?>
} ?>
<?php if ($widget['collapsible'] === true) { ?> <?php if ($widget['collapsible'] === true) { ?>
</a> </a>
<?php } ?> <?php } ?>