Skip to content

Commit

Permalink
added: charts for top 10 groups with most content and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Dec 21, 2023
1 parent b8ea932 commit edf85a4
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 1 deletion.
2 changes: 2 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
'advanced_statistics:content:subscriptions' => 'Content subscriptions',
'advanced_statistics:content:subscriptions:help' => 'Shows the number of subscribers on content over time, excluding the owner subscriptions.',
'advanced_statistics:content:block_subscriptions' => 'Content block subscriptions',
'advanced_statistics:content:active_groups' => 'Top 10 groups with the most new content',
'advanced_statistics:content:commenting_groups' => 'Top 10 groups with the most comments',

// system
'advanced_statistics:system:files:users' => 'Users with the most files and photos',
Expand Down
2 changes: 2 additions & 0 deletions languages/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'advanced_statistics:content:subscriptions' => 'Content abonnementen',
'advanced_statistics:content:subscriptions:help' => 'Toont het aantal abonnees op content over tijd, exclusief de eigenaren abonnementen',
'advanced_statistics:content:block_subscriptions' => 'Geblokkeerde content abonnementen',
'advanced_statistics:content:active_groups' => 'Top 10 groepen met de meeste content',
'advanced_statistics:content:commenting_groups' => 'Top 10 groepen met de meeste reacties',
'advanced_statistics:settings:enable_group_stats' => 'Schakel statistieken voor groepsbeheerders in',
'advanced_statistics:group:title' => 'Groepsstatistieken',
'advanced_statistics:group:members' => 'Leden',
Expand Down
19 changes: 19 additions & 0 deletions views/default/admin/advanced_statistics/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,22 @@
'section' => 'content',
'chart' => 'block_subscriptions',
]);

echo elgg_view('advanced_statistics/elements/chart', [
'title' => elgg_echo('advanced_statistics:content:active_groups'),
'id' => 'advanced-statistics-content-active-groups',
'date_limited' => true,
'allow_export' => false,
'page' => 'admin_data',
'section' => 'content',
'chart' => 'active_groups',
]);

