Browse Source

Adding report to see diff between total course time and total LP time

- Check the course/course-session list users and shows a warning
if the total LP time is bigger than course time
- see BT#13552
Julio 7 years ago
parent
commit
96446928cc
2 changed files with 492 additions and 0 deletions
  1. 142 0
      main/inc/lib/tracking.lib.php
  2. 350 0
      main/tracking/total_time.php

+ 142 - 0
main/inc/lib/tracking.lib.php

@@ -7476,4 +7476,146 @@ class TrackingCourseLog
 
         return $users;
     }
+
+    /**
+     * Get data for users list in sortable with pagination
+     * @param $from
+     * @param $number_of_items
+     * @param $column
+     * @param $direction
+     * @param $includeInvitedUsers boolean Whether include the invited users
+     * @return array
+     */
+    public static function getTotalTimeReport(
+        $from,
+        $number_of_items,
+        $column,
+        $direction,
+        $includeInvitedUsers = false
+    ) {
+        global $user_ids, $course_code, $export_csv, $csv_content, $session_id;
+
+        $course_code = Database::escape_string($course_code);
+        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+        $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
+        $access_url_id = api_get_current_access_url_id();
+
+        // 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).") ";
+        } else {
+            $user_ids = intval($user_ids);
+            $condition_user = " WHERE user.user_id = $user_ids ";
+        }
+
+        $url_table = null;
+        $url_condition = null;
+        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'";
+        }
+
+        $invitedUsersCondition = '';
+        if (!$includeInvitedUsers) {
+            $invitedUsersCondition = " AND user.status != ".INVITEE;
+        }
+
+        $sql = "SELECT  user.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";
+
+        if (!in_array($direction, array('ASC', 'DESC'))) {
+            $direction = 'ASC';
+        }
+
+        $column = intval($column);
+        $from = intval($from);
+        $number_of_items = intval($number_of_items);
+
+        $sql .= " ORDER BY col$column $direction ";
+        $sql .= " LIMIT $from,$number_of_items";
+
+        $res = Database::query($sql);
+        $users = array();
+
+        $course_info = api_get_course_info($course_code);
+
+        while ($user = Database::fetch_array($res, 'ASSOC')) {
+            $courseInfo = api_get_course_info($course_code);
+            $courseId = $courseInfo['real_id'];
+
+            $user['official_code'] = $user['col0'];
+            $user['lastname'] = $user['col1'];
+            $user['firstname'] = $user['col2'];
+            $user['username'] = $user['col3'];
+
+            $totalCourseTime = Tracking::get_time_spent_on_the_course(
+                $user['user_id'],
+                $courseId,
+                $session_id
+            );
+
+            $user['time'] = api_time_to_hms($totalCourseTime);
+            $totalLpTime = Tracking::get_time_spent_in_lp(
+                $user['user_id'],
+                $course_code,
+                array(),
+                $session_id
+            );
+
+            $user['total_lp_time'] = $totalLpTime;
+            $warning = '';
+            if ($totalLpTime > $totalCourseTime) {
+                $warning = ' '.Display::label(get_lang('TimeDifference'), 'danger');
+            }
+
+            $user['total_lp_time'] = api_time_to_hms($totalLpTime).$warning;
+
+            $user['first_connection'] = Tracking::get_first_connection_date_on_the_course(
+                $user['user_id'],
+                $courseId,
+                $session_id
+            );
+            $user['last_connection'] = Tracking::get_last_connection_date_on_the_course(
+                $user['user_id'],
+                $courseInfo,
+                $session_id,
+                $export_csv === false
+            );
+
+            $user['link'] = '<center>
+                             <a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'">
+                             '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
+                             </a>
+                         </center>';
+
+            // store columns in array $users
+            $is_western_name_order = api_is_western_name_order();
+            $user_row = array();
+            $user_row['official_code'] = $user['official_code']; //0
+            if ($is_western_name_order) {
+                $user_row['firstname'] = $user['firstname'];
+                $user_row['lastname'] = $user['lastname'];
+            } else {
+                $user_row['lastname'] = $user['lastname'];
+                $user_row['firstname'] = $user['firstname'];
+            }
+            $user_row['username'] = $user['username'];
+            $user_row['time'] = $user['time'];
+            $user_row['total_lp_time'] = $user['total_lp_time'];
+            $user_row['first_connection'] = $user['first_connection'];
+            $user_row['last_connection'] = $user['last_connection'];
+
+            $user_row['link'] = $user['link'];
+            $users[] = array_values($user_row);
+        }
+
+        return $users;
+    }
+
 }

