Statistics - use entities

pull/3996/head
Julio 3 years ago
parent 833de2f2aa
commit b5a85d8684
  1. 40
      public/main/admin/statistics/index.php
  2. 26
      public/main/inc/ajax/statistics.ajax.php
  3. 24
      public/main/inc/lib/statistics.lib.php

@ -5,6 +5,9 @@
/**
* This tool show global Statistics on general platform events.
*/
use Chamilo\CoreBundle\Framework\Container;
$cidReset = true;
require_once __DIR__.'/../../inc/global.inc.php';
@ -130,7 +133,7 @@ in_array(
$form = new FormValidator('users_active', 'get', api_get_self().'?report=users_active');
$form->addDateRangePicker(
'daterange',
get_lang('DateRange'),
get_lang('Date range'),
true,
['format' => 'YYYY-MM-DD', 'timePicker' => 'false', 'validate_format' => 'Y-m-d']
);
@ -162,14 +165,14 @@ in_array(
cutoutPercentage: 25
';
$reportName1 = get_lang('UsersCreatedInTheSelectedPeriod');
$reportName2 = get_lang('UsersByStatus');
$reportName3 = get_lang('UsersByLanguage');
$reportName4 = get_lang('UsersByTargetLanguage');
$reportName5 = get_lang('UsersByCareer');
$reportName6 = get_lang('UsersByContract');
$reportName7 = get_lang('UsersByCertificate');
$reportName8 = get_lang('UsersByAge');
$reportName1 = get_lang('Users created in the selected period');
$reportName2 = get_lang('Users by status');
$reportName3 = get_lang('Users per language');
$reportName4 = get_lang('Users by target language');
$reportName5 = get_lang('Users by career');
$reportName6 = get_lang('Users by contract');
$reportName7 = get_lang('Users by certificate');
$reportName8 = get_lang('Users by age');
//$url1 = $urlBase.'a=users_active&filter=active&date_start='.$dateStart.'&date_end='.$dateEnd;
$url2 = $urlBase.'a=users_active&filter=status&date_start='.$dateStart.'&date_end='.$dateEnd;
@ -329,10 +332,10 @@ if (isset($_GET['export'])) {
$tool_name = get_lang('Statistics');
$tools = [
get_lang('Courses') => [
'report=courses' => get_lang('CountCours'),
'report=tools' => get_lang('PlatformToolAccess'),
'report=courselastvisit' => get_lang('LastAccess'),
'report=coursebylanguage' => get_lang('CountCourseByLanguage'),
'report=courses' => get_lang('Courses'),
'report=tools' => get_lang('Tools access'),
'report=courselastvisit' => get_lang('Latest access'),
'report=coursebylanguage' => get_lang('Number of courses by language'),
],
get_lang('Users') => [
'report=users' => get_lang('CountUsers'),
@ -342,7 +345,7 @@ $tools = [
'report=logins&type=hour' => get_lang('Logins').' ('.get_lang('PeriodHour').')',
'report=pictures' => get_lang('CountUsers').' ('.get_lang('UserPicture').')',
'report=logins_by_date' => get_lang('LoginsByDate'),
'report=no_login_users' => get_lang('StatsUsersDidNotLoginInLastPeriods'),
'report=no_login_users' => get_lang('Not logged in for some time'),
'report=zombies' => get_lang('Zombies'),
'report=users_active' => get_lang('UserStats'),
'report=users_online' => get_lang('UsersOnline'),
@ -361,7 +364,6 @@ $tools = [
],
];
$course_categories = Statistics::getCourseCategories();
$content = '';
switch ($report) {
@ -685,13 +687,15 @@ switch ($report) {
break;
case 'courses':
$courseCategoryRepo = Container::getCourseCategoryRepository();
$categories = $courseCategoryRepo->findAll();
$content .= '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
// total amount of courses
foreach ($course_categories as $code => $name) {
$courses[$name] = Statistics::countCourses($code);
foreach ($categories as $category) {
$courses[$category->getName()] = $category->getCourses()->count();
}
// courses for each course category
$content .= Statistics::printStats(get_lang('CountCours'), $courses);
$content .= Statistics::printStats(get_lang('Courses'), $courses);
break;
case 'tools':
$content .= '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\CoreBundle\Framework\Container;
/**
* Responses to AJAX calls.
@ -170,12 +171,13 @@ switch ($action) {
$statsName = 'Tools';
$all = Statistics::getToolsStats();
} elseif ('courses' == $action) {
$courseCategoryRepo = Container::getCourseCategoryRepository();
$categories = $courseCategoryRepo->findAll();
$statsName = 'CountCours';
$course_categories = Statistics::getCourseCategories();
// total amount of courses
$all = [];
foreach ($course_categories as $code => $name) {
$all[$name] = Statistics::countCourses($code);
foreach ($categories as $category) {
$all[$category->getName()] = $category->getCourses()->count();
}
} elseif ('courses_by_language' == $action) {
$statsName = 'CountCourseByLanguage';
@ -194,11 +196,14 @@ switch ($action) {
];
} elseif ('users_teachers' == $action) {
$statsName = 'Teachers';
$course_categories = Statistics::getCourseCategories();
$courseCategoryRepo = Container::getCourseCategoryRepository();
$categories = $courseCategoryRepo->findAll();
$countInvisible = isset($_GET['count_invisible']) ? (int) $_GET['count_invisible'] : null;
$all = [];
foreach ($course_categories as $code => $name) {
$name = str_replace(get_lang('Department'), "", $name);
foreach ($categories as $category) {
$code = $category->getCode();
$name = $category->getName();
$name = str_replace(get_lang('Department'), '', $name);
$all[$name] = Statistics::countUsers(COURSEMANAGER, $code, $countInvisible);
}
// use slightly different colors than previous chart
@ -208,11 +213,14 @@ switch ($action) {
}
} elseif ('users_students' == $action) {
$statsName = 'Students';
$course_categories = Statistics::getCourseCategories();
$courseCategoryRepo = Container::getCourseCategoryRepository();
$categories = $courseCategoryRepo->findAll();
$countInvisible = isset($_GET['count_invisible']) ? (int) $_GET['count_invisible'] : null;
$all = [];
foreach ($course_categories as $code => $name) {
$name = str_replace(get_lang('Department'), "", $name);
foreach ($categories as $category) {
$code = $category->getCode();
$name = $category->getName();
$name = str_replace(get_lang('Department'), '', $name);
$all[$name] = Statistics::countUsers(STUDENT, $code, $countInvisible);
}
// use slightly different colors than previous chart

@ -51,8 +51,8 @@ class Statistics
$categoryCondition = '';
if (!empty($categoryCode)) {
$categoryJoin = " LEFT JOIN $tblCourseCategory course_category ON course.category_id = course_category.id ";
$categoryCondition = " course_category.code = '".Database::escape_string($categoryCode)."' ";
//$categoryJoin = " LEFT JOIN $tblCourseCategory course_category ON course.category_id = course_category.id ";
//$categoryCondition = " course_category.code = '".Database::escape_string($categoryCode)."' ";
}
if (api_is_multiple_url_enabled()) {
@ -415,26 +415,6 @@ class Statistics
return $activities;
}
/**
* Get all course categories.
*
* @return array All course categories (code => name)
*/
public static function getCourseCategories()
{
$categoryTable = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT code, name
FROM $categoryTable
ORDER BY tree_pos";
$res = Database::query($sql);
$categories = [];
while ($category = Database::fetch_object($res)) {
$categories[$category->code] = $category->name;
}
return $categories;
}
/**
* Rescale data.
*

Loading…
Cancel
Save