echo elgg_view('advanced_statistics/elements/chart', [
'title' => elgg_echo('advanced_statistics:content:commenting_groups'),
'id' => 'advanced-statistics-content-commenting-groups',
'date_limited' => true,
'page' => 'admin_data',
'section' => 'content',
'chart' => 'commenting_groups',
]);
3 changes: 2 additions & 1 deletion views/default/js/advanced_statistics/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(['jquery', 'jqplot/jquery.jqplot'], function($) {
ajax.view($(this).data().chartHref, {
success: function(result){
var options = result.options;

console.log(result.options);
if (options['seriesDefaults']) {
options['seriesDefaults']['renderer'] = eval(options['seriesDefaults']['renderer']);
}
Expand All @@ -51,6 +51,7 @@ define(['jquery', 'jqplot/jquery.jqplot'], function($) {
if (options['axesDefaults']) {
options['axesDefaults']['tickRenderer'] = eval(options['axesDefaults']['tickRenderer']);
}
console.log(options);

if (result.data[0].length) {
$target.html(''); // remove loader
Expand Down
99 changes: 99 additions & 0 deletions views/json/advanced_statistics/admin/content/active_groups.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

use Elgg\Database\Select;

$result = [
'options' => advanced_statistics_get_default_chart_options('bar'),
];

$searchable_subtypes = elgg_extract('object', elgg_entity_types_with_capability('searchable'), []);
$key = array_search('comment', $searchable_subtypes);
if ($key !== false) {
unset($searchable_subtypes[$key]);
}

$qb = Select::fromTable('entities', 'e');
$qb->select('e.guid');
$qb->addSelect('count(*) AS total');
$qb->join('e', 'entities', 'e2', 'e2.container_guid = e.guid');
$qb->where("e.type = 'group'");
$qb->andWhere($qb->compare('e2.subtype', 'IN', $searchable_subtypes, ELGG_VALUE_STRING));
$qb->groupBy('e.guid');
$qb->orderBy('total', 'desc');
$qb->setMaxResults(10);

$ts_limit = advanced_statistics_get_timestamp_query_part('e2.time_created');
if ($ts_limit) {
$qb->andWhere($ts_limit);
}

$query_result = array_reverse($qb->execute()->fetchAllAssociative()); // we want to show from large to small

$groups = [];
foreach ($query_result as $row) {
$groups[$row['guid']] = get_entity($row['guid'])->getDisplayName();
}

$data = [];
if ($query_result) {
$series = [];
foreach ($searchable_subtypes as $subtype) {
$serie = [];

$qb = Select::fromTable('entities', 'e');
$qb->select('e.container_guid');
$qb->addSelect('count(*) AS total');
$qb->where($qb->compare('e.container_guid', 'IN', array_keys($groups), ELGG_VALUE_GUID));
$qb->andWhere($qb->compare('e.type', '=', 'object', ELGG_VALUE_STRING));
$qb->andWhere($qb->compare('e.subtype', '=', $subtype, ELGG_VALUE_STRING));
$qb->groupBy('e.container_guid');

$container_values = [];
$container_results = $qb->execute()->fetchAllAssociative();
if (empty($container_results)) {
continue;
}

$series[] = ['label' => elgg_echo("collection:object:{$subtype}")];

foreach ($container_results as $container_row) {
$container_values[$container_row['container_guid']] = $container_row['total'];
}

// set in correct order
foreach ($groups as $group_guid => $group_name) {
$serie[] = elgg_extract($group_guid, $container_values, 0);
}

$data[] = $serie;
}
}

$result['data'] = $data;

$result['options']['stackSeries'] = true;
$result['options']['seriesDefaults']['rendererOptions'] = [
'barDirection' => 'horizontal',
];

$result['options']['seriesDefaults']['pointLabels'] = [
'show' => true,
'hideZeros' => true,
'formatString' => '%d',
];

$result['options']['highlighter'] = [
'show' => false
];
$result['options']['legend'] = [
'show' => true,
'location' => 'e',
];
$result['options']['series'] = $series;

$result['options']['axes']['xaxis']['tickRenderer'] = '$.jqplot.CategoryAxisTickRenderer';
$result['options']['axes']['xaxis']['renderer'] = '$.jqplot.LinearAxisRenderer';
$result['options']['axes']['yaxis']['renderer'] = '$.jqplot.CategoryAxisRenderer';
$result['options']['axes']['yaxis']['ticks'] = array_values($groups);

echo json_encode($result);
60 changes: 60 additions & 0 deletions views/json/advanced_statistics/admin/content/commenting_groups.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

use Elgg\Database\Select;

$result = [
'options' => advanced_statistics_get_default_chart_options('bar'),
];

$searchable_subtypes = elgg_extract('object', elgg_entity_types_with_capability('searchable'), []);
$key = array_search('comment', $searchable_subtypes);
if ($key !== false) {
unset($searchable_subtypes[$key]);
}

$qb = Select::fromTable('entities', 'e');
$qb->select('ge.guid');
$qb->addSelect('count(*) AS total');
$qb->join('e', 'entities', 'e2', 'e.container_guid = e2.guid');
$qb->join('e2', 'entities', 'ge', 'e2.container_guid = ge.guid');
$qb->where($qb->compare('ge.type', '=', 'group', ELGG_VALUE_STRING));
$qb->andWhere($qb->compare('e.subtype', '=', 'comment', ELGG_VALUE_STRING));
$qb->groupBy('ge.guid');
$qb->orderBy('total', 'desc');
$qb->setMaxResults(10);

$ts_limit = advanced_statistics_get_timestamp_query_part('e.time_created');
if ($ts_limit) {
$qb->andWhere($ts_limit);
}

$query_result = array_reverse($qb->execute()->fetchAllAssociative()); // we want to show from large to small

$data = [];
if ($query_result) {
foreach ($query_result as $row) {
$data[] = [
$row['total'],
get_entity($row['guid'])->getDisplayName(),
];
}
}

$result['data'] = [$data];

$result['options']['seriesDefaults']['rendererOptions'] = [
'barDirection' => 'horizontal',
];

$result['options']['seriesDefaults']['pointLabels'] = [
'show' => false,
];

$result['options']['highlighter'] = [
'show' => false
];

$result['options']['axes']['xaxis']['renderer'] = '$.jqplot.LinearAxisRenderer';
$result['options']['axes']['yaxis']['renderer'] = '$.jqplot.CategoryAxisRenderer';

echo json_encode($result);

0 comments on commit edf85a4

Please sign in to comment.