Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
add filter to export
Browse files Browse the repository at this point in the history
  • Loading branch information
Davka committed Nov 11, 2020
1 parent 11f0770 commit 92a0780
Show file tree
Hide file tree
Showing 7 changed files with 7,555 additions and 621 deletions.
96 changes: 51 additions & 45 deletions assets/bbb-connector-app.js

Large diffs are not rendered by default.

60 changes: 32 additions & 28 deletions controllers/statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
Metric::collect();

$this->buildSidebar();
}

Expand All @@ -22,13 +21,13 @@ public function index_action()
Navigation::activateItem('simplebbbconnector/statistics/index');
PageLayout::setTitle(_('Statistik'));
$current_month_complete = Metric::getStatistics('current_month');
$data = ['labels' => array_keys($current_month_complete)];
$data['datasets'][] = $this->buildDataSet(strftime('%B'), $current_month_complete, 'red', 'redDark');
$data['datasets'][] = $this->buildDataSet(_('Diese Woche'), Metric::getStatistics('current_week'), 'blue', 'blueDark');
$data['datasets'][] = $this->buildDataSet(_('Letzte Woche'), Metric::getStatistics('last_week'), 'green', 'greenDark');
$data['datasets'][] = $this->buildDataSet(_('Heute'), Metric::getStatistics('today'), 'yellow', 'yellowDark');
$data['datasets'][] = $this->buildDataSet(_('Gestern'), Metric::getStatistics('yesterday'), 'purple', 'purpleDark');
$this->dataset = json_encode($data);
$data = ['labels' => array_keys($current_month_complete)];
$data['datasets'][] = $this->buildDataSet(strftime('%B'), $current_month_complete, 'red', 'redDark');
$data['datasets'][] = $this->buildDataSet(_('Diese Woche'), Metric::getStatistics('current_week'), 'blue', 'blueDark');
$data['datasets'][] = $this->buildDataSet(_('Letzte Woche'), Metric::getStatistics('last_week'), 'green', 'greenDark');
$data['datasets'][] = $this->buildDataSet(_('Heute'), Metric::getStatistics('today'), 'yellow', 'yellowDark');
$data['datasets'][] = $this->buildDataSet(_('Gestern'), Metric::getStatistics('yesterday'), 'purple', 'purpleDark');
$this->dataset = json_encode($data);
$this->biggest_meetings = Metric::getStatistics('current_month', 'all', 10);
}

Expand All @@ -44,43 +43,48 @@ public function export_csv_action()
public function buildDataSet($label, $data, $border_color, $background_color)
{
$set = [
'label' => $label,
'data' => array_map('intval', array_values($data)),
'label' => $label,
'data' => array_map('intval', array_values($data)),
'borderWidth' => 1
];

for ($i = 0; $i < count($data); $i++) {
$set['borderColor'][] = $this->getColor($border_color);
$set['borderColor'][] = $this->getColor($border_color);
$set['backgroundColor'][] = $this->getColor($background_color);
}
return $set;
}

private function getColor($color)
{
$colors = ['redDark' => 'rgba(255, 99, 132, 0.2)',
'red' => 'rgba(255, 99, 132, 1)',
'blueDark' => 'rgba(54, 162, 235, 0.2)',
'blue' => 'rgba(54, 162, 235, 1)',
'yellowDark' => 'rgba(255, 206, 86, 0.2)',
'yellow' => 'rgba(255, 206, 86, 1)',
'greenDark' => 'rgba(75, 192, 192, 0.2)',
'green' => 'rgba(75, 192, 192, 1)',
'purpleDark' => 'rgba(153, 102, 255, 0.2)',
'purple' => 'rgba(153, 102, 255, 1)',
'brownDark' => 'rgba(255, 159, 64, 0.2)',
'brown' => 'rgba(255, 159, 64, 1)'];
$colors = [
'redDark' => 'rgba(255, 99, 132, 0.2)',
'red' => 'rgba(255, 99, 132, 1)',
'blueDark' => 'rgba(54, 162, 235, 0.2)',
'blue' => 'rgba(54, 162, 235, 1)',
'yellowDark' => 'rgba(255, 206, 86, 0.2)',
'yellow' => 'rgba(255, 206, 86, 1)',
'greenDark' => 'rgba(75, 192, 192, 0.2)',
'green' => 'rgba(75, 192, 192, 1)',
'purpleDark' => 'rgba(153, 102, 255, 0.2)',
'purple' => 'rgba(153, 102, 255, 1)',
'brownDark' => 'rgba(255, 159, 64, 0.2)',
'brown' => 'rgba(255, 159, 64, 1)'
];
return $colors[$color];
}

private function buildSidebar()
{
$exports = new ExportWidget();
$exports->addLink(
_('Als CSV herunterladen'),
$this->url_for('statistics/export_csv'),
Icon::create('file-excel')
$template_factory = new Flexi_TemplateFactory(__DIR__ . '/../templates');
$template = $template_factory->open('date-export-widget.php');
$template->url = $this->url_for('statistics/export_csv');
$exports = new SidebarWidget();
$exports->setTitle(_('CSV-Export'));
$exports->addElement(
new WidgetElement($template->render())
);

Sidebar::Get()->addWidget($exports);
}
}
74 changes: 39 additions & 35 deletions models/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PluginEngine;
use DBManager;
use SimpleORMapCollection;
use Request;

