Skip to content

Commit

Permalink
Merge branch 'MDL-68784' of https://github.com/Peterburnett/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 7, 2020
2 parents d07fb8b + 91f26b5 commit e47c53a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 68 deletions.
22 changes: 6 additions & 16 deletions mod/scorm/report/basic/classes/report.php
Expand Up @@ -81,27 +81,19 @@ public function display($scorm, $cm, $course, $download) {
&& ($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 ) {
Expand Down Expand Up @@ -273,8 +265,6 @@ public function display($scorm, $cm, $course, $download) {
$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, ' .
Expand All @@ -287,15 +277,15 @@ public function display($scorm, $cm, $course, $download) {
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;
}

Expand Down
25 changes: 7 additions & 18 deletions mod/scorm/report/graphs/classes/report.php
Expand Up @@ -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,
Expand All @@ -70,7 +67,7 @@ protected function get_data($scoid, $allowedlist = []) {
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 = [];
Expand Down Expand Up @@ -144,15 +141,7 @@ public function display($scorm, $cm, $course, $download) {

// 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')];
Expand All @@ -164,7 +153,7 @@ public function display($scorm, $cm, $course, $download) {
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();
Expand Down
23 changes: 6 additions & 17 deletions mod/scorm/report/interactions/classes/report.php
Expand Up @@ -98,28 +98,19 @@ public function display($scorm, $cm, $course, $download) {
&& ($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.
Expand Down Expand Up @@ -163,8 +154,6 @@ public function display($scorm, $cm, $course, $download) {
}
}

$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, ' .
Expand All @@ -177,15 +166,15 @@ public function display($scorm, $cm, $course, $download) {
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;
}

Expand Down
23 changes: 6 additions & 17 deletions mod/scorm/report/objectives/classes/report.php
Expand Up @@ -92,28 +92,19 @@ public function display($scorm, $cm, $course, $download) {
&& ($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.
Expand Down Expand Up @@ -157,8 +148,6 @@ public function display($scorm, $cm, $course, $download) {
}
}

$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, ' .
Expand All @@ -171,15 +160,15 @@ public function display($scorm, $cm, $course, $download) {
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;
}

Expand Down

0 comments on commit e47c53a

Please sign in to comment.