From 996dd0b0b92995eaa26c8b3ff4748392b626ffd6 Mon Sep 17 00:00:00 2001 From: Peter Burnett Date: Wed, 20 May 2020 12:53:36 +1000 Subject: [PATCH] MDL-68784 scorm: Removed limit on allowed scorm users in report --- mod/scorm/report/basic/classes/report.php | 22 +++++----------- mod/scorm/report/graphs/classes/report.php | 25 ++++++------------- .../report/interactions/classes/report.php | 23 +++++------------ .../report/objectives/classes/report.php | 23 +++++------------ 4 files changed, 25 insertions(+), 68 deletions(-) diff --git a/mod/scorm/report/basic/classes/report.php b/mod/scorm/report/basic/classes/report.php index 5c1cfb33c0d..d5f1285c095 100644 --- a/mod/scorm/report/basic/classes/report.php +++ b/mod/scorm/report/basic/classes/report.php @@ -81,27 +81,19 @@ class report extends \mod_scorm\report { && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO); // Select the students. $nostudents = false; - + list($allowedlistsql, $params) = get_enrolled_sql($contextmodule, 'mod/scorm:savetrack', (int) $currentgroup); if (empty($currentgroup)) { // All users who can attempt scoes. - if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false)) { + if (!$DB->record_exists_sql($allowedlistsql, $params)) { echo $OUTPUT->notification(get_string('nostudentsyet')); $nostudents = true; - $allowedlist = ''; - } else { - $allowedlist = array_keys($students); } - unset($students); } else { // All users who can attempt scoes and who are in the currently selected group. - if (!$groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', - $currentgroup, '', false)) { + if (!$DB->record_exists_sql($allowedlistsql, $params)) { echo $OUTPUT->notification(get_string('nostudentsingroup')); $nostudents = true; - $groupstudents = array(); } - $allowedlist = array_keys($groupstudents); - unset($groupstudents); } if ( !$nostudents ) { @@ -273,8 +265,6 @@ class report extends \mod_scorm\report { $csvexport->set_filename($filename, ".txt"); $csvexport->add_data($headers); } - $params = array(); - list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED); // Construct the SQL. $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . @@ -287,15 +277,15 @@ class report extends \mod_scorm\report { switch ($attemptsmode) { case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH: // Show only students with attempts. - $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NOT NULL"; break; case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO: // Show only students without attempts. - $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NULL"; break; case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS: // Show all students with or without attempts. - $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND (st.userid IS NOT NULL OR st.userid IS NULL)"; break; } diff --git a/mod/scorm/report/graphs/classes/report.php b/mod/scorm/report/graphs/classes/report.php index 4971d5c366d..6fa46f73cdc 100644 --- a/mod/scorm/report/graphs/classes/report.php +++ b/mod/scorm/report/graphs/classes/report.php @@ -50,18 +50,15 @@ class report extends \mod_scorm\report { * Get the data for the report. * * @param int $scoid The sco ID. - * @param array $allowedlist The list of user IDs allowed to be displayed. + * @param array $allowedlist The SQL and params to get the userlist. * @return array of data indexed per bar. */ - protected function get_data($scoid, $allowedlist = []) { + protected function get_data($scoid, $allowedlistsql) { global $DB; $data = array_fill(0, self::BANDS, 0); - if (empty($allowedlist)) { - return $data; - } - list($usql, $params) = $DB->get_in_or_equal($allowedlist); - $params[] = $scoid; + list($allowedlist, $params) = $allowedlistsql; + $params = array_merge($params, ['scoid' => $scoid]); // Construct the SQL. $sql = "SELECT DISTINCT " . $DB->sql_concat('st.userid', '\'#\'', 'COALESCE(st.attempt, 0)') . " AS uniqueid, @@ -70,7 +67,7 @@ class report extends \mod_scorm\report { st.attempt AS attempt, st.scoid AS scoid FROM {scorm_scoes_track} st - WHERE st.userid $usql AND st.scoid = ?"; + WHERE st.userid IN ({$allowedlistsql}) AND st.scoid = :scoid"; $attempts = $DB->get_records_sql($sql, $params); $usergrades = []; @@ -144,15 +141,7 @@ class report extends \mod_scorm\report { // Find out current restriction. $group = groups_get_activity_group($cm, true); - if (empty($group)) { - // All users who can attempt scoes. - $students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id' , '', '', '', '', '', false); - $allowedlist = empty($students) ? array() : array_keys($students); - } else { - // All users who can attempt scoes and who are in the currently selected group. - $groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $group, '', false); - $allowedlist = empty($groupstudents) ? array() : array_keys($groupstudents); - } + $allowedlistsql = get_enrolled_sql($contextmodule, 'mod/scorm:savetrack', (int) $group); // Labels. $labels = [get_string('invaliddata', 'scormreport_graphs')]; @@ -164,7 +153,7 @@ class report extends \mod_scorm\report { foreach ($scoes as $sco) { if ($sco->launch != '') { - $data = $this->get_data($sco->id, $allowedlist); + $data = $this->get_data($sco->id, $allowedlistsql); $series = new chart_series($sco->title, $data); $chart = new chart_bar(); diff --git a/mod/scorm/report/interactions/classes/report.php b/mod/scorm/report/interactions/classes/report.php index 1deef30b7d5..1bc5afbda20 100644 --- a/mod/scorm/report/interactions/classes/report.php +++ b/mod/scorm/report/interactions/classes/report.php @@ -98,28 +98,19 @@ class report extends \mod_scorm\report { && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO); // Select the students. $nostudents = false; - + list($allowedlistsql, $params) = get_enrolled_sql($contextmodule, 'mod/scorm:savetrack', (int) $currentgroup); if (empty($currentgroup)) { // All users who can attempt scoes. - if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false)) { + if (!$DB->record_exists_sql($allowedlistsql, $params)) { echo $OUTPUT->notification(get_string('nostudentsyet')); $nostudents = true; - $allowedlist = ''; - } else { - $allowedlist = array_keys($students); } - unset($students); } else { // All users who can attempt scoes and who are in the currently selected group. - if (!$groupstudents = get_users_by_capability($contextmodule, - 'mod/scorm:savetrack', 'u.id', '', '', '', - $currentgroup, '', false)) { + if (!$DB->record_exists_sql($allowedlistsql, $params)) { echo $OUTPUT->notification(get_string('nostudentsingroup')); $nostudents = true; - $groupstudents = array(); } - $allowedlist = array_keys($groupstudents); - unset($groupstudents); } if ( !$nostudents ) { // Now check if asked download of data. @@ -163,8 +154,6 @@ class report extends \mod_scorm\report { } } - $params = array(); - list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED); // Construct the SQL. $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . @@ -177,15 +166,15 @@ class report extends \mod_scorm\report { switch ($attemptsmode) { case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH: // Show only students with attempts. - $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NOT NULL"; break; case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO: // Show only students without attempts. - $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NULL"; break; case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS: // Show all students with or without attempts. - $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND (st.userid IS NOT NULL OR st.userid IS NULL)"; break; } diff --git a/mod/scorm/report/objectives/classes/report.php b/mod/scorm/report/objectives/classes/report.php index 85488c7dde2..4e2ad624ed6 100644 --- a/mod/scorm/report/objectives/classes/report.php +++ b/mod/scorm/report/objectives/classes/report.php @@ -92,28 +92,19 @@ class report extends \mod_scorm\report { && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO); // Select the students. $nostudents = false; - + list($allowedlistsql, $params) = get_enrolled_sql($contextmodule, 'mod/scorm:savetrack', (int) $currentgroup); if (empty($currentgroup)) { // All users who can attempt scoes. - if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false)) { + if (!$DB->record_exists_sql($allowedlistsql, $params)) { echo $OUTPUT->notification(get_string('nostudentsyet')); $nostudents = true; - $allowedlist = ''; - } else { - $allowedlist = array_keys($students); } - unset($students); } else { // All users who can attempt scoes and who are in the currently selected group. - $groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', - 'u.id', '', '', '', $currentgroup, '', false); - if (!$groupstudents) { + if (!$DB->record_exists_sql($allowedlistsql, $params)) { echo $OUTPUT->notification(get_string('nostudentsingroup')); $nostudents = true; - $groupstudents = array(); } - $allowedlist = array_keys($groupstudents); - unset($groupstudents); } if ( !$nostudents ) { // Now check if asked download of data. @@ -157,8 +148,6 @@ class report extends \mod_scorm\report { } } - $params = array(); - list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED); // Construct the SQL. $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . @@ -171,15 +160,15 @@ class report extends \mod_scorm\report { switch ($attemptsmode) { case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH: // Show only students with attempts. - $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NOT NULL"; break; case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO: // Show only students without attempts. - $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND st.userid IS NULL"; break; case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS: // Show all students with or without attempts. - $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)'; + $where = " WHERE u.id IN ({$allowedlistsql}) AND (st.userid IS NOT NULL OR st.userid IS NULL)"; break; } -- 2.43.0