/** * * @global moodle_database $DB */ function local_hub_stats_top_10_countries() { global $DB; list($where, $params) = local_hub_stats_get_confirmed_sql(); $sql = 'SELECT r.countrycode, COUNT(DISTINCT r.id) AS countrycount FROM {hub_site_directory} r WHERE ' . $where . ' AND r.countrycode <> \'\' GROUP BY r.countrycode ORDER BY countrycount DESC LIMIT 10'; return $DB->get_records_sql($sql, $params); }
/** * * @global moodle_database $DB * @param string $countrycode * @return stdClass */ function get_sites_for_country($countrycode) { global $DB; list($where, $params) = local_hub_stats_get_confirmed_sql(null); $params['countrycode'] = $countrycode; $country = new stdClass(); $country->totalsites = $DB->count_records_select('hub_site_directory', "countrycode LIKE :countrycode AND {$where}", $params); $country->privatesites = $DB->count_records_select('hub_site_directory', "countrycode LIKE :countrycode AND privacy = 'notdisplayed' AND {$where}", $params); $country->publicsites = $country->totalsites - $country->privatesites; $country->sites = $DB->get_records_select('hub_site_directory', "countrycode LIKE :countrycode AND (privacy = 'named' or privacy = 'linked') AND {$where}", $params, 'name, url', 'id,name,url,countrycode,privacy,timeregistered,cool,contactable'); return $country; }
function moodle_users_per_site() { global $CFG, $DB; $graph = new google_charts_bar_graph(); $graph->set_chart_title("Moodle users per site comparison"); $graph->set_style(GOOGLE_CHARTS_BAR_VERTICAL_GROUPED); $graph->set_dimensions(800, 375); $graph->use_second_xlabel(); $filename = 'users_per_site.' . STATS_CACHE_FILE_NAME_ID . '.png'; if (!$graph->set_filename($filename)) { // There is an error setting the filename probably that we were unable // to create the stats directory in moodledata } if ($graph->check_if_graph_exists()) { return $graph; } $range = array(); $range[] = array('start' => 0, 'end' => 9); $range[] = array('start' => 10, 'end' => 99); $range[] = array('start' => 100, 'end' => 499); $range[] = array('start' => 500, 'end' => 999); $range[] = array('start' => 1000, 'end' => 4999); $range[] = array('start' => 5000, 'end' => 9999); $range[] = array('start' => 10000, 'end' => 19999); $range[] = array('start' => 20000, 'end' => 29999); $range[] = array('start' => 30000, 'end' => 39999); $range[] = array('start' => 40000, 'end' => 49999); $range[] = array('start' => 50000, 'end' => 99999); $range[] = array('start' => 100000, 'end' => 199999); $range[] = array('start' => 200000, 'end' => 299999); $range[] = array('start' => 300000, 'end' => 399999); $range[] = array('start' => 400000, 'end' => 499999); $range[] = array('start' => 500000, 'end' => 999999); $range[] = array('start' => 1000000, 'end' => 1999999); $graph->set_bar_limit(count($range) + 1); list($where, $params) = local_hub_stats_get_confirmed_sql(); $sql = "SELECT COUNT(id) sitecount\n FROM {hub_site_directory} r\n WHERE r.users > :start AND\n r.users <= :end AND\n {$where}"; $secondxlabelpos = ceil(count($range) / 2); $count = 0; $xlabelcount = count($range); $graph->overridelabelposition[] = 0; $graph->overridelabelposition[] = 0; foreach ($range as $key => $group) { $params['start'] = $group['start']; $params['end'] = $group['end']; $sitesizeresults = $DB->get_record_sql($sql, $params); $count++; $label = number_format($group['start']); $graph->overridelabelposition[] = round(100 / $xlabelcount * ($key + 1), 1); if ($key == count($range) - 1) { $label = array($label, number_format($group['end'] + 1)); #$graph->overridelabelposition[] = 100; } if ($secondxlabelpos == $count) { $graph->add_value(array($sitesizeresults->sitecount, $label, 'Users')); } else { $graph->add_value(array($sitesizeresults->sitecount, $label)); } } return $graph; }