From dce5e8ff50305878a607a189ec90f9c1e71a911f Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 19 Mar 2015 17:39:56 -0500 Subject: [PATCH 1/7] Filter the user list in all courses in the session - refs BT#9590 --- main/admin/add_users_to_session.php | 20 ++++++++++++++++++++ main/inc/lib/sessionmanager.lib.php | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/main/admin/add_users_to_session.php b/main/admin/add_users_to_session.php index eb3df1100a..c0be27016a 100755 --- a/main/admin/add_users_to_session.php +++ b/main/admin/add_users_to_session.php @@ -22,6 +22,7 @@ $xajax->registerFunction('search_users'); $this_section = SECTION_PLATFORM_ADMIN; $id_session = intval($_GET['id_session']); +$sessionCoursesList = SessionManager::get_course_list_by_session_id($id_session); $addProcess = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null; @@ -365,6 +366,25 @@ if ($ajax_search) { foreach ($users as $user) { $sessionUsersList[$user['user_id']] = $user ; } + + $sessionUserInfo = SessionManager::getTotalUserCoursesInSession($id_session); + + // Filter the user list in all courses in the session + foreach ($sessionUserInfo as $sessionUser) { + // filter students in session + if ($sessionUser['status_in_session'] != 0) { + continue; + } + + if (!array_key_exists($sessionUser['user_id'], $sessionUsersList)) { + continue; + } + + if ($sessionUser['count'] != count($sessionCoursesList)) { + unset($sessionUsersList[$sessionUser['user_id']]); + } + } + unset($users); //clean to free memory } else { //Filter by Extra Fields diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 08d16f69a1..bd4333de55 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -5491,4 +5491,29 @@ class SessionManager ) )); } + + /** + * Get the count of user courses in session + * @param int $sessionId The session id + * @return array + */ + public static function getTotalUserCoursesInSession($sessionId) + { + $sql = "SELECT COUNT(1) as count, u.user_id, scu.status status_in_session, u.status user_status " + . "FROM session_rel_course_rel_user scu " + . "INNER JOIN user u ON scu.id_user = u.user_id " + . "WHERE scu.id_session = " . intval($sessionId) . " " + . "GROUP BY u.user_id"; + + $result = Database::query($sql); + + $list = array(); + + while ($data = Database::fetch_assoc($result)) { + $list[] = $data; + } + + return $list; + } + } From 8e2df9e6e5e131cc2168b563ee9f2d3b83fb3f17 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 20 Mar 2015 08:39:06 -0500 Subject: [PATCH 2/7] Update function to get count session courses - refs BT#9590 --- main/admin/add_users_to_session.php | 4 ++-- main/inc/lib/sessionmanager.lib.php | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/main/admin/add_users_to_session.php b/main/admin/add_users_to_session.php index c0be27016a..d4757a1ce9 100755 --- a/main/admin/add_users_to_session.php +++ b/main/admin/add_users_to_session.php @@ -22,7 +22,7 @@ $xajax->registerFunction('search_users'); $this_section = SECTION_PLATFORM_ADMIN; $id_session = intval($_GET['id_session']); -$sessionCoursesList = SessionManager::get_course_list_by_session_id($id_session); +$countSessionCoursesList = SessionManager::get_course_list_by_session_id($id_session, null, null, true); $addProcess = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null; @@ -380,7 +380,7 @@ if ($ajax_search) { continue; } - if ($sessionUser['count'] != count($sessionCoursesList)) { + if ($sessionUser['count'] != $countSessionCoursesList) { unset($sessionUsersList[$sessionUser['user_id']]); } } diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index bd4333de55..93360ccbcb 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -2983,15 +2983,22 @@ class SessionManager public static function get_course_list_by_session_id( $session_id, $course_name = '', - $orderBy = null + $orderBy = null, + $getCount = false ) { $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $session_id = intval($session_id); + $sqlSelect = "SELECT *"; + + if ($getCount) { + $sqlSelect = "SELECT COUNT(1)"; + } + // select the courses - $sql = "SELECT * FROM $tbl_course c + $sql = "$sqlSelect FROM $tbl_course c INNER JOIN $tbl_session_rel_course src ON c.code = src.course_code WHERE src.id_session = '$session_id' "; @@ -3017,6 +3024,12 @@ class SessionManager $num_rows = Database::num_rows($result); $courses = array(); if ($num_rows > 0) { + if ($getCount) { + $count = Database::fetch_array($result); + + return intval($count[0]); + } + while ($row = Database::fetch_array($result,'ASSOC')) { $courses[$row['id']] = $row; } From 2d70d4e201d838d4fc27afe713332b251113f0ae Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 20 Mar 2015 08:42:46 -0500 Subject: [PATCH 3/7] Minor - Update PHPDoc - refs BT#9590 --- main/inc/lib/sessionmanager.lib.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 93360ccbcb..3bd229f063 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -2975,10 +2975,12 @@ class SessionManager } /** - * Gets the list of courses by session filtered by access_url - * @param int $session_id - * @param string $course_name - * @return array list of courses + * Gets the list (or the count) of courses by session filtered by access_url + * @param int $session_id The session id + * @param string $course_name The course code + * @param string $orderBy Field to order the data + * @param boolean $getCount Optional. Count the session courses + * @return array|int List of courses. Whether $getCount is true, return the count */ public static function get_course_list_by_session_id( $session_id, From ada067400b2ab78857224b8be122b367ce76d49a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 23 Mar 2015 10:41:42 +0100 Subject: [PATCH 4/7] Fix condition. --- main/tracking/courseLog.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index bb48059ad2..2200f0ee11 100755 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -50,21 +50,28 @@ if (api_is_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)) { - $coursesFromSession = array_keys($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, $coursesFromSession)) { + 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 + // 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)) { From bb67d44625cdbc3cf2b680be0766e3e3aa5265a2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 23 Mar 2015 11:15:17 +0100 Subject: [PATCH 5/7] Drh can see this stats. --- main/attendance/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/attendance/index.php b/main/attendance/index.php index 20acba645a..cc55acefc1 100755 --- a/main/attendance/index.php +++ b/main/attendance/index.php @@ -332,7 +332,7 @@ switch ($action) { $attendanceController->attendance_calendar($action, $attendance_id, $calendar_id); break; case 'calendar_logins': - if (api_is_allowed_to_edit(null, true)) { + if (api_is_allowed_to_edit(null, true) || api_is_drh()) { $attendanceController->getAttendanceBaseInLogin(false, true); } break; From aced0a69779781a2cb7a3f32c392aba5e560b661 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 23 Mar 2015 11:23:35 +0100 Subject: [PATCH 6/7] Add attendance link see BT#9609 --- main/mySpace/course.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main/mySpace/course.php b/main/mySpace/course.php index f9b82e75d8..8f1cc9ef23 100755 --- a/main/mySpace/course.php +++ b/main/mySpace/course.php @@ -279,6 +279,12 @@ function get_courses($from, $limit, $column, $direction) $data['title'], $courseInfo['course_public_url'].'?id_session='.$sessionId ); + + $attendanceLink = Display::url( + Display::return_icon('attendance_list.png', get_lang('Attendance'), array(), ICON_SIZE_MEDIUM), + api_get_path(WEB_CODE_PATH).'attendance/index.php?cidReq='.$courseCode.'&id_session='.$sessionId.'&action=calendar_logins' + ); + $courseList[] = array( $title, $countStudents, @@ -288,6 +294,7 @@ function get_courses($from, $limit, $column, $direction) is_null($avgScoreInCourse) ? '-' : $avgScoreInCourse, is_null($messagesInCourse) ? '-' : $messagesInCourse, is_null($assignmentsInCourse) ? '-' : $assignmentsInCourse, + $attendanceLink, $courseIcon ); } @@ -313,7 +320,8 @@ $table->set_header(4, get_lang('AvgStudentsProgress').Display :: return_icon('in $table->set_header(5, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false); $table->set_header(6, get_lang('AvgMessages'), false); $table->set_header(7, get_lang('AvgAssignments'), false); -$table->set_header(8, get_lang('Details'), false); +$table->set_header(8, get_lang('Attendances'), false); +$table->set_header(9, get_lang('Details'), false); $form = new FormValidator('search_course', 'get', api_get_path(WEB_CODE_PATH).'mySpace/course.php'); $form->addElement('text', 'keyword', get_lang('Keyword')); From c4792482d5967f96de27eee4557828fe872243cd Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 23 Mar 2015 12:33:01 +0100 Subject: [PATCH 7/7] Add setting course_log_hide_columns default columns to hide see BT#9609 --- main/install/configuration.dist.php | 2 + main/tracking/courseLog.php | 88 ++++++++++++++++------------- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 00446e34a8..f089bfc497 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -293,3 +293,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE; //$_configuration['prevent_session_admins_to_manage_all_users'] = false; // Show delete option in attendance //$_configuration['allow_delete_attendance'] = false; +// Course log - Default columns to hide +//$_configuration['course_log_hide_columns'] = array(1, 9); diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index 2200f0ee11..abb705cd48 100755 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -100,6 +100,9 @@ if ($export_csv) { } ob_start(); } +$columnsToHideFromSetting = api_get_configuration_value('course_log_hide_columns'); +$columnsToHide = empty($columnsToHideFromSetting) ? array(1, 9, 10, 11, 12) : $columnsToHideFromSetting; +$columnsToHide = json_encode($columnsToHide); $csv_content = array(); // Scripts for reporting array hide/show columns @@ -130,14 +133,14 @@ $js = ""; @@ -184,9 +187,6 @@ if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') { $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : ''; $nameTools = get_lang('Tracking'); -// Display the header. -Display::display_header($nameTools, 'Tracking'); - // getting all the students of the course if (empty($session_id)) { // Registered students in a course outside session. @@ -224,6 +224,9 @@ if (isset($_GET['additional_profile_field']) && ); } +// Display the header. +Display::display_header($nameTools, 'Tracking'); + /* MAIN CODE */ echo '
'; @@ -366,7 +369,8 @@ if (count($a_students) > 0) { $el = $form->addElement( 'select', 'since', - ''.get_lang('RemindInactivesLearnersSince'), + ''. + get_lang('RemindInactivesLearnersSince'), $options ); $el->setSelected(7); @@ -404,78 +408,84 @@ if (count($a_students) > 0) { $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null; $table->set_additional_parameters($parameters); - $tab_table_header = array(); + $headers = array(); // tab of header texts $table->set_header(0, get_lang('OfficialCode'), true); - $tab_table_header[] = get_lang('OfficialCode'); + $headers['official_code'] = get_lang('OfficialCode'); if ($is_western_name_order) { $table->set_header(1, get_lang('FirstName'), true); - $tab_table_header[] = get_lang('FirstName'); + $headers['firstname'] = get_lang('FirstName'); $table->set_header(2, get_lang('LastName'), true); - $tab_table_header[] = get_lang('LastName'); + $headers['lastname'] = get_lang('LastName'); } else { $table->set_header(1, get_lang('LastName'), true); - $tab_table_header[] = get_lang('LastName'); + $headers['lastname'] = get_lang('LastName'); $table->set_header(2, get_lang('FirstName'), true); - $tab_table_header[] = get_lang('FirstName'); + $headers['firstname'] = get_lang('FirstName'); } $table->set_header(3, get_lang('Login'), false); - $tab_table_header[] = get_lang('Login'); + $headers['login'] = get_lang('Login'); $table->set_header(4, get_lang('TrainingTime').' '.Display::return_icon('info3.gif', get_lang('TrainingTimeInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;')); - $tab_table_header[] = get_lang('TrainingTime'); + $headers['training_time'] = get_lang('TrainingTime'); $table->set_header(5, get_lang('CourseProgress').' '.Display::return_icon('info3.gif', get_lang('ScormAndLPProgressTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;')); - $tab_table_header[] = get_lang('CourseProgress'); + $headers['course_progress'] = get_lang('CourseProgress'); $table->set_header(6, get_lang('ExerciseProgress').' '.Display::return_icon('info3.gif', get_lang('ExerciseProgressInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;')); - $tab_table_header[] = get_lang('ExerciseProgress'); + $headers['exercise_progress'] = get_lang('ExerciseProgress'); $table->set_header(7, get_lang('ExerciseAverage').' '.Display::return_icon('info3.gif', get_lang('ExerciseAverageInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;')); - $tab_table_header[] = get_lang('ExerciseAverage'); + $headers['exercise_average'] = get_lang('ExerciseAverage'); $table->set_header(8, get_lang('Score').' '.Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;')); - $tab_table_header[] = get_lang('Score'); + $headers['score'] = get_lang('Score'); $table->set_header(9, get_lang('Student_publication'), false); - $tab_table_header[] = get_lang('Student_publication'); + $headers['student_publication'] = get_lang('Student_publication'); $table->set_header(10, get_lang('Messages'), false); - $tab_table_header[] = get_lang('Messages'); + $headers['messages'] = get_lang('Messages'); if (empty($session_id)) { $table->set_header(11, get_lang('Survey'), false); - $tab_table_header[] = get_lang('Survey'); + $headers['survey'] = get_lang('Survey'); $table->set_header(12, get_lang('FirstLogin'), false); - $tab_table_header[] = get_lang('FirstLogin'); + $headers['first_login'] = get_lang('FirstLogin'); $table->set_header(13, get_lang('LatestLogin'), false); - $tab_table_header[] = get_lang('LatestLogin'); + $headers['latest_login'] = get_lang('LatestLogin'); if (isset($_GET['additional_profile_field']) and is_numeric($_GET['additional_profile_field'])) { $table->set_header(14, $extra_info['field_display_text'], false); - $tab_table_header[] = $extra_info['field_display_text']; + $headers['field_display_text'] = $extra_info['field_display_text']; $table->set_header(15, get_lang('Details'), false); - $tab_table_header[] = get_lang('Details'); + $headers['details'] = get_lang('Details'); } else { $table->set_header(14, get_lang('Details'), false); - $tab_table_header[] = get_lang('Details'); + $headers['details'] = get_lang('Details'); } - } else { $table->set_header(11, get_lang('FirstLogin'), false); - $tab_table_header[] = get_lang('FirstLogin'); + $headers['first_login'] = get_lang('FirstLogin'); $table->set_header(12, get_lang('LatestLogin'), false); - $tab_table_header[] = get_lang('LatestLogin'); + $headers['latest_login'] = get_lang('LatestLogin'); if (isset($_GET['additional_profile_field']) and is_numeric($_GET['additional_profile_field'])) { $table->set_header(13, $extra_info['field_display_text'], false); - $tab_table_header[] = $extra_info['field_display_text']; + $headers['field_display_text'] = $extra_info['field_display_text']; $table->set_header(14, get_lang('Details'), false); - $tab_table_header[] = get_lang('Details'); + $headers['Details'] = get_lang('Details'); } else { $table->set_header(13, get_lang('Details'), false); - $tab_table_header[] = get_lang('Details'); + $headers['Details'] = get_lang('Details'); } } // display buttons to un hide hidden columns echo "

"; - for ($i=0; $i < count($tab_table_header); $i++) { - $index = $i + 1; - echo "".Display :: return_icon('move.png', get_lang('DisplayColumn'), array('align'=>'absmiddle', 'hspace'=>'3px'), 16)." ".$tab_table_header[$i].""; + $index = 0; + foreach ($headers as $header) { + echo "". + Display :: return_icon( + 'move.png', + get_lang('DisplayColumn'), + array('align'=>'absmiddle', 'hspace'=>'3px'), + 16 + )." ".$header.""; + $index++; } echo "
"; // Display the table