Merge branch 'MDL-68784' of https://github.com/Peterburnett/moodle
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user