Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/undefined notices #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function render_tab_viewtable() {
if ($sumofsiteswithplugins > 0) {

// Get all site records and the plugin counts from DB ordered by site name
$sql_sitesplugins = 'SELECT site.id, site.url, site.title, count(jointable.site)
$sql_sitesplugins = 'SELECT site.id, site.url, site.title, count(jointable.site) AS count
FROM {local_sitestats_sites} AS site
JOIN {local_sitestats_plugins_site} AS jointable
ON site.id = jointable.site
Expand All @@ -88,7 +88,7 @@ public function render_tab_viewtable() {
$result_sitesplugins = $DB->get_records_sql($sql_sitesplugins);

// Get all plugin records and the installation counts from DB ordered by installation count
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle)
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle) AS count
FROM {local_sitestats_plugins} AS pl
JOIN {local_sitestats_plugins_site} AS jointable
ON pl.id = jointable.plugin
Expand Down Expand Up @@ -298,7 +298,7 @@ public function render_tab_viewchart() {
if ($sumofsiteswithplugins > 0) {

// Get all site records and the plugin counts from DB ordered by site name
$sql_sites = 'SELECT site.id, site.url, site.title, count(jointable.site)
$sql_sites = 'SELECT site.id, site.url, site.title, count(jointable.site) AS count
FROM {local_sitestats_sites} AS site
JOIN {local_sitestats_plugins_site} AS jointable
ON site.id = jointable.site
Expand All @@ -307,7 +307,7 @@ public function render_tab_viewchart() {
$result_sites = $DB->get_records_sql($sql_sites);

// Get all plugin records and the installation counts from DB ordered by installation count
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle)
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle) AS count
FROM {local_sitestats_plugins} AS pl
JOIN {local_sitestats_plugins_site} AS jointable
ON pl.id = jointable.plugin
Expand Down Expand Up @@ -365,18 +365,27 @@ public function render_tab_viewchart() {
// Pick the plugin counts per site.
$pluginsusedpersiterawdata = array();
foreach ($result_sites as $s) {
if ($pluginsusedpersiterawdata[$s->count]) {
if (array_key_exists($s->count, $pluginsusedpersiterawdata)) {
$pluginsusedpersiterawdata[$s->count]++;
} else {
$pluginsusedpersiterawdata[$s->count] = 1;
};
}

$rangekey = 0;
$pluginsusedpersitedata = array();
$pluginsusedpersitelabels = array();
for ($j = 1; $j <= max(array_keys($pluginsusedpersiterawdata)); $j += 5) {
$pluginsusedpersitedata[] = $pluginsusedpersiterawdata[$j] + $pluginsusedpersiterawdata[$j + 1] +
$pluginsusedpersiterawdata[$j + 2] + $pluginsusedpersiterawdata[$j + 3] + $pluginsusedpersiterawdata[$j + 4];
$pluginsusedpersitelabels[] = get_string('chart_pluginusedpersiteaxis', 'local_sitestats', array('from' => $j, 'to' => ($j + 4)));
$pluginsusedpersitedata[$rangekey] = 0;

for ($i = 0; $i < 5; $i++) {
$pluginsusedpersitedata[$rangekey] += $pluginsusedpersiterawdata[$j + $i] ?? 0;
}

$pluginsusedpersitelabels[$rangekey] =
get_string('chart_pluginusedpersiteaxis', 'local_sitestats', ['from' => $j, 'to' => ($j + 4)]);

$rangekey++;
}

// Build chart heading.
Expand Down Expand Up @@ -485,7 +494,7 @@ public function render_tab_viewmetrics() {
if ($sumofsiteswithplugins > 0) {

// Get all site records and the plugin counts from DB ordered by site name
$sql_sites = 'SELECT site.id, site.url, site.title, count(jointable.site)
$sql_sites = 'SELECT site.id, site.url, site.title, count(jointable.site) AS count
FROM {local_sitestats_sites} AS site
JOIN {local_sitestats_plugins_site} AS jointable
ON site.id = jointable.site
Expand All @@ -494,7 +503,7 @@ public function render_tab_viewmetrics() {
$result_sites = $DB->get_records_sql($sql_sites);

// Get all plugin records and the installation counts from DB ordered by installation count
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle)
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle) AS count
FROM {local_sitestats_plugins} AS pl
JOIN {local_sitestats_plugins_site} AS jointable
ON pl.id = jointable.plugin
Expand Down