Adds search for a specific conference name

main
Yasen Pramatarov 2024-07-05 11:36:03 +03:00
parent ff9aea0894
commit 69ff44c4a2
3 changed files with 151 additions and 3 deletions

View File

@ -19,7 +19,7 @@ class Conference {
} }
// search/list specific conference // search/list specific conference ID
public function conferenceById($conference_id, $from_time, $until_time) { public function conferenceById($conference_id, $from_time, $until_time) {
// time period drill-down // time period drill-down
@ -44,6 +44,31 @@ class Conference {
} }
// search/list specific conference name
public function conferenceByName($conference_name, $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['conference_by_name'];
$sql = sprintf($sql, $conference_name, $from_time, $until_time, $conference_name, $from_time, $until_time);
$query = $this->db->prepare($sql);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
// list of all conferences // list of all conferences
public function conferencesAllFormatted($from_time, $until_time) { public function conferencesAllFormatted($from_time, $until_time) {

View File

@ -94,7 +94,53 @@ WHERE
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59') AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY ORDER BY
pe.time;" pe.time;",
// search for a conference by its name for a time period (if given)
'conference_by_name' => "
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_name = '%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_name = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;",
]; ];

View File

@ -116,7 +116,84 @@ if (isset($conference_id)) {
} }
// list of all conferences // search and list specific conference ID
} elseif (isset($conference_name)) {
try {
$conference = new Conference($db);
// prepare the result
$search = $conference->conferenceByName($conference_name, $from_time, $until_time);
if (!empty($search)) {
$conferences = array();
$conferences['records'] = array();
foreach ($search as $item) {
extract($item);
$conference_record = array(
// assign title to the field in the array record
'time' => $time,
'conference ID' => $conference_id,
'conference name' => $conference_name,
'conference host' => $conference_host,
'loglevel' => $loglevel,
'participant ID' => $participant_id,
'event' => $event_type,
'parameter' => $event_param
);
// populate the result array
array_push($conferences['records'], $conference_record);
}
}
} catch (Exception $e) {
$error = 'Error: ' . $e->getMessage();
include 'templates/message.php';
exit();
}
// display the result
echo "Conferences with name matching \"<strong>$conference_name</strong>\"";
if ($time_range_specified) {
echo " for the time period <strong>$from_time - $until_time</strong>";
}
if (!empty($conferences['records'])) {
echo "\t<table id=\"results\">";
echo "\t\t<tr>";
// table headers
foreach (array_keys($conferences['records'][0]) as $header) {
echo "\t\t\t<th>" . htmlspecialchars($header) . "</th>";
}
echo "\t\t</tr>";
//table rows
foreach ($conferences['records'] as $row) {
echo "\t\t<tr>";
// sometimes $column is empty, we make it '' then
foreach ($row as $key => $column) {
if ($column === $conference_name) {
echo "\t\t\t<td><strong>" . htmlspecialchars($column ?? '') . "</strong></td>";
} elseif ($key === 'conference ID') {
echo "\t\t\t<td><a href=\"$app_root?page=conferences&id=" . htmlspecialchars($column ?? '') . "\">" . htmlspecialchars($column ?? '') . "</a></td>";
} else {
echo "\t\t\t<td>" . htmlspecialchars($column ?? '') . "</td>";
}
}
echo "\t\t</tr>";
}
echo "\t</table>";
} else {
echo '<p>No matching conferences found.</p>';
}
// list of all conferences (default)
} else { } else {
try { try {
$conference = new Conference($db); $conference = new Conference($db);