Elgg  Version master
queue.php
Go to the documentation of this file.
1 <?php
4 
5 // show queue database statistics
6 
7 $header = '<tr><th>' . elgg_echo('admin:statistics:queue:name') . '</th>';
8 $header .= '<th>' . elgg_echo('admin:statistics:queue:row_count') . '</th>';
9 $header .= '<th>' . elgg_echo('admin:statistics:queue:oldest') . '</th>';
10 $header .= '<th>' . elgg_echo('admin:statistics:queue:newest') . '</th></tr>';
11 
12 $qb = Select::fromTable(DatabaseQueue::TABLE_NAME);
13 $qb->select('DISTINCT name');
14 
15 $queue_names = _elgg_services()->db->getData($qb);
16 if (empty($queue_names)) {
17  return;
18 }
19 
20 $rows = '';
21 foreach ($queue_names as $queue) {
22  $qb = Select::fromTable(DatabaseQueue::TABLE_NAME);
23  $qb->select('COUNT(*) AS total');
24  $qb->where($qb->compare('name', '=', $queue->name, ELGG_VALUE_STRING, true));
25 
26  $row_count = _elgg_services()->db->getDataRow($qb);
27  $row_count = empty($row_count) ? 0 : (int) $row_count->total;
28 
29  $qb = Select::fromTable(DatabaseQueue::TABLE_NAME);
30  $qb->select('MIN(timestamp) AS min');
31  $qb->where($qb->compare('name', '=', $queue->name, ELGG_VALUE_STRING, true));
32 
33  $oldest = _elgg_services()->db->getDataRow($qb);
34  $oldest = empty($oldest) ? 0 : (int) $oldest->min;
35  $oldest = elgg_view('output/datetime-local', ['value' => $oldest]);
36 
37  $qb = Select::fromTable(DatabaseQueue::TABLE_NAME);
38  $qb->select('MAX(timestamp) AS max');
39  $qb->where($qb->compare('name', '=', $queue->name, ELGG_VALUE_STRING, true));
40 
41  $newest = _elgg_services()->db->getDataRow($qb);
42  $newest = empty($newest) ? 0 : (int) $newest->max;
43  $newest = elgg_view('output/datetime-local', ['value' => $newest]);
44 
45  $rows .= "<tr><td>{$queue->name}</td><td>{$row_count}</td><td>{$oldest}</td><td>{$newest}</td></tr>";
46 }
47 
48 $body = "<table class='elgg-table'><thead>{$header}</thead><tbody>{$rows}</tbody></table>";
49 
50 echo elgg_view_module('info', elgg_echo('admin:statistics:queue'), $body);
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:919
$header
Definition: queue.php:7
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$queue_names
Definition: queue.php:15
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(empty($queue_names)) $rows
Definition: queue.php:20
const ELGG_VALUE_STRING
Definition: constants.php:112
foreach($queue_names as $queue) $body
Definition: queue.php:48
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
$qb
Definition: queue.php:12