+ 350 - 0
main/tracking/total_time.php

@@ -0,0 +1,350 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+use ChamiloSession as Session;
+
+/**
+ * @package chamilo.tracking
+ */
+
+$pathopen = isset($_REQUEST['pathopen']) ? $_REQUEST['pathopen'] : null;
+
+// Including the global initialization file
+require_once __DIR__.'/../inc/global.inc.php';
+$current_course_tool = TOOL_TRACKING;
+
+$courseInfo = api_get_course_info(api_get_course_id());
+$courseCode = $courseInfo['code'];
+$from_myspace = false;
+$from = isset($_GET['from']) ? $_GET['from'] : null;
+
+// Starting the output buffering when we are exporting the information.
+$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
+$session_id = isset($_REQUEST['id_session']) ? intval($_REQUEST['id_session']) : 0;
+
+if ($from == 'myspace') {
+    $from_myspace = true;
+    $this_section = "session_my_space";
+} else {
+    $this_section = SECTION_COURSES;
+}
+
+// Access restrictions.
+$is_allowedToTrack =
+    api_is_platform_admin() ||
+    SessionManager::user_is_general_coach(api_get_user_id(), $session_id) ||
+    api_is_allowed_to_create_course() ||
+    api_is_session_admin() ||
+    api_is_drh() ||
+    api_is_course_tutor() ||
+    api_is_course_admin();
+
+if (!$is_allowedToTrack) {
+    api_not_allowed(true);
+    exit;
+}
+
+// If the user is a HR director (drh)
+if (api_is_drh()) {
+    // Blocking course for drh
+    if (api_drh_can_access_all_session_content()) {
+        // If the drh has been configured to be allowed to see all session content, give him access to the session courses
+        $coursesFromSession = SessionManager::getAllCoursesFollowedByUser(
+            api_get_user_id(),
+            null
+        );
+
+        $coursesFromSessionCodeList = array();
+        if (!empty($coursesFromSession)) {
+            foreach ($coursesFromSession as $course) {
+                $coursesFromSessionCodeList[$course['code']] = $course['code'];
+            }
+        }
+
+        $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
+
+        if (!empty($coursesFollowedList)) {
+            $coursesFollowedList = array_keys($coursesFollowedList);
+        }
+
+        if (!in_array($courseCode, $coursesFollowedList)) {
+            if (!in_array($courseCode, $coursesFromSessionCodeList)) {
+                api_not_allowed();
+            }
+        }
+    } else {
+        // If the drh has *not* been configured to be allowed to see all session content,
+        // 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(api_get_course_id(), $coursesFollowedList)) {
+            api_not_allowed(true);
+            exit;
+        }
+    }
+}
+
+if ($export_csv) {
+    if (!empty($session_id)) {
+        Session::write('id_session', $session_id);
+    }
+    ob_start();
+}
+$columnsToHideFromSetting = api_get_configuration_value('course_log_hide_columns');
+$columnsToHide = empty($columnsToHideFromSetting) ? array(0, 8, 9, 10, 11) : $columnsToHideFromSetting;
+$columnsToHide = json_encode($columnsToHide);
+
+$csv_content = array();
+// Database table definitions.
+//@todo remove this calls
+$TABLETRACK_DOWNLOADS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
+$TABLETRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
+$TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
+$TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
+$table_user = Database::get_main_table(TABLE_MAIN_USER);
+$TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
+
+$sessionId = api_get_session_id();
+
+// Breadcrumbs.
+if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
+    $interbreadcrumb[] = array(
+        'url' => '../admin/index.php',
+        'name' => get_lang('PlatformAdmin')
+    );
+    $interbreadcrumb[] = array(
+        'url' => '../session/session_list.php',
+        'name' => get_lang('SessionList')
+    );
+    $interbreadcrumb[] = array(
+        'url' => '../session/resume_session.php?id_session='.$sessionId,
+        'name' => get_lang('SessionOverview')
+    );
+}
+
+$view = isset($_REQUEST['view']) ? $_REQUEST['view'] : '';
+$nameTools = get_lang('Tracking');
+
+// getting all the students of the course
+if (empty($session_id)) {
+    // Registered students in a course outside session.
+    $a_students = CourseManager::get_student_list_from_course_code(
+        api_get_course_id()
+    );
+} else {
+    // Registered students in session.
+    $a_students = CourseManager::get_student_list_from_course_code(
+        api_get_course_id(),
+        true,
+        $sessionId
+    );
+}
+
+$nbStudents = count($a_students);
+
+// Display the header.
+Display::display_header($nameTools, 'Tracking');
+
+/* MAIN CODE */
+
+$actionsLeft = Display::return_icon(
+    'user_na.png',
+    get_lang('StudentsTracking'),
+    array(),
+    ICON_SIZE_MEDIUM
+);
+$actionsLeft .= Display::url(
+    Display::return_icon('group.png', get_lang('GroupReporting'), array(), ICON_SIZE_MEDIUM),
+    'course_log_groups.php?'.api_get_cidreq()
+);
+$actionsLeft .= Display::url(
+    Display::return_icon('course.png', get_lang('CourseTracking'), array(), ICON_SIZE_MEDIUM),
+    'course_log_tools.php?'.api_get_cidreq()
+);
+
+$actionsLeft .= Display::url(
+    Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), ICON_SIZE_MEDIUM),
+    'course_log_resources.php?'.api_get_cidreq()
+);
+$actionsLeft .= Display::url(
+    Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), ICON_SIZE_MEDIUM),
+    api_get_path(WEB_CODE_PATH).'tracking/exams.php?'.api_get_cidreq()
+);
+
+if (!empty($sessionId)) {
+    $actionsLeft .= Display::url(
+        Display::return_icon('attendance_list.png', get_lang('Logins'), '', ICON_SIZE_MEDIUM),
+        api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq().'&action=calendar_logins'
+    );
+}
+
+$actionsRight = '<div class="pull-right">';
+$actionsRight .= '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
+    Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
+
+$users_tracking_per_page = '';
+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&'.$users_tracking_per_page.'">
+     '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
+$actionsRight .= '</div>';
+// Create a search-box.
+$form_search = new FormValidator(
+    'search_simple',
+    'GET',
+    api_get_path(WEB_CODE_PATH).'tracking/total_time.php?'.api_get_cidreq(),
+    '',
+    array(),
+    FormValidator::LAYOUT_INLINE
+);
+$form_search->addElement('hidden', 'from', Security::remove_XSS($from));
+$form_search->addElement('hidden', 'session_id', $sessionId);
+$form_search->addElement('hidden', 'id_session', $sessionId);
+$form_search->addElement('text', 'user_keyword');
+$form_search->addButtonSearch(get_lang('SearchUsers'));
+echo Display::toolbarAction(
+    'toolbar-courselog',
+    [$actionsLeft, $form_search->returnForm(), $actionsRight]
+);
+
+$course_name = get_lang('Course').' '.$courseInfo['name'];
+if ($session_id) {
+    $titleSession = Display::return_icon(
+        'session.png',
+        get_lang('Session'),
+        array(),
+        ICON_SIZE_SMALL
+    ).' '.api_get_session_name($session_id);
+    $titleCourse = Display::return_icon(
+        'course.png',
+        get_lang('Course'),
+        array(),
+        ICON_SIZE_SMALL
+    ).' '.$course_name;
+} else {
+    $titleSession = Display::return_icon(
+        'course.png',
+        get_lang('Course'),
+        array(),
+        ICON_SIZE_SMALL
+    ).' '.$courseInfo['name'];
+}
+$teacherList = CourseManager::get_teacher_list_from_course_code_to_string(
+    $courseInfo['code'],
+    ',',
+    false,
+    true
+);
+
+$coaches = null;
+if (!empty($session_id)) {
+    $coaches = CourseManager::get_coachs_from_course_to_string(
+        $session_id,
+        $courseInfo['real_id'],
+        ',',
+        false,
+        true
+    );
+}
+$html = '';
+
+if (!empty($teacherList)) {
+    $html .= Display::page_subheader2(get_lang('Teachers'));
+    $html .= $teacherList;
+}
+
+if (!empty($coaches)) {
+    $html .= Display::page_subheader2(get_lang('Coaches'));
+    $html .= $coaches;
+}
+
+if (api_is_platform_admin(true) ||
+    api_is_session_general_coach()
+) {
+    $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
+
+    if (!empty($sessionList)) {
+        $html .= Display::page_subheader2(get_lang('SessionList'));
+        $icon = Display::return_icon(
+            'session.png',
+            null,
+            null,
+            ICON_SIZE_TINY
+        );
+
+        $html .= '<ul class="session-list">';
+        foreach ($sessionList as $session) {
+            $url = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='
+                .$session['id'].'&cidReq='.$courseInfo['code'];
+            $html .= Display::tag('li', $icon.' '.Display::url($session['name'], $url));
+        }
+        $html .= '</ul>';
+    }
+}
+
+$html .= Display::page_subheader2(get_lang('StudentList'));
+
+// PERSON_NAME_DATA_EXPORT is buggy
+$is_western_name_order = api_is_western_name_order();
+
+if (count($a_students) > 0) {
+
+    $all_datas = array();
+    $course_code = $_course['id'];
+    $user_ids = array_keys($a_students);
+
+    $table = new SortableTable(
+        'users_tracking',
+        array('TrackingCourseLog', 'get_number_of_users'),
+        array('TrackingCourseLog', 'getTotalTimeReport'),
+        (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
+    );
+
+    $parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']);
+    $parameters['id_session'] = $session_id;
+    $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
+
+    $table->set_additional_parameters($parameters);
+    $headers = array();
+    // tab of header texts
+    $table->set_header(0, get_lang('OfficialCode'), true);
+    $headers['official_code'] = get_lang('OfficialCode');
+    if ($is_western_name_order) {
+        $table->set_header(1, get_lang('FirstName'), true);
+        $headers['firstname'] = get_lang('FirstName');
+        $table->set_header(2, get_lang('LastName'), true);
+        $headers['lastname'] = get_lang('LastName');
+    } else {
+        $table->set_header(1, get_lang('LastName'), true);
+        $headers['lastname'] = get_lang('LastName');
+        $table->set_header(2, get_lang('FirstName'), true);
+        $headers['firstname'] = get_lang('FirstName');
+    }
+    $table->set_header(3, get_lang('Login'), false);
+    $headers['login'] = get_lang('Login');
+
+    $table->set_header(4, get_lang('TrainingTime').'&nbsp;'.
+        Display::return_icon('info3.gif', get_lang('CourseTimeInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
+    $headers['training_time'] = get_lang('TrainingTime');
+
+
+    $table->set_header(5, get_lang('TotalLPTime').'&nbsp;'.
+        Display::return_icon('info3.gif', get_lang('TotalLPTime'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
+    $headers['total_time_lp'] = get_lang('TotalLPTime');
+
+
+    $table->set_header(6, get_lang('FirstLoginInCourse'), false);
+    $headers['first_login'] = get_lang('FirstLoginInCourse');
+    $table->set_header(7, get_lang('LatestLoginInCourse'), false);
+    $headers['latest_login'] = get_lang('LatestLoginInCourse');
+
+    // Display the table
+    $html .= "<div id='reporting_table'>";
+    $html .= $table->return_table();
+    $html .= "</div>";
+} else {
+    $html .= Display::return_message(get_lang('NoUsersInCourse'), 'warning', true);
+}
+echo Display::panel($html, $titleSession);
+Display::display_footer();