class Metric extends SimpleORMap
{
Expand All @@ -21,7 +22,7 @@ protected static function configure($config = [])
$config['db_table'] = 'bigbluebutton_metrics';

$config['belongs_to']['server'] = [
'class_name' => 'Vec\\BBB\\Server',
'class_name' => 'Vec\\BBB\\Server',
'foreign_key' => 'server_id',
];
parent::configure($config);
Expand All @@ -34,10 +35,13 @@ public static function getCollectedYears()

public static function getExport()
{
$metrics = self::findBySQL('1 ORDER BY `mkdate`');
list($start, $end) = array_map('date_create', [Request::get('from'), Request::get('to')]);
$metrics = self::findBySQL(
'start_time BETWEEN ? AND ? ORDER BY `mkdate`', [$start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')]
);
$results = [];
if (!empty($metrics)) {
$results[] = [
$results[] = [
'Server',
'Meeting-id',
'Meeting-Name',
Expand All @@ -56,28 +60,28 @@ public static function getExport()
foreach ($metrics as $metric) {
$start_date = '';
$start_time = '';
$end_date = '';
$end_time = '';
$end_date = '';
$end_time = '';
if ($metric->start_time) {
$start = new DateTime($metric->start_time);
$start = new DateTime($metric->start_time);
$start_date = $start->format('d.m.Y');
$start_time = $start->format('H:i');
}

$result = [];
$result['server'] = $metric->server->url;
$result['meeting_id'] = $metric->meeting_id;
$result['meeting_name'] = $metric->meeting_name;
$result['participant_count'] = $metric->participant_count;
$result['video_count'] = $metric->video_count;
$result['listener_count'] = $metric->listener_count;
$result = [];
$result['server'] = $metric->server->url;
$result['meeting_id'] = $metric->meeting_id;
$result['meeting_name'] = $metric->meeting_name;
$result['participant_count'] = $metric->participant_count;
$result['video_count'] = $metric->video_count;
$result['listener_count'] = $metric->listener_count;
$result['voice_participant_count'] = $metric->voice_participant_count;
$result['is_break_out'] = $metric->is_break_out;
$result['start_date'] = $start_date;
$result['start_time'] = $start_time;
$result['end_date'] = $end_date;
$result['end_time'] = $end_time;
$result['email'] = "";
$result['is_break_out'] = $metric->is_break_out;
$result['start_date'] = $start_date;
$result['start_time'] = $start_time;
$result['end_date'] = $end_date;
$result['end_time'] = $end_time;
$result['email'] = "";
if ($meeting_plugin_installed) {
$username = DBManager::get()->fetchColumn(
"SELECT a.username FROM auth_user_md5 a
Expand Down Expand Up @@ -107,7 +111,7 @@ public static function collect()
$servers = SimpleORMapCollection::createFromArray(
Server::findBySQL('1')
)->orderBy('name');
$msgs = [];
$msgs = [];

foreach ($servers as $server) {
$result = ['server' => $server];
Expand All @@ -127,26 +131,26 @@ public static function collect()
$start_time = (new DateTime())
->setTimestamp((int)$meeting->startTime / 1000)
->format(self::BBB_DATETIME_FORMAT);
$end_time = null;
$end_time = null;
if ((int)$meeting->endTime) {
$end_time = (new DateTime())
->setTimestamp((int)$meeting->endTime / 1000)
->format(self::BBB_DATETIME_FORMAT);
}

$data =
$data =
[
'server_id' => $server->id,
'meeting_id' => (string)$meeting->meetingID,
'meeting_name' => (string)$meeting->meetingName,
'participant_count' => (string)$meeting->participantCount,
'video_count' => (int)$meeting->videoCount,
'listener_count' => (int)$meeting->listenerCount,
'server_id' => $server->id,
'meeting_id' => (string)$meeting->meetingID,
'meeting_name' => (string)$meeting->meetingName,
'participant_count' => (string)$meeting->participantCount,
'video_count' => (int)$meeting->videoCount,
'listener_count' => (int)$meeting->listenerCount,
'voice_participant_count' => (int)$meeting->voiceParticipantCount,
'moderator_count' => (int)$meeting->moderatorCount,
'is_break_out' => (string)$meeting->isBreakout === "true" ? 1 : 0,
'start_time' => $start_time,
'end_time' => $end_time,
'moderator_count' => (int)$meeting->moderatorCount,
'is_break_out' => (string)$meeting->isBreakout === "true" ? 1 : 0,
'start_time' => $start_time,
'end_time' => $end_time,
];
$metric = self::findOneBySQL('meeting_id = ? AND start_time = ?', [$data['meeting_id'], $data['start_time']]);
if (!$metric) {
Expand Down Expand Up @@ -188,13 +192,13 @@ public static function getStatistics($filter = '', $mode = 'sum', $limit = null)

if ($filter !== '') {
$result = self::getFilter($filter);
list($begin, $end) = $result;
[$begin, $end] = $result;
}

if ($begin && $end) {
$sql .= ' WHERE start_time BETWEEN :start_time AND :end_time';
$sql .= ' WHERE start_time BETWEEN :start_time AND :end_time';
$attributes[':start_time'] = $begin;
$attributes[':end_time'] = $end;
$attributes[':end_time'] = $end;
}
$sql .= ' ORDER BY `participant_count` DESC, `meeting_name`';

Expand Down
Loading

0 comments on commit 92a0780

Please sign in to comment.