Add group report in courseLog.php BT#17127

pull/3213/head
Julio Montoya 5 years ago
parent 7e728e2abe
commit 3a66ab0a05
  1. 70
      main/auth/courses.php
  2. 108
      main/inc/lib/extra_field.lib.php
  3. 16
      main/inc/lib/sortable_table.class.php
  4. 119
      main/inc/lib/tracking.lib.php
  5. 352
      main/tracking/courseLog.php

@ -258,72 +258,10 @@ switch ($action) {
} else {
$values = $_REQUEST;
if ($allowExtraFields) {
// Parse params.
foreach ($values as $key => $value) {
if (substr($key, 0, 6) !== 'extra_' && substr($key, 0, 7) !== '_extra_') {
continue;
}
if (!empty($value)) {
$fields[$key] = $value;
}
}
$extraFieldsAll = $extraField->get_all(
['visible_to_self = ? AND filter = ?' => [1, 1]],
'option_order'
);
$extraFieldsType = array_column($extraFieldsAll, 'field_type', 'variable');
$extraFields = array_column($extraFieldsAll, 'variable');
$filter = new stdClass();
foreach ($fields as $variable => $col) {
$variableNoExtra = str_replace('extra_', '', $variable);
if (isset($values[$variable]) && !empty($values[$variable]) &&
in_array($variableNoExtra, $extraFields)
) {
$rule = new stdClass();
$rule->field = $variable;
$rule->op = 'in';
$data = $col;
if (is_array($data) && array_key_exists($variable, $data)) {
$data = $col;
}
$rule->data = $data;
$filter->rules[] = $rule;
$filter->groupOp = 'AND';
if ($extraFieldsType[$variableNoExtra] == ExtraField::FIELD_TYPE_TAG) {
$tagElement = $form->getElement($variable);
$tags = [];
foreach ($values[$variable] as $tag) {
$tag = Security::remove_XSS($tag);
$tags[] = $tag;
$tagElement->addOption(
$tag,
$tag
);
}
$defaults[$variable] = $tags;
} else {
if (is_array($data)) {
$defaults[$variable] = array_map(['Security', 'remove_XSS'], $data);
} else {
$defaults[$variable] = Security::remove_XSS($data);
}
}
}
}
$result = $extraField->getExtraFieldRules($filter);
$conditionArray = $result['condition_array'];
$whereCondition = '';
$extraCondition = '';
if (!empty($conditionArray)) {
$extraCondition = ' ( ';
$extraCondition .= implode(' AND ', $conditionArray);
$extraCondition .= ' ) ';
}
$whereCondition .= $extraCondition;
$options = ['where' => $whereCondition, 'extra' => $result['extra_fields']];
$conditions = $extraField->parseConditions($options, 'course');
$extraResult = $extraField->processExtraFieldSearch($values, $form, 'course');
$conditions = $extraResult['condition'];
$fields = $extraResult['fields'];
$defaults = $extraResult['defaults'];
}
$courses = CoursesAndSessionsCatalog::searchAndSortCourses(

@ -531,19 +531,17 @@ class ExtraField extends Model
$extraData = false;
if (!empty($itemId)) {
$extraData = $this->get_handler_extra_data($itemId);
if ($form) {
if (!empty($showOnlyTheseFields)) {
$setData = [];
foreach ($showOnlyTheseFields as $variable) {
$extraName = 'extra_'.$variable;
if (in_array($extraName, array_keys($extraData))) {
$setData[$extraName] = $extraData[$extraName];
}
if (!empty($showOnlyTheseFields)) {
$setData = [];
foreach ($showOnlyTheseFields as $variable) {
$extraName = 'extra_'.$variable;
if (in_array($extraName, array_keys($extraData))) {
$setData[$extraName] = $extraData[$extraName];
}
$form->setDefaults($setData);
} else {
$form->setDefaults($extraData);
}
$form->setDefaults($setData);
} else {
$form->setDefaults($extraData);
}
}
@ -675,16 +673,16 @@ class ExtraField extends Model
}
/**
* @param string $field_type
* @param string $type
*
* @return array
*/
public function get_all_extra_field_by_type($field_type)
public function get_all_extra_field_by_type($type)
{
// all the information of the field
$sql = "SELECT * FROM {$this->table}
WHERE
field_type = '".Database::escape_string($field_type)."' AND
field_type = '".Database::escape_string($type)."' AND
extra_field_type = $this->extraFieldType
";
$result = Database::query($sql);
@ -2253,6 +2251,88 @@ JAVASCRIPT;
return $rules;
}
public function processExtraFieldSearch($values, $form, $alias)
{
// Parse params.
$fields = [];
foreach ($values as $key => $value) {
if (substr($key, 0, 6) !== 'extra_' && substr($key, 0, 7) !== '_extra_') {
continue;
}
if (!empty($value)) {
$fields[$key] = $value;
}
}
$extraFieldsAll = $this->get_all(
['visible_to_self = ? AND filter = ?' => [1, 1]],
'option_order'
);
$extraFieldsType = array_column($extraFieldsAll, 'field_type', 'variable');
$extraFields = array_column($extraFieldsAll, 'variable');
$filter = new stdClass();
$defaults = [];
foreach ($fields as $variable => $col) {
$variableNoExtra = str_replace('extra_', '', $variable);
if (isset($values[$variable]) && !empty($values[$variable]) &&
in_array($variableNoExtra, $extraFields)
) {
$rule = new stdClass();
$rule->field = $variable;
$rule->op = 'in';
$data = $col;
if (is_array($data) && array_key_exists($variable, $data)) {
$data = $col;
}
$rule->data = $data;
$filter->rules[] = $rule;
$filter->groupOp = 'AND';
if ($extraFieldsType[$variableNoExtra] == ExtraField::FIELD_TYPE_TAG) {
$tagElement = $form->getElement($variable);
$tags = [];
foreach ($values[$variable] as $tag) {
$tag = Security::remove_XSS($tag);
$tags[] = $tag;
$tagElement->addOption(
$tag,
$tag
);
}
$defaults[$variable] = $tags;
} else {
if (is_array($data)) {
$defaults[$variable] = array_map(['Security', 'remove_XSS'], $data);
} else {
$defaults[$variable] = Security::remove_XSS($data);
}
}
}
}
$result = $this->getExtraFieldRules($filter);
$conditionArray = $result['condition_array'];
$whereCondition = '';
$extraCondition = '';
if (!empty($conditionArray)) {
$extraCondition = ' ( ';
$extraCondition .= implode(' AND ', $conditionArray);
$extraCondition .= ' ) ';
}
$whereCondition .= $extraCondition;
$conditions = $this->parseConditions(
[
'where' => $whereCondition,
'extra' => $result['extra_fields'],
],
$alias
);
return ['condition' => $conditions, 'fields' => $fields, 'defaults' => $defaults];
}
/**
* @param array $options
*

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
@ -94,7 +95,6 @@ class SortableTable extends HTML_Table
public $table_id = null;
public $headers = [];
public $actionButtons = [];
/**
* The array containing all data for this table.
*/
@ -124,7 +124,7 @@ class SortableTable extends HTML_Table
* @param string $default_order_direction The default order direction;
* either the constant 'ASC' or 'DESC'
* @param string $table_id
* @param array $parameters They are custom attributes of the table
* @param array $attributes They are custom attributes of the table
*/
public function __construct(
$table_name = 'table',
@ -134,17 +134,20 @@ class SortableTable extends HTML_Table
$default_items_per_page = 20,
$default_order_direction = 'ASC',
$table_id = null,
$parameters = []
$attributes = []
) {
if (empty($table_id)) {
$table_id = $table_name.uniqid('table', true);
}
if (isset($parameters) && empty($parameters)) {
$parameters = ['class' => 'table table-bordered data_table', 'id' => $table_id];
if (empty($attributes)) {
$attributes = [];
$attributes['class'] = 'table table-bordered data_table';
$attributes['id'] = $table_id;
}
$this->table_id = $table_id;
parent::__construct($parameters);
parent::__construct($attributes);
$this->table_name = $table_name;
$this->additional_parameters = [];
$this->param_prefix = $table_name.'_';
@ -163,7 +166,6 @@ class SortableTable extends HTML_Table
}
// Allow to change paginate in multiples tabs
//Session::erase($this->param_prefix.'per_page');
$this->per_page = Session::read($this->param_prefix.'per_page', $default_items_per_page);
// If per page changed, then reset the page to 1

@ -15,8 +15,6 @@ use ExtraField as ExtraFieldModel;
* Class Tracking.
*
* @author Julio Montoya <gugli100@gmail.com>
*
* @package chamilo.library
*/
class Tracking
{
@ -1822,7 +1820,7 @@ class Tracking
*
* @param int $user_id
* @param int $courseId
* @param int Session id (optional)
* @param int $session_id
*
* @return int Time in seconds
*/
@ -1839,18 +1837,20 @@ class Tracking
if (self::minimumTimeAvailable($session_id, $courseId)) {
$courseTime = self::getCalculateTime($user_id, $courseId, $session_id);
$time = isset($courseTime['total_time']) ? $courseTime['total_time'] : 0;
return $time;
return isset($courseTime['total_time']) ? $courseTime['total_time'] : 0;
}
$conditionUser = '';
$session_id = (int) $session_id;
if (is_array($user_id)) {
$user_id = array_map('intval', $user_id);
$conditionUser = " AND user_id IN (".implode(',', $user_id).") ";
} else {
$user_id = (int) $user_id;
$conditionUser = " AND user_id = $user_id ";
if (!empty($user_id)) {
$user_id = (int) $user_id;
$conditionUser = " AND user_id = $user_id ";
}
}
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
@ -1866,6 +1866,7 @@ class Tracking
}
$sql .= $conditionUser;
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
@ -5916,7 +5917,6 @@ class Tracking
$count = 0;
foreach ($exercise_result as $result) {
$percentage = $result * 100;
//echo $percentage.' - '.$min.' - '.$max."<br />";
if ($percentage >= $min && $percentage <= $max) {
//echo ' is > ';
$count++;
@ -7520,21 +7520,23 @@ class TrackingCourseLog
*
* @return int
*/
public static function get_number_of_users()
public static function get_number_of_users($conditions)
{
global $user_ids;
$conditions['get_count'] = true;
return self::get_user_data(null, null, null, null, $conditions);
return count($user_ids);
//return count($user_ids);
}
/**
* Get data for users list in sortable with pagination.
*
* @param $from
* @param $number_of_items
* @param int $from
* @param int $number_of_items
* @param $column
* @param $direction
* @param $includeInvitedUsers boolean Whether include the invited users
* @param $conditions
*
* @return array
*/
@ -7543,9 +7545,11 @@ class TrackingCourseLog
$number_of_items,
$column,
$direction,
$includeInvitedUsers = false
$conditions = []
) {
global $user_ids, $course_code, $export_csv, $session_id;
$includeInvitedUsers = $conditions['include_invited_users']; // include the invited users
$getCount = isset($conditions['get_count']) ? $conditions['get_count'] : false;
$csv_content = [];
$course_code = Database::escape_string($course_code);
@ -7556,10 +7560,10 @@ class TrackingCourseLog
// get all users data from a course for sortable with limit
if (is_array($user_ids)) {
$user_ids = array_map('intval', $user_ids);
$condition_user = " WHERE user.user_id IN (".implode(',', $user_ids).") ";
$condition_user = " WHERE user.id IN (".implode(',', $user_ids).") ";
} else {
$user_ids = (int) $user_ids;
$condition_user = " WHERE user.user_id = $user_ids ";
$condition_user = " WHERE user.id = $user_ids ";
}
if (!empty($_GET['user_keyword'])) {
@ -7572,11 +7576,11 @@ class TrackingCourseLog
) ";
}
$url_table = null;
$url_condition = null;
$url_table = '';
$url_condition = '';
if (api_is_multiple_url_enabled()) {
$url_table = ", $tbl_url_rel_user as url_users";
$url_condition = " AND user.user_id = url_users.user_id AND access_url_id = '$access_url_id'";
$url_table = " INNER JOIN $tbl_url_rel_user as url_users ON (user.id = url_users.user_id)";
$url_condition = " AND access_url_id = '$access_url_id'";
}
$invitedUsersCondition = '';
@ -7584,13 +7588,46 @@ class TrackingCourseLog
$invitedUsersCondition = " AND user.status != ".INVITEE;
}
$sql = "SELECT user.user_id as user_id,
$select = '
SELECT user.id as user_id,
user.official_code as col0,
user.lastname as col1,
user.firstname as col2,
user.username as col3
FROM $tbl_user as user $url_table
$condition_user $url_condition $invitedUsersCondition";
user.username as col3';
if ($getCount) {
$select = ' SELECT COUNT(distinct(user.id)';
}
$sqlInjectJoins = '';
$where = 'AND 1 = 1 ';
$sqlInjectWhere = '';
if (!empty($conditions)) {
if (isset($conditions['inject_joins'])) {
$sqlInjectJoins = $conditions['inject_joins'];
}
if (isset($conditions['where'])) {
$where = $conditions['where'];
}
if (isset($conditions['inject_where'])) {
$sqlInjectWhere = $conditions['inject_where'];
}
$injectExtraFields = !empty($conditions['inject_extra_fields']) ? $conditions['inject_extra_fields'] : 1;
$injectExtraFields = rtrim($injectExtraFields, ', ');
if (false === $getCount) {
$select .= " , $injectExtraFields";
}
}
$sql = "$select
FROM $tbl_user as user
$url_table
$sqlInjectJoins
$condition_user
$url_condition
$invitedUsersCondition
$where
$sqlInjectWhere
";
if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC';
@ -7600,6 +7637,13 @@ class TrackingCourseLog
$from = (int) $from;
$number_of_items = (int) $number_of_items;
if ($getCount) {
$res = Database::query($sql);
$row = Database::fetch_array($res);
return $row['count'];
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from, $number_of_items";
@ -7619,18 +7663,19 @@ class TrackingCourseLog
if (empty($session_id)) {
$survey_user_list = [];
$survey_list = SurveyManager::get_surveys($course_code, $session_id);
$total_surveys = count($survey_list);
foreach ($survey_list as $survey) {
$user_list = SurveyManager::get_people_who_filled_survey(
$survey['survey_id'],
false,
$course_info['real_id']
);
$surveyList = SurveyManager::get_surveys($course_code, $session_id);
if ($surveyList) {
$total_surveys = count($surveyList);
foreach ($surveyList as $survey) {
$user_list = SurveyManager::get_people_who_filled_survey(
$survey['survey_id'],
false,
$course_info['real_id']
);
foreach ($user_list as $user_id) {
isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id]++ : $survey_user_list[$user_id] = 1;
foreach ($user_list as $user_id) {
isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id]++ : $survey_user_list[$user_id] = 1;
}
}
}
}
@ -7645,7 +7690,6 @@ class TrackingCourseLog
while ($user = Database::fetch_array($res, 'ASSOC')) {
$user['official_code'] = $user['col0'];
$user['username'] = $user['col3'];
$user['time'] = api_time_to_hms(
Tracking::get_time_spent_on_the_course(
$user['user_id'],
@ -7782,6 +7826,7 @@ class TrackingCourseLog
// we need to display an additional profile field
if (isset($_GET['additional_profile_field'])) {
$data = Session::read('additional_user_profile_info');
$extraFieldInfo = Session::read('extra_field_info');
foreach ($_GET['additional_profile_field'] as $fieldId) {
if (isset($data[$fieldId]) && isset($data[$fieldId][$user['user_id']])) {

@ -1,20 +1,29 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use ChamiloSession as Session;
/**
* @package chamilo.tracking
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_TRACKING;
$courseId = api_get_course_id();
$courseInfo = api_get_course_info($courseId);
//keep course_code form as it is loaded (global) by the table's get_user_data
$course_code = $courseCode = $courseInfo['code'];
$courseInfo = api_get_course_info();
if (empty($courseInfo)) {
api_not_allowed(true);
}
$sessionId = api_get_session_id();
$is_allowedToTrack = Tracking::isAllowToTrack($sessionId);
if (!$is_allowedToTrack) {
api_not_allowed(true);
}
//keep course_code form as it is loaded (global) by the table's get_user_data
$courseCode = $courseInfo['code'];
$courseId = $courseInfo['real_id'];
// PERSON_NAME_DATA_EXPORT is buggy
$sortByFirstName = api_sort_by_first_name();
$from_myspace = false;
@ -33,12 +42,6 @@ if ($from === 'myspace') {
$this_section = 'session_my_space';
}
$is_allowedToTrack = Tracking::isAllowToTrack($sessionId);
if (!$is_allowedToTrack) {
api_not_allowed(true);
}
// If the user is a HR director (drh)
if (api_is_drh()) {
// Blocking course for drh
@ -67,7 +70,7 @@ if (api_is_drh()) {
// then check if he has also been given access to the corresponding courses
$coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
$coursesFollowedList = array_keys($coursesFollowedList);
if (!in_array($courseId, $coursesFollowedList)) {
if (!in_array($courseCode, $coursesFollowedList)) {
api_not_allowed(true);
}
}
@ -102,11 +105,11 @@ $js = "<script>
function(index) {
$(this).prepend(
'<div style=\"cursor:pointer\" onclick=\"foldup(' + index + ')\">".Display::return_icon(
'visible.png',
get_lang('HideColumn'),
['align' => 'absmiddle', 'hspace' => '3px'],
ICON_SIZE_SMALL
)."</div>'
'visible.png',
get_lang('HideColumn'),
['align' => 'absmiddle', 'hspace' => '3px'],
ICON_SIZE_SMALL
)."</div>'
);
}
);
@ -159,10 +162,10 @@ $tpl = new Template($nameTools);
// Getting all the students of the course
if (empty($sessionId)) {
// Registered students in a course outside session.
$studentList = CourseManager::get_student_list_from_course_code($courseId);
$studentList = CourseManager::get_student_list_from_course_code($courseCode);
} else {
// Registered students in session.
$studentList = CourseManager::get_student_list_from_course_code($courseId, true, $sessionId);
$studentList = CourseManager::get_student_list_from_course_code($courseCode, true, $sessionId);
}
$nbStudents = count($studentList);
@ -182,7 +185,6 @@ if (isset($_GET['additional_profile_field'])) {
$fieldId,
$user_array
);
$extra_info[$fieldId] = UserManager::get_extra_field_information($fieldId);
}
}
@ -210,7 +212,8 @@ if (isset($_GET['users_tracking_per_page'])) {
$users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
}
$actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$additionalParams.$users_tracking_per_page.'">
$actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq(
).'&export=csv&'.$additionalParams.$users_tracking_per_page.'">
'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsRight .= '</div>';
// Create a search-box.
@ -236,24 +239,24 @@ $course_name = get_lang('Course').' '.$courseInfo['name'];
if ($sessionId) {
$titleSession = Display::return_icon(
'session.png',
get_lang('Session'),
[],
ICON_SIZE_SMALL
).' '.api_get_session_name($sessionId);
'session.png',
get_lang('Session'),
[],
ICON_SIZE_SMALL
).' '.api_get_session_name($sessionId);
$titleCourse = Display::return_icon(
'course.png',
get_lang('Course'),
[],
ICON_SIZE_SMALL
).' '.$course_name;
'course.png',
get_lang('Course'),
[],
ICON_SIZE_SMALL
).' '.$course_name;
} else {
$titleSession = Display::return_icon(
'course.png',
get_lang('Course'),
[],
ICON_SIZE_SMALL
).' '.$courseInfo['name'];
'course.png',
get_lang('Course'),
[],
ICON_SIZE_SMALL
).' '.$courseInfo['name'];
}
$teacherList = CourseManager::getTeacherListFromCourseCodeToString(
@ -322,11 +325,69 @@ if ($showReporting) {
$trackingColumn = isset($_GET['users_tracking_column']) ? $_GET['users_tracking_column'] : null;
$trackingDirection = isset($_GET['users_tracking_direction']) ? $_GET['users_tracking_direction'] : null;
$hideReports = api_get_configuration_value('hide_course_report_graph');
$conditions = [];
$groupList = GroupManager::get_group_list(null, $courseInfo, 1);
$class = new UserGroup();
$options['where'] = [' usergroup.course_id = ? ' => $courseId];
$classes = $class->getUserGroupInCourse($options);
// Show the charts part only if there are students subscribed to this course/session
if ($nbStudents > 0) {
// Classes
$formClass = new FormValidator(
'classes',
'get',
api_get_self().'?'.api_get_cidreq().'&'.$additionalParams.$users_tracking_per_page
);
$formClass->addHidden('cidReq', $courseCode);
$formClass->addHidden('id_session', $sessionId);
$groupIdList = ['--'];
foreach ($classes as $class) {
$groupIdList[$class['id']] = $class['name'];
}
$formClass->addSelect('class_id', get_lang('Class'), $groupIdList);
$formClass->addButtonSearch(get_lang('Search'));
// Groups
$formGroup = new FormValidator(
'groups',
'get',
api_get_self().'?'.api_get_cidreq().'&'.$additionalParams.$users_tracking_per_page
);
$formGroup->addHidden('cidReq', $courseCode);
$formGroup->addHidden('id_session', $sessionId);
$groupIdList = ['--'];
foreach ($groupList as $group) {
$groupIdList[$group['id']] = $group['name'];
}
$formGroup->addSelect('group_id', get_lang('Group'), $groupIdList);
$formGroup->addButtonSearch(get_lang('Search'));
// Extra fields
$formExtraField = new FormValidator(
'extra_fields',
'get',
api_get_self().'?'.api_get_cidreq().'&'.$additionalParams.$users_tracking_per_page
);
$formExtraField->addHidden('cidReq', $courseCode);
$formExtraField->addHidden('id_session', $sessionId);
if (isset($_GET['additional_profile_field'])) {
foreach ($_GET['additional_profile_field'] as $fieldId) {
$fieldId = Security::remove_XSS($fieldId);
$formExtraField->addHidden('additional_profile_field[]', $fieldId);
$formGroup->addHidden('additional_profile_field[]', $fieldId);
$formClass->addHidden('additional_profile_field[]', $fieldId);
}
}
$extraField = new ExtraField('user');
$extraField->addElements($formExtraField);
$formExtraField->addButtonSearch(get_lang('Search'));
$numberStudentsCompletedLP = 0;
$averageStudentsTestScore = 0;
$scoresDistribution = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
@ -337,19 +398,51 @@ if ($nbStudents > 0) {
$category = Category::load(
null,
null,
$course_code,
$courseCode,
null,
null,
$sessionId
);
$conditions = [];
$fields = [];
if ($formClass->validate()) {
$classId = (int) $formClass->getSubmitValue('class_id');
if (!empty($classId)) {
$whereCondition = " AND gu.usergroup_id = $classId ";
$tableGroup = Database::get_main_table(TABLE_USERGROUP_REL_USER);
$joins = " INNER JOIN $tableGroup gu ON (user.id = gu.user_id) ";
$conditions = ['where' => $whereCondition, 'inject_joins' => $joins];
}
}
if ($formGroup->validate()) {
$groupId = (int) $formGroup->getSubmitValue('group_id');
if (!empty($groupId)) {
$whereCondition = " AND gu.group_id = $groupId ";
$tableGroup = Database::get_course_table(TABLE_GROUP_USER);
$joins = " INNER JOIN $tableGroup gu ON (user.id = gu.user_id) ";
$conditions = ['where' => $whereCondition, 'inject_joins' => $joins];
}
}
if ($formExtraField->validate()) {
$extraResult = $extraField->processExtraFieldSearch($_REQUEST, $formExtraField, 'user');
if (!empty($extraResult)) {
$conditions = $extraResult['condition'];
$fields = $extraResult['fields'];
}
}
if ($hideReports === false) {
$conditions['include_invited_users'] = false;
$usersTracking = TrackingCourseLog::get_user_data(
null,
$nbStudents,
$trackingColumn,
$trackingDirection,
false
$conditions
);
foreach ($usersTracking as $userTracking) {
$userInfo = api_get_user_info_from_username($userTracking[3]);
@ -397,7 +490,6 @@ if ($nbStudents > 0) {
$averageStudentsTestScore = round($averageStudentsTestScore / $nbStudents);
$colors = ChamiloApi::getColorPalette(true, true, 10);
$tpl->assign('chart_colors', json_encode($colors));
$tpl->assign('certificate_count', $certificateCount);
$tpl->assign('score_distribution', json_encode($scoresDistribution));
@ -414,6 +506,10 @@ if ($nbStudents > 0) {
$html .= Display::page_subheader2(get_lang('StudentList'));
if ($nbStudents > 0) {
$html .= $formClass->returnForm();
$html .= $formGroup->returnForm();
$html .= $formExtraField->returnForm();
$getLangXDays = get_lang('XDays');
$form = new FormValidator(
'reminder_form',
@ -441,17 +537,15 @@ if ($nbStudents > 0) {
['disable_js' => true, 'class' => 'col-sm-3']
);
$el->setSelected(7);
$form->addElement('hidden', 'action', 'add');
$form->addElement('hidden', 'remindallinactives', 'true');
$form->addElement('hidden', 'cidReq', $courseInfo['code']);
$form->addElement('hidden', 'id_session', api_get_session_id());
$form->addButtonSend(get_lang('SendNotification'));
$extra_field_select = TrackingCourseLog::display_additional_profile_fields();
if (!empty($extra_field_select)) {
$html .= $extra_field_select;
$extraFieldSelect = TrackingCourseLog::display_additional_profile_fields();
if (!empty($extraFieldSelect)) {
$html .= $extraFieldSelect;
}
$html .= $form->returnForm();
@ -470,22 +564,22 @@ if ($nbStudents > 0) {
'users_tracking'
);
} else {
$conditions['include_invited_users'] = true;
$table = new SortableTable(
'users_tracking',
['TrackingCourseLog', 'get_number_of_users'],
['TrackingCourseLog', 'get_user_data'],
1
1,
20
);
$table->setDataFunctionParams($conditions);
}
$table->total_number_of_items = $nbStudents;
$parameters['cidReq'] = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
$parameters['id_session'] = $sessionId;
$parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
$table->set_additional_parameters($parameters);
$headers = [];
// tab of header texts
$table->set_header(0, get_lang('OfficialCode'), true);
@ -512,7 +606,9 @@ if ($nbStudents > 0) {
['style' => 'width:110px;']
);
$headers['training_time'] = get_lang('TrainingTime');
$table->set_header(5, get_lang('CourseProgress').'&nbsp;'.
$table->set_header(
5,
get_lang('CourseProgress').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('ScormAndLPProgressTotalAverage'),
@ -523,7 +619,9 @@ if ($nbStudents > 0) {
);
$headers['course_progress'] = get_lang('CourseProgress');
$table->set_header(6, get_lang('ExerciseProgress').'&nbsp;'.
$table->set_header(
6,
get_lang('ExerciseProgress').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('ExerciseProgressInfo'),
@ -533,13 +631,17 @@ if ($nbStudents > 0) {
['style' => 'width:110px;']
);
$headers['exercise_progress'] = get_lang('ExerciseProgress');
$table->set_header(7, get_lang('ExerciseAverage').'&nbsp;'.
$table->set_header(
7,
get_lang('ExerciseAverage').'&nbsp;'.
Display::return_icon('info3.gif', get_lang('ExerciseAverageInfo'), ['align' => 'absmiddle', 'hspace' => '3px']),
false,
['style' => 'width:110px;']
);
$headers['exercise_average'] = get_lang('ExerciseAverage');
$table->set_header(8, get_lang('Score').'&nbsp;'.
$table->set_header(
8,
get_lang('Score').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('ScormAndLPTestTotalAverage'),
@ -573,6 +675,7 @@ if ($nbStudents > 0) {
$table->set_header($counter, $extra_info[$fieldId]['display_text'], false);
$headers[$extra_info[$fieldId]['variable']] = $extra_info[$fieldId]['display_text'];
$counter++;
$parameters['additional_profile_field'] = $fieldId;
}
$table->set_header($counter, get_lang('Details'), false);
$headers['details'] = get_lang('Details');
@ -580,6 +683,17 @@ if ($nbStudents > 0) {
$table->set_header(15, get_lang('Details'), false);
$headers['Details'] = get_lang('Details');
}
if (!empty($fields)) {
foreach ($fields as $key => $value) {
$key = Security::remove_XSS($key);
$value = Security::remove_XSS($value);
$parameters[$key] = $value;
}
}
$parameters['cidReq'] = $courseCode;
$parameters['id_session'] = $sessionId;
$table->set_additional_parameters($parameters);
// display buttons to un hide hidden columns
$html .= '<div id="unhideButtons" class="btn-toolbar">';
$index = 0;
@ -607,8 +721,136 @@ if ($nbStudents > 0) {
$html .= Display::return_message(get_lang('NoUsersInCourse'), 'warning', true);
}
$groupContent = '';
echo Display::panel($html, $titleSession);
if (!empty($groupList)) {
$groupTable = new HTML_Table(['class' => 'table data_table']);
$column = 0;
$groupTable->setHeaderContents(0, $column++, get_lang('Name'));
$groupTable->setHeaderContents(0, $column++, get_lang('TrainingTime'));
$groupTable->setHeaderContents(0, $column++, get_lang('AverageTrainingTime'));
$groupTable->setHeaderContents(0, $column++, get_lang('CourseProgress'));
$groupTable->setHeaderContents(0, $column++, get_lang('ExerciseAverage'));
$row = 1;
$exerciseList = ExerciseLib::get_all_exercises(
$courseInfo,
$sessionId,
false,
null,
false,
3
);
$totalTime = null;
$totalLpProgress = null;
$totalScore = null;
$totalAverageTime = null;
$totalBestScoreAverageNotInLP = null;
foreach ($groupList as $groupInfo) {
$column = 0;
$groupTable->setCellContents($row, $column++, $groupInfo['name']);
$usersInGroup = GroupManager::getStudents($groupInfo['iid']);
$time = null;
$lpProgress = null;
$score = null;
$averageTime = null;
$bestScoreAverageNotInLP = null;
if (!empty($usersInGroup)) {
$usersInGroup = array_column($usersInGroup, 'user_id');
$userInGroupCount = count($usersInGroup);
$timeInSeconds = Tracking::get_time_spent_on_the_course(
$usersInGroup,
$courseId,
$sessionId
);
$totalTime += $timeInSeconds;
if (!empty($timeInSeconds)) {
$time = api_time_to_hms($timeInSeconds);
$averageTime = $timeInSeconds / $userInGroupCount;
$totalAverageTime += $averageTime;
$averageTime = api_time_to_hms($averageTime);
}
$lpProgress = Tracking::get_avg_student_progress(
$usersInGroup,
$courseCode,
[],
$sessionId,
true
);
if (empty($lpProgress)) {
$lpProgress = '';
} else {
$lpProgress = $lpProgress[0] / $userInGroupCount;
$totalLpProgress += $lpProgress;
}
if (!empty($exerciseList)) {
foreach ($exerciseList as $exerciseData) {
foreach ($usersInGroup as $userId) {
$results = Event::get_best_exercise_results_by_user(
$exerciseData['id'],
$courseInfo['real_id'],
0,
$userId
);
$best = 0;
if (!empty($results)) {
foreach ($results as $result) {
if (!empty($result['exe_weighting'])) {
$score = $result['exe_result'] / $result['exe_weighting'];
if ($score > $best) {
$best = $score;
}
}
}
}
$bestScoreAverageNotInLP += $best;
}
}
$bestScoreAverageNotInLP = round(
$bestScoreAverageNotInLP / count($exerciseList) * 100 / $userInGroupCount,
2
);
$totalBestScoreAverageNotInLP += $bestScoreAverageNotInLP;
}
if (empty($score)) {
$score = '';
}
if (empty($lpProgress)) {
$lpProgress = '';
}
if (empty($bestScoreAverageNotInLP)) {
$bestScoreAverageNotInLP = '';
}
}
$groupTable->setCellContents($row, $column++, $time);
$groupTable->setCellContents($row, $column++, $averageTime);
$groupTable->setCellContents($row, $column++, $lpProgress);
$groupTable->setCellContents($row, $column++, $bestScoreAverageNotInLP);
$row++;
}
$column = 0;
$totalTime = api_time_to_hms($totalTime);
$totalAverageTime = api_time_to_hms($totalAverageTime);
$groupTable->setCellContents($row, $column++, get_lang('Total'));
$groupTable->setCellContents($row, $column++, $totalTime);
$groupTable->setCellContents($row, $column++, $totalAverageTime);
$groupTable->setCellContents($row, $column++, $totalLpProgress);
$groupTable->setCellContents($row, $column++, $totalBestScoreAverageNotInLP);
echo Display::panel($groupTable->toHtml(), '');
}
// Send the csv file if asked.
if ($export_csv) {
$csv_headers = [];

Loading…
Cancel
Save