first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,92 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for scormreport_basic.
*
* @package scormreport_basic
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_basic\privacy;
defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\writer;
/**
* Privacy Subsystem for scormreport_basic.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
// User preferences shared between different scorm reports.
$collection->add_user_preference('scorm_report_pagesize', 'privacy:metadata:preference:scorm_report_pagesize');
// User preferences specific for this scorm report.
$collection->add_user_preference('scorm_report_detailed', 'privacy:metadata:preference:scorm_report_detailed');
return $collection;
}
/**
* Store all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
static::get_and_export_user_preference($userid, 'scorm_report_pagesize');
static::get_and_export_user_preference($userid, 'scorm_report_detailed', true);
}
/**
* Get and export a user preference.
*
* @param int $userid The userid of the user whose data is to be exported.
* @param string $userpreference The user preference to export.
* @param boolean $transform If true, transform value to yesno.
*/
protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) {
$prefvalue = get_user_preferences($userpreference, null, $userid);
if ($prefvalue !== null) {
if ($transform) {
$transformedvalue = transform::yesno($prefvalue);
} else {
$transformedvalue = $prefvalue;
}
writer::export_user_preference(
'scormreport_basic',
$userpreference,
$transformedvalue,
get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_basic')
);
}
}
}
+524
View File
@@ -0,0 +1,524 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Core Report class of basic reporting plugin
* @package scormreport
* @subpackage basic
* @author Dan Marsden and Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_basic;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/csvlib.class.php');
class report extends \mod_scorm\report {
/**
* displays the full report
* @param \stdClass $scorm full SCORM object
* @param \stdClass $cm - full course_module object
* @param \stdClass $course - full course object
* @param string $download - type of download being requested
*/
public function display($scorm, $cm, $course, $download) {
global $CFG, $DB, $OUTPUT, $PAGE;
$contextmodule = \context_module::instance($cm->id);
$action = optional_param('action', '', PARAM_ALPHA);
$attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
$attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
$PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
// Scorm action bar for report.
if ($download === '') {
$actionbar = new \mod_scorm\output\actionbar($cm->id, true, $attemptsmode);
$renderer = $PAGE->get_renderer('mod_scorm');
echo $renderer->report_actionbar($actionbar);
}
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
}
}
// Find out current groups mode.
$currentgroup = groups_get_activity_group($cm, true);
// Detailed report.
$mform = new \mod_scorm_report_settings($PAGE->url, compact('currentgroup'));
if ($fromform = $mform->get_data()) {
$detailedrep = $fromform->detailedrep;
$pagesize = $fromform->pagesize;
set_user_preference('scorm_report_detailed', $detailedrep);
set_user_preference('scorm_report_pagesize', $pagesize);
} else {
$detailedrep = get_user_preferences('scorm_report_detailed', false);
$pagesize = get_user_preferences('scorm_report_pagesize', 0);
}
if ($pagesize < 1) {
$pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
}
// Select group menu.
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
if (!$download) {
groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions));
}
}
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
&& ($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 (!$DB->record_exists_sql($allowedlistsql, $params)) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
$nostudents = true;
}
} else {
// All users who can attempt scoes and who are in the currently selected group.
if (!$DB->record_exists_sql($allowedlistsql, $params)) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
$nostudents = true;
}
}
if ( !$nostudents ) {
// Now check if asked download of data.
$coursecontext = \context_course::instance($course->id);
if ($download) {
$shortname = format_string($course->shortname, true, array('context' => $coursecontext));
$filename = clean_filename("$shortname ".format_string($scorm->name, true));
}
// Define table columns.
$columns = array();
$headers = array();
if (!$download && $candelete) {
$columns[] = 'checkbox';
$headers[] = $this->generate_master_checkbox();
}
if (!$download && $CFG->grade_report_showuserimage) {
$columns[] = 'picture';
$headers[] = '';
}
$columns[] = 'fullname';
$headers[] = get_string('name');
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core_user\fields::get_identity_fields($coursecontext, false);
foreach ($extrafields as $field) {
$columns[] = $field;
$headers[] = \core_user\fields::get_display_name($field);
}
$columns[] = 'attempt';
$headers[] = get_string('attempt', 'scorm');
$columns[] = 'start';
$headers[] = get_string('started', 'scorm');
$columns[] = 'finish';
$headers[] = get_string('last', 'scorm');
$columns[] = 'score';
$headers[] = get_string('score', 'scorm');
if ($detailedrep && $scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$columns[] = 'scograde'.$sco->id;
$headers[] = format_string($sco->title);
}
}
} else {
$scoes = null;
}
if (!$download) {
$table = new \flexible_table('mod-scorm-report');
$table->define_columns($columns);
$table->define_headers($headers);
$table->define_baseurl($PAGE->url);
$table->sortable(true);
$table->collapsible(true);
// This is done to prevent redundant data, when a user has multiple attempts.
$table->column_suppress('picture');
$table->column_suppress('fullname');
foreach ($extrafields as $field) {
$table->column_suppress($field);
}
$table->no_sorting('start');
$table->no_sorting('finish');
$table->no_sorting('score');
$table->no_sorting('checkbox');
$table->no_sorting('picture');
if ( $scoes ) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$table->no_sorting('scograde'.$sco->id);
}
}
}
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'bold');
$table->column_class('score', 'bold');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else if ($download == 'ODS') {
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
// Creating a workbook.
$workbook = new \MoodleODSWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers.
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else if ($download == 'Excel') {
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
// Creating a workbook.
$workbook = new \MoodleExcelWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else if ($download == 'CSV') {
$csvexport = new \csv_export_writer("tab");
$csvexport->set_filename($filename, ".txt");
$csvexport->add_data($headers);
}
// Construct the SQL.
$select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(sa.attempt, 0)').' AS uniqueid, ';
// TODO Does not support custom user profile fields (MDL-70456).
$userfields = \core_user\fields::for_identity($coursecontext, false)->with_userpic()->including('idnumber');
$selectfields = $userfields->get_sql('u', false, '', 'userid')->selects;
$select .= 'sa.scormid AS scormid, sa.attempt AS attempt ' . $selectfields . ' ';
// This part is the same for all cases - join users and user tracking tables.
$from = 'FROM {user} u ';
$from .= 'LEFT JOIN {scorm_attempt} sa ON sa.userid = u.id AND sa.scormid = '.$scorm->id;
switch ($attemptsmode) {
case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
// Show only students with attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND sa.userid IS NOT NULL";
break;
case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
// Show only students without attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND sa.userid IS NULL";
break;
case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
// Show all students with or without attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND (sa.userid IS NOT NULL OR sa.userid IS NULL)";
break;
}
$countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(sa.attempt, 0)').')) AS nbresults, ';
$countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'sa.attempt').')) AS nbattempts, ';
$countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
$countsql .= $from.$where;
if (!$download) {
$sort = $table->get_sql_sort();
} else {
$sort = '';
}
// Fix some wired sorting.
if (empty($sort)) {
$sort = ' ORDER BY uniqueid';
} else {
$sort = ' ORDER BY '.$sort;
}
if (!$download) {
// Add extra limits due to initials bar.
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$where .= ' AND '.$twhere; // Initial bar.
$params = array_merge($params, $tparams);
}
if (!empty($countsql)) {
$count = $DB->get_record_sql($countsql, $params);
$totalinitials = $count->nbresults;
if ($twhere) {
$countsql .= ' AND '.$twhere;
}
$count = $DB->get_record_sql($countsql, $params);
$total = $count->nbresults;
}
$table->pagesize($pagesize, $total);
echo \html_writer::start_div('scormattemptcounts');
if ( $count->nbresults == $count->nbattempts ) {
echo get_string('reportcountattempts', 'scorm', $count);
} else if ( $count->nbattempts > 0 ) {
echo get_string('reportcountallattempts', 'scorm', $count);
} else {
echo $count->nbusers.' '.get_string('users');
}
echo \html_writer::end_div();
}
// Fetch the attempts.
if (!$download) {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
$table->get_page_start(), $table->get_page_size());
echo \html_writer::start_div('', array('id' => 'scormtablecontainer'));
if ($candelete) {
// Start form.
$strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post',
'action' => $PAGE->url->out(false),
'onsubmit' => 'return confirm("'.$strreallydel.'");'));
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo \html_writer::start_div('', array('style' => 'display: none;'));
echo \html_writer::input_hidden_params($PAGE->url);
echo \html_writer::end_div();
echo \html_writer::start_div();
}
$table->initialbars($totalinitials > 20); // Build table rows.
} else {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
}
if ($attempts) {
foreach ($attempts as $scouser) {
$row = array();
if (!empty($scouser->attempt)) {
$timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
} else {
$timetracks = '';
}
if (in_array('checkbox', $columns)) {
if ($candelete && !empty($timetracks->start)) {
$row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
} else if ($candelete) {
$row[] = '';
}
}
if (in_array('picture', $columns)) {
$user = new \stdClass();
$additionalfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
$user->id = $scouser->userid;
$row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id));
}
if (!$download) {
$url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id));
$row[] = \html_writer::link($url, fullname($scouser));
} else {
$row[] = fullname($scouser);
}
foreach ($extrafields as $field) {
$row[] = s($scouser->{$field});
}
if (empty($timetracks->start)) {
$row[] = '-';
$row[] = '-';
$row[] = '-';
$row[] = '-';
} else {
if (!$download) {
$url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id,
'user' => $scouser->userid, 'attempt' => $scouser->attempt, 'mode' => 'basic'));
$row[] = \html_writer::link($url, $scouser->attempt);
} else {
$row[] = $scouser->attempt;
}
if ($download == 'ODS' || $download == 'Excel' ) {
$row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
} else {
$row[] = userdate($timetracks->start);
}
if ($download == 'ODS' || $download == 'Excel' ) {
$row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
} else {
$row[] = userdate($timetracks->finish);
}
$row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
}
// Print out all scores of attempt.
if ($scoes) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
if ($trackdata->status == '') {
$trackdata->status = 'notattempted';
}
$strstatus = get_string($trackdata->status, 'scorm');
// If raw score exists, print it.
if ($trackdata->score_raw != '') {
$score = $trackdata->score_raw;
// Add max score if it exists.
if (scorm_version_check($scorm->version, SCORM_13)) {
$maxkey = 'cmi.score.max';
} else {
$maxkey = 'cmi.core.score.max';
}
if (isset($trackdata->$maxkey)) {
$score .= '/'.$trackdata->$maxkey;
}
// Else print out status.
} else {
$score = $strstatus;
}
if (!$download) {
$url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id,
'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt,
'mode' => 'basic'));
$row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '<br>' .
\html_writer::link($url, $score, array('title' => get_string('details', 'scorm')));
} else {
$row[] = $score;
}
} else {
// If we don't have track data, we haven't attempted yet.
$strstatus = get_string('notattempted', 'scorm');
if (!$download) {
$row[] = $OUTPUT->pix_icon('notattempted', $strstatus, 'scorm') . '<br>' . $strstatus;
} else {
$row[] = $strstatus;
}
}
}
}
}
if (!$download) {
$table->add_data($row);
} else if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
foreach ($row as $item) {
$myxls->write($rownum, $colnum, $item, $format);
$colnum++;
}
$rownum++;
} else if ($download == 'CSV') {
$csvexport->add_data($row);
}
}
if (!$download) {
$table->finish_output();
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
echo $this->generate_delete_selected_button();
echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
// Close form.
echo \html_writer::end_tag('div');
echo \html_writer::end_tag('form');
}
}
} else {
if ($candelete && !$download) {
echo \html_writer::end_div();
echo \html_writer::end_tag('form');
$table->finish_output();
}
echo \html_writer::end_div();
}
// Show preferences form irrespective of attempts are there to report or not.
if (!$download) {
$mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
$mform->display();
}
if ($download == 'Excel' or $download == 'ODS') {
$workbook->close();
exit;
} else if ($download == 'CSV') {
$csvexport->download_file();
exit;
}
} else {
echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
}
}// Function ends.
}
@@ -0,0 +1,28 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'scorm_basic' report plugin
*
* @package scormreport
* @subpackage basic
* @author Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Basic report';
$string['privacy:metadata:preference:scorm_report_detailed'] = 'Whether to track details in the SCORM basic report';
$string['privacy:metadata:preference:scorm_report_pagesize'] = 'Number of users to display in the SCORM reports';
@@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the scormreport_basic implementation of the privacy API.
*
* @package scormreport_basic
* @category test
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_basic\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\request\writer;
use scormreport_basic\privacy\provider;
/**
* Unit tests for the scormreport_basic implementation of the privacy API.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Basic setup for these tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
}
/**
* Ensure that export_user_preferences returns no data if the user has no data.
*/
public function test_export_user_preferences_not_defined(): void {
$user = \core_user::get_user_by_username('admin');
provider::export_user_preferences($user->id);
$writer = writer::with_context(\context_system::instance());
$this->assertFalse($writer->has_any_data());
}
/**
* Ensure that export_user_preferences returns single preferences.
*/
public function test_export_user_preferences_single(): void {
// Define a user preference.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
set_user_preference('scorm_report_detailed', 1);
set_user_preference('scorm_report_pagesize', 50);
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('scormreport_basic');
$this->assertCount(2, (array) $prefs);
$this->assertEquals(
get_string('privacy:metadata:preference:scorm_report_detailed', 'scormreport_basic'),
$prefs->scorm_report_detailed->description
);
$this->assertEquals(get_string('yes'), $prefs->scorm_report_detailed->value);
$this->assertEquals(
get_string('privacy:metadata:preference:scorm_report_pagesize', 'scormreport_basic'),
$prefs->scorm_report_pagesize->description
);
$this->assertEquals(50, $prefs->scorm_report_pagesize->value);
}
}
+6
View File
@@ -0,0 +1,6 @@
This files describes API changes in the mod scorm basic report
=== 3.6 ===
* The following renamed classes have been completely removed:
- scorm_basic_report (now: scormreport_basic\report)
+31
View File
@@ -0,0 +1,31 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of scorm_basic
*
* @package scormreport
* @subpackage basic
* @author Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->component = 'scormreport_basic';
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for scormreport_graphs.
*
* @package scormreport_graphs
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_graphs\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for scormreport_graphs implementing null_provider.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+178
View File
@@ -0,0 +1,178 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Core Report class of graphs reporting plugin
*
* @package scormreport_graphs
* @copyright 2012 Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_graphs;
defined('MOODLE_INTERNAL') || die();
use context_module;
use core\chart_bar;
use core\chart_series;
use moodle_url;
/**
* Main class to control the graphs reporting
*
* @package scormreport_graphs
* @copyright 2012 Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report extends \mod_scorm\report {
/** Number of bars. */
const BANDS = 11;
/** Range of each bar. */
const BANDWIDTH = 10;
/**
* Get the data for the report.
*
* @param int $scoid The sco ID.
* @param array $allowedlist The SQL and params to get the userlist.
* @return array of data indexed per bar.
*/
protected function get_data($scoid, $allowedlistsql) {
global $DB;
$data = array_fill(0, self::BANDS, 0);
list($allowedlist, $params) = $allowedlistsql;
$params = array_merge($params, ['scoid' => $scoid]);
// Construct the SQL.
$sql = "SELECT DISTINCT " . $DB->sql_concat('a.userid', '\'#\'', 'COALESCE(a.attempt, 0)') . " AS uniqueid,
a.userid AS userid,
a.scormid AS scormid,
a.attempt AS attempt,
v.scoid AS scoid
FROM {scorm_attempt} a
JOIN {scorm_scoes_value} v ON v.attemptid = a.id
WHERE a.userid IN ({$allowedlist}) AND v.scoid = :scoid";
$attempts = $DB->get_records_sql($sql, $params);
$usergrades = [];
foreach ($attempts as $attempt) {
if ($trackdata = scorm_get_tracks($scoid, $attempt->userid, $attempt->attempt)) {
if (isset($trackdata->score_raw)) {
$score = (int) $trackdata->score_raw;
if (empty($trackdata->score_min)) {
$minmark = 0;
} else {
$minmark = $trackdata->score_min;
}
// TODO MDL-55004: Get this value from elsewhere?
if (empty($trackdata->score_max)) {
$maxmark = 100;
} else {
$maxmark = $trackdata->score_max;
}
$range = ($maxmark - $minmark);
if (empty($range)) {
continue;
}
$percent = round((($score * 100) / $range), 2);
if (empty($usergrades[$attempt->userid]) || !isset($usergrades[$attempt->userid])
|| ($percent > $usergrades[$attempt->userid]) || ($usergrades[$attempt->userid] === '*')) {
$usergrades[$attempt->userid] = $percent;
}
unset($percent);
} else {
// User has made an attempt but either SCO was not able to record the score or something else is broken in SCO.
if (!isset($usergrades[$attempt->userid])) {
$usergrades[$attempt->userid] = '*';
}
}
}
}
// Recording all users who attempted the SCO, but resulting data was invalid.
foreach ($usergrades as $userpercent) {
if ($userpercent === '*') {
$data[0]++;
} else {
$gradeband = floor($userpercent / self::BANDWIDTH);
if ($gradeband != (self::BANDS - 1)) {
$gradeband++;
}
$data[$gradeband]++;
}
}
return $data;
}
/**
* Displays the full report.
*
* @param \stdClass $scorm full SCORM object
* @param \stdClass $cm - full course_module object
* @param \stdClass $course - full course object
* @param string $download - type of download being requested
* @return void
*/
public function display($scorm, $cm, $course, $download) {
global $DB, $OUTPUT, $PAGE;
$contextmodule = context_module::instance($cm->id);
$actionbar = new \mod_scorm\output\actionbar($cm->id, false, 0);
$renderer = $PAGE->get_renderer('mod_scorm');
echo $renderer->report_actionbar($actionbar);
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
groups_print_activity_menu($cm, new moodle_url($PAGE->url));
}
// Find out current restriction.
$group = groups_get_activity_group($cm, true);
$allowedlistsql = get_enrolled_sql($contextmodule, 'mod/scorm:savetrack', (int) $group);
// Labels.
$labels = [get_string('invaliddata', 'scormreport_graphs')];
for ($i = 1; $i <= self::BANDS - 1; $i++) {
$labels[] = ($i - 1) * self::BANDWIDTH . ' - ' . $i * self::BANDWIDTH;
}
if ($scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) {
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$data = $this->get_data($sco->id, $allowedlistsql);
$series = new chart_series($sco->title, $data);
$chart = new chart_bar();
$chart->set_labels($labels);
$chart->add_series($series);
$chart->get_xaxis(0, true)->set_label(get_string('percent', 'scormreport_graphs'));
$yaxis = $chart->get_yaxis(0, true);
$yaxis->set_label(get_string('participants', 'scormreport_graphs'));
$yaxis->set_stepsize(max(1, round(max($data) / 10)));
echo $OUTPUT->heading($sco->title, 3);
echo $OUTPUT->render($chart);
}
}
}
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Core Report class of graphs reporting plugin
*
* @package scormreport_graphs
* @copyright 2012 Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since Moodle 3.2
*/
define('NO_DEBUG_DISPLAY', true);
require_once(__DIR__ . '/../../../../config.php');
require_once($CFG->libdir . '/filelib.php');
debugging('This way of generating the chart is deprecated, refer to \\scormreport_graphs\\report::display().', DEBUG_DEVELOPER);
send_file_not_found();
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'scorm_basic' report plugin
*
* @package scormreport_graphs
* @copyright 2012 Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['invaliddata'] = 'Not enough data';
$string['participants'] = 'Number of participants';
$string['percent'] = 'Percent(%) secured';
$string['pluginname'] = 'Graph report';
$string['privacy:metadata'] = 'The Graph report only shows data stored in other locations.';
+30
View File
@@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of scormreport_graphs
*
* @package scormreport_graphs
* @copyright 2012 Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'scormreport_graphs'; // Full name of the plugin (used for diagnostics).
@@ -0,0 +1,110 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for scormreport_interactions.
*
* @package scormreport_interactions
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_interactions\privacy;
defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\writer;
/**
* Privacy Subsystem for scormreport_interactions.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
// User preferences shared between different scorm reports.
$collection->add_user_preference('scorm_report_pagesize', 'privacy:metadata:preference:scorm_report_pagesize');
// User preferences specific for this scorm report.
$collection->add_user_preference(
'scorm_report_interactions_qtext',
'privacy:metadata:preference:scorm_report_interactions_qtext'
);
$collection->add_user_preference(
'scorm_report_interactions_resp',
'privacy:metadata:preference:scorm_report_interactions_resp'
);
$collection->add_user_preference(
'scorm_report_interactions_right',
'privacy:metadata:preference:scorm_report_interactions_right'
);
$collection->add_user_preference(
'scorm_report_interactions_result',
'privacy:metadata:preference:scorm_report_interactions_result'
);
return $collection;
}
/**
* Store all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
static::get_and_export_user_preference($userid, 'scorm_report_pagesize');
static::get_and_export_user_preference($userid, 'scorm_report_interactions_qtext', true);
static::get_and_export_user_preference($userid, 'scorm_report_interactions_resp', true);
static::get_and_export_user_preference($userid, 'scorm_report_interactions_right', true);
static::get_and_export_user_preference($userid, 'scorm_report_interactions_result', true);
}
/**
* Get and export a user preference.
*
* @param int $userid The userid of the user whose data is to be exported.
* @param string $userpreference The user preference to export.
* @param boolean $transform If true, transform value to yesno.
*/
protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) {
$prefvalue = get_user_preferences($userpreference, null, $userid);
if ($prefvalue !== null) {
if ($transform) {
$transformedvalue = transform::yesno($prefvalue);
} else {
$transformedvalue = $prefvalue;
}
writer::export_user_preference(
'scormreport_interactions',
$userpreference,
$transformedvalue,
get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_interactions')
);
}
}
}
@@ -0,0 +1,615 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Core Report class of basic reporting plugin
* @package scormreport
* @subpackage interactions
* @author Dan Marsden and Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_interactions;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/scorm/report/interactions/responsessettings_form.php');
class report extends \mod_scorm\report {
/**
* displays the full report
* @param \stdClass $scorm full SCORM object
* @param \stdClass $cm - full course_module object
* @param \stdClass $course - full course object
* @param string $download - type of download being requested
*/
public function display($scorm, $cm, $course, $download) {
global $CFG, $DB, $OUTPUT, $PAGE;
$contextmodule = \context_module::instance($cm->id);
$action = optional_param('action', '', PARAM_ALPHA);
$attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
$attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
$PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
// Scorm action bar for report.
if ($download === '') {
$actionbar = new \mod_scorm\output\actionbar($cm->id, true, $attemptsmode);
$renderer = $PAGE->get_renderer('mod_scorm');
echo $renderer->report_actionbar($actionbar);
}
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
}
}
// Find out current groups mode.
$currentgroup = groups_get_activity_group($cm, true);
// Detailed report.
$mform = new \mod_scorm_report_interactions_settings($PAGE->url, compact('currentgroup'));
if ($fromform = $mform->get_data()) {
$pagesize = $fromform->pagesize;
$includeqtext = $fromform->qtext;
$includeresp = $fromform->resp;
$includeright = $fromform->right;
$includeresult = $fromform->result;
set_user_preference('scorm_report_pagesize', $pagesize);
set_user_preference('scorm_report_interactions_qtext', $includeqtext);
set_user_preference('scorm_report_interactions_resp', $includeresp);
set_user_preference('scorm_report_interactions_right', $includeright);
set_user_preference('scorm_report_interactions_result', $includeresult);
} else {
$pagesize = get_user_preferences('scorm_report_pagesize', 0);
$includeqtext = get_user_preferences('scorm_report_interactions_qtext', 0);
$includeresp = get_user_preferences('scorm_report_interactions_resp', 1);
$includeright = get_user_preferences('scorm_report_interactions_right', 0);
$includeresult = get_user_preferences('scorm_report_interactions_result', 0);
}
if ($pagesize < 1) {
$pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
}
// Select group menu.
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qtext'] = $includeqtext;
$displayoptions['resp'] = $includeresp;
$displayoptions['right'] = $includeright;
$displayoptions['result'] = $includeresult;
$mform->set_data($displayoptions + array('pagesize' => $pagesize));
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
if (!$download) {
groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions));
}
}
$formattextoptions = array('context' => \context_course::instance($course->id));
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
&& ($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 (!$DB->record_exists_sql($allowedlistsql, $params)) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
$nostudents = true;
}
} else {
// All users who can attempt scoes and who are in the currently selected group.
if (!$DB->record_exists_sql($allowedlistsql, $params)) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
$nostudents = true;
}
}
if ( !$nostudents ) {
// Now check if asked download of data.
$coursecontext = \context_course::instance($course->id);
if ($download) {
$filename = clean_filename("$course->shortname ".format_string($scorm->name, true, $formattextoptions));
}
// Define table columns.
$columns = array();
$headers = array();
if (!$download && $candelete) {
$columns[] = 'checkbox';
$headers[] = $this->generate_master_checkbox();
}
if (!$download && $CFG->grade_report_showuserimage) {
$columns[] = 'picture';
$headers[] = '';
}
$columns[] = 'fullname';
$headers[] = get_string('name');
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core_user\fields::get_identity_fields($coursecontext, false);
foreach ($extrafields as $field) {
$columns[] = $field;
$headers[] = \core_user\fields::get_display_name($field);
}
$columns[] = 'attempt';
$headers[] = get_string('attempt', 'scorm');
$columns[] = 'start';
$headers[] = get_string('started', 'scorm');
$columns[] = 'finish';
$headers[] = get_string('last', 'scorm');
$columns[] = 'score';
$headers[] = get_string('score', 'scorm');
$scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id');
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$columns[] = 'scograde'.$sco->id;
$headers[] = format_string($sco->title, '', $formattextoptions);
}
}
// Construct the SQL.
$select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(sa.attempt, 0)').' AS uniqueid, ';
// TODO Does not support custom user profile fields (MDL-70456).
$userfields = \core_user\fields::for_identity($coursecontext, false)->with_userpic()->including('idnumber');
$selectfields = $userfields->get_sql('u', false, '', 'userid')->selects;
$select .= 'sa.scormid AS scormid, sa.attempt AS attempt ' . $selectfields . ' ';
// This part is the same for all cases - join users and user tracking tables.
$from = 'FROM {user} u ';
$from .= 'LEFT JOIN {scorm_attempt} sa ON sa.userid = u.id AND sa.scormid = '.$scorm->id;
switch ($attemptsmode) {
case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
// Show only students with attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND sa.userid IS NOT NULL";
break;
case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
// Show only students without attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND sa.userid IS NULL";
break;
case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
// Show all students with or without attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND (sa.userid IS NOT NULL OR sa.userid IS NULL)";
break;
}
$countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(sa.attempt, 0)').')) AS nbresults, ';
$countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'sa.attempt').')) AS nbattempts, ';
$countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
$countsql .= $from.$where;
$questioncount = get_scorm_question_count($scorm->id);
$nbmaincolumns = count($columns);
for ($id = 0; $id < $questioncount; $id++) {
if ($displayoptions['qtext']) {
$columns[] = 'question' . $id;
$headers[] = get_string('questionx', 'scormreport_interactions', $id);
}
if ($displayoptions['resp']) {
$columns[] = 'response' . $id;
$headers[] = get_string('responsex', 'scormreport_interactions', $id);
}
if ($displayoptions['right']) {
$columns[] = 'right' . $id;
$headers[] = get_string('rightanswerx', 'scormreport_interactions', $id);
}
if ($displayoptions['result']) {
$columns[] = 'result' . $id;
$headers[] = get_string('resultx', 'scormreport_interactions', $id);
}
}
if (!$download) {
$table = new \flexible_table('mod-scorm-report');
$table->define_columns($columns);
$table->define_headers($headers);
$table->define_baseurl($PAGE->url);
$table->sortable(true);
$table->collapsible(true);
// This is done to prevent redundant data, when a user has multiple attempts.
$table->column_suppress('picture');
$table->column_suppress('fullname');
foreach ($extrafields as $field) {
$table->column_suppress($field);
}
$table->no_sorting('start');
$table->no_sorting('finish');
$table->no_sorting('score');
$table->no_sorting('checkbox');
$table->no_sorting('picture');
for ($id = 0; $id < $questioncount; $id++) {
if ($displayoptions['qtext']) {
$table->no_sorting('question'.$id);
}
if ($displayoptions['resp']) {
$table->no_sorting('response'.$id);
}
if ($displayoptions['right']) {
$table->no_sorting('right'.$id);
}
if ($displayoptions['result']) {
$table->no_sorting('result'.$id);
}
}
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$table->no_sorting('scograde'.$sco->id);
}
}
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'bold');
$table->column_class('score', 'bold');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else if ($download == 'ODS') {
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
// Creating a workbook.
$workbook = new \MoodleODSWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers.
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else if ($download == 'Excel') {
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
// Creating a workbook.
$workbook = new \MoodleExcelWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else if ($download == 'CSV') {
$csvexport = new \csv_export_writer("tab");
$csvexport->set_filename($filename, ".txt");
$csvexport->add_data($headers);
}
if (!$download) {
$sort = $table->get_sql_sort();
} else {
$sort = '';
}
// Fix some wired sorting.
if (empty($sort)) {
$sort = ' ORDER BY uniqueid';
} else {
$sort = ' ORDER BY '.$sort;
}
if (!$download) {
// Add extra limits due to initials bar.
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$where .= ' AND '.$twhere; // Initial bar.
$params = array_merge($params, $tparams);
}
if (!empty($countsql)) {
$count = $DB->get_record_sql($countsql, $params);
$totalinitials = $count->nbresults;
if ($twhere) {
$countsql .= ' AND '.$twhere;
}
$count = $DB->get_record_sql($countsql, $params);
$total = $count->nbresults;
}
$table->pagesize($pagesize, $total);
echo \html_writer::start_div('scormattemptcounts');
if ( $count->nbresults == $count->nbattempts ) {
echo get_string('reportcountattempts', 'scorm', $count);
} else if ( $count->nbattempts > 0 ) {
echo get_string('reportcountallattempts', 'scorm', $count);
} else {
echo $count->nbusers.' '.get_string('users');
}
echo \html_writer::end_div();
}
// Fetch the attempts.
if (!$download) {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
$table->get_page_start(), $table->get_page_size());
echo \html_writer::start_div('', array('id' => 'scormtablecontainer'));
if ($candelete) {
// Start form.
$strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post',
'action' => $PAGE->url->out(false),
'onsubmit' => 'return confirm("'.$strreallydel.'");'));
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo \html_writer::start_div('', array('style' => 'display: none;'));
echo \html_writer::input_hidden_params($PAGE->url);
echo \html_writer::end_div();
echo \html_writer::start_div();
}
$table->initialbars($totalinitials > 20); // Build table rows.
} else {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
}
if ($attempts) {
foreach ($attempts as $scouser) {
$row = array();
if (!empty($scouser->attempt)) {
$timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
} else {
$timetracks = '';
}
if (in_array('checkbox', $columns)) {
if ($candelete && !empty($timetracks->start)) {
$row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
} else if ($candelete) {
$row[] = '';
}
}
if (in_array('picture', $columns)) {
$user = new \stdClass();
$additionalfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
$user->id = $scouser->userid;
$row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id));
}
if (!$download) {
$url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id));
$row[] = \html_writer::link($url, fullname($scouser));
} else {
$row[] = fullname($scouser);
}
foreach ($extrafields as $field) {
$row[] = s($scouser->{$field});
}
if (empty($timetracks->start)) {
$row[] = '-';
$row[] = '-';
$row[] = '-';
$row[] = '-';
} else {
if (!$download) {
$url = new \moodle_url('/mod/scorm/report/userreport.php',
array('id' => $cm->id,
'user' => $scouser->userid,
'attempt' => $scouser->attempt,
'mode' => 'interactions'));
$row[] = \html_writer::link($url, $scouser->attempt);
} else {
$row[] = $scouser->attempt;
}
if ($download == 'ODS' || $download == 'Excel' ) {
$row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
} else {
$row[] = userdate($timetracks->start);
}
if ($download == 'ODS' || $download == 'Excel' ) {
$row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
} else {
$row[] = userdate($timetracks->finish);
}
$row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
}
// Print out all scores of attempt.
$emptyrow = $download ? '' : '&nbsp;';
foreach ($scoes as $sco) {
if ($sco->launch != '') {
if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
if ($trackdata->status == '') {
$trackdata->status = 'notattempted';
}
$strstatus = get_string($trackdata->status, 'scorm');
// If raw score exists, print it.
if ($trackdata->score_raw != '') {
$score = $trackdata->score_raw;
// Add max score if it exists.
if (isset($trackdata->score_max)) {
$score .= '/'.$trackdata->score_max;
}
} else { // Else print out status.
$score = $strstatus;
}
if (!$download) {
$url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id,
'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt,
'mode' => 'interactions'));
$row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '<br>' .
\html_writer::link($url, $score, array('title' => get_string('details', 'scorm')));
} else {
$row[] = $score;
}
// Interaction data.
for ($i = 0; $i < $questioncount; $i++) {
if ($displayoptions['qtext']) {
$element = 'cmi.interactions_'.$i.'.id';
if (isset($trackdata->$element)) {
$row[] = s($trackdata->$element);
} else {
$row[] = $emptyrow;
}
}
if ($displayoptions['resp']) {
$element = 'cmi.interactions_'.$i.'.student_response';
if (isset($trackdata->$element)) {
$row[] = s($trackdata->$element);
} else {
$row[] = $emptyrow;
}
}
if ($displayoptions['right']) {
$j = 0;
$element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
$rightans = '';
if (isset($trackdata->$element)) {
while (isset($trackdata->$element)) {
if ($j > 0) {
$rightans .= ',';
}
$rightans .= s($trackdata->$element);
$j++;
$element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
}
$row[] = $rightans;
} else {
$row[] = $emptyrow;
}
}
if ($displayoptions['result']) {
$element = 'cmi.interactions_'.$i.'.result';
if (isset($trackdata->$element)) {
$row[] = s($trackdata->$element);
} else {
$row[] = $emptyrow;
}
}
}
// End of interaction data.
} else {
// If we don't have track data, we haven't attempted yet.
$strstatus = get_string('notattempted', 'scorm');
if (!$download) {
$row[] = $OUTPUT->pix_icon('notattempted', $strstatus, 'scorm') . '<br>' . $strstatus;
} else {
$row[] = $strstatus;
}
// Complete the empty cells.
for ($i = 0; $i < count($columns) - $nbmaincolumns; $i++) {
$row[] = $emptyrow;
}
}
}
}
if (!$download) {
$table->add_data($row);
} else if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
foreach ($row as $item) {
$myxls->write($rownum, $colnum, $item, $format);
$colnum++;
}
$rownum++;
} else if ($download == 'CSV') {
$csvexport->add_data($row);
}
}
if (!$download) {
$table->finish_output();
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
echo $this->generate_delete_selected_button();
echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
// Close form.
echo \html_writer::end_tag('div');
echo \html_writer::end_tag('form');
}
}
} else {
if ($candelete && !$download) {
echo \html_writer::end_div();
echo \html_writer::end_tag('form');
$table->finish_output();
}
echo \html_writer::end_div();
}
// Show preferences form irrespective of attempts are there to report or not.
if (!$download) {
$mform->set_data(compact('pagesize', 'attemptsmode'));
$mform->display();
}
if ($download == 'Excel' or $download == 'ODS') {
$workbook->close();
exit;
} else if ($download == 'CSV') {
$csvexport->download_file();
exit;
}
} else {
echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
}
}// Function ends.
}
@@ -0,0 +1,42 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'scorm_interactions' report plugin
*
* @package scormreport
* @subpackage interactions
* @author Dan Marsden and Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Interactions report';
$string['privacy:metadata:preference:scorm_report_interactions_qtext'] = 'Whether to display the summary of questions in the SCORM interactions report';
$string['privacy:metadata:preference:scorm_report_interactions_resp'] = 'Whether to display the summary of responses in the SCORM interactions report';
$string['privacy:metadata:preference:scorm_report_interactions_result'] = 'Whether to display the summary of results in the SCORM interactions report';
$string['privacy:metadata:preference:scorm_report_interactions_right'] = 'Whether to display the summary of right anwers in the SCORM interactions report';
$string['privacy:metadata:preference:scorm_report_pagesize'] = 'Number of users to display in the SCORM reports';
$string['questionx'] = 'Question {$a}';
$string['responsex'] = 'Response {$a}';
$string['rightanswerx'] = 'Right answer {$a}';
$string['resultx'] = 'Result {$a}';
$string['summaryofquestiontext'] = 'Summary of question';
$string['summaryofresponse'] = 'Summary of responses';
$string['summaryofrightanswer'] = 'Summary of right answer';
$string['summaryofresult'] = 'Summary of result';
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of scorm_interactions
* @package scormreport
* @subpackage interactions
* @author Dan Marsden and Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/formslib.php");
class mod_scorm_report_interactions_settings extends moodleform {
public function definition() {
global $COURSE;
$mform =& $this->_form;
// -------------------------------------------------------------------------------
$mform->addElement('header', 'preferencespage', get_string('preferencespage', 'scorm'));
$options = array();
if ($COURSE->id != SITEID) {
$options[SCORM_REPORT_ATTEMPTS_ALL_STUDENTS] = get_string('optallstudents', 'scorm');
$options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH] = get_string('optattemptsonly', 'scorm');
$options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'scorm');
}
$mform->addElement('select', 'attemptsmode', get_string('show', 'scorm'), $options);
$mform->addElement('advcheckbox', 'qtext', '', get_string('summaryofquestiontext', 'scormreport_interactions'));
$mform->addElement('advcheckbox', 'resp', '', get_string('summaryofresponse', 'scormreport_interactions'));
$mform->addElement('advcheckbox', 'right', '', get_string('summaryofrightanswer', 'scormreport_interactions'));
$mform->addElement('advcheckbox', 'result', '', get_string('summaryofresult', 'scormreport_interactions'));
// -------------------------------------------------------------------------------
$mform->addElement('header', 'preferencesuser', get_string('preferencesuser', 'scorm'));
$mform->addElement('text', 'pagesize', get_string('pagesize', 'scorm'));
$mform->setType('pagesize', PARAM_INT);
$this->add_action_buttons(false, get_string('savepreferences'));
}
}
@@ -0,0 +1,91 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the scormreport_interactions implementation of the privacy API.
*
* @package scormreport_interactions
* @category test
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_interactions\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\request\writer;
use scormreport_interactions\privacy\provider;
/**
* Unit tests for the scormreport_interactions implementation of the privacy API.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Basic setup for these tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
}
/**
* Ensure that export_user_preferences returns no data if the user has no data.
*/
public function test_export_user_preferences_not_defined(): void {
$user = \core_user::get_user_by_username('admin');
provider::export_user_preferences($user->id);
$writer = writer::with_context(\context_system::instance());
$this->assertFalse($writer->has_any_data());
}
/**
* Ensure that export_user_preferences returns single preferences.
*/
public function test_export_user_preferences_single(): void {
// Define a user preference.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
set_user_preference('scorm_report_pagesize', 50);
set_user_preference('scorm_report_interactions_qtext', 1);
set_user_preference('scorm_report_interactions_resp', 0);
set_user_preference('scorm_report_interactions_right', 1);
set_user_preference('scorm_report_interactions_result', 1);
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('scormreport_interactions');
$this->assertCount(5, (array) $prefs);
$this->assertEquals(
get_string('privacy:metadata:preference:scorm_report_pagesize', 'scormreport_interactions'),
$prefs->scorm_report_pagesize->description
);
$this->assertEquals(50, $prefs->scorm_report_pagesize->value);
$this->assertEquals(
get_string('privacy:metadata:preference:scorm_report_interactions_qtext', 'scormreport_interactions'),
$prefs->scorm_report_interactions_qtext->description
);
$this->assertEquals(get_string('yes'), $prefs->scorm_report_interactions_qtext->value);
$this->assertEquals(get_string('no'), $prefs->scorm_report_interactions_resp->value);
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of scorm_interactions
* @package scormreport
* @subpackage interactions
* @author Dan Marsden and Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'scormreport_interactions'; // Full name of the plugin (used for diagnostics).
@@ -0,0 +1,95 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for scormreport_objectives.
*
* @package scormreport_objectives
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_objectives\privacy;
defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\writer;
/**
* Privacy Subsystem for scormreport_objectives.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
// User preferences shared between different scorm reports.
$collection->add_user_preference('scorm_report_pagesize', 'privacy:metadata:preference:scorm_report_pagesize');
// User preferences specific for this scorm report.
$collection->add_user_preference(
'scorm_report_objectives_score',
'privacy:metadata:preference:scorm_report_objectives_score'
);
return $collection;
}
/**
* Store all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
static::get_and_export_user_preference($userid, 'scorm_report_pagesize');
static::get_and_export_user_preference($userid, 'scorm_report_objectives_score', true);
}
/**
* Get and export a user preference.
*
* @param int $userid The userid of the user whose data is to be exported.
* @param string $userpreference The user preference to export.
* @param boolean $transform If true, transform value to yesno.
*/
protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) {
$prefvalue = get_user_preferences($userpreference, null, $userid);
if ($prefvalue !== null) {
if ($transform) {
$transformedvalue = transform::yesno($prefvalue);
} else {
$transformedvalue = $prefvalue;
}
writer::export_user_preference(
'scormreport_objectives',
$userpreference,
$transformedvalue,
get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_objectives')
);
}
}
}
@@ -0,0 +1,641 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Core Report class of objectives SCORM report plugin
* @package scormreport_objectives
* @author Dan Marsden <dan@danmarsden.com>
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_objectives;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/scorm/report/objectives/responsessettings_form.php');
/**
* Objectives report class
*
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report extends \mod_scorm\report {
/**
* displays the full report
* @param \stdClass $scorm full SCORM object
* @param \stdClass $cm - full course_module object
* @param \stdClass $course - full course object
* @param string $download - type of download being requested
*/
public function display($scorm, $cm, $course, $download) {
global $CFG, $DB, $OUTPUT, $PAGE;
$contextmodule = \context_module::instance($cm->id);
$action = optional_param('action', '', PARAM_ALPHA);
$attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
$attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
$PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
// Scorm action bar for report.
if ($download === '') {
$actionbar = new \mod_scorm\output\actionbar($cm->id, true, $attemptsmode);
$renderer = $PAGE->get_renderer('mod_scorm');
echo $renderer->report_actionbar($actionbar);
}
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
}
}
// Find out current groups mode.
$currentgroup = groups_get_activity_group($cm, true);
// Detailed report.
$mform = new \mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup'));
if ($fromform = $mform->get_data()) {
$pagesize = $fromform->pagesize;
$showobjectivescore = $fromform->objectivescore;
set_user_preference('scorm_report_pagesize', $pagesize);
set_user_preference('scorm_report_objectives_score', $showobjectivescore);
} else {
$pagesize = get_user_preferences('scorm_report_pagesize', 0);
$showobjectivescore = get_user_preferences('scorm_report_objectives_score', 0);
}
if ($pagesize < 1) {
$pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
}
// Select group menu.
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['objectivescore'] = $showobjectivescore;
$mform->set_data($displayoptions + array('pagesize' => $pagesize));
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
if (!$download) {
groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions));
}
}
$formattextoptions = array('context' => \context_course::instance($course->id));
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
&& ($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 (!$DB->record_exists_sql($allowedlistsql, $params)) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
$nostudents = true;
}
} else {
// All users who can attempt scoes and who are in the currently selected group.
if (!$DB->record_exists_sql($allowedlistsql, $params)) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
$nostudents = true;
}
}
if ( !$nostudents ) {
// Now check if asked download of data.
$coursecontext = \context_course::instance($course->id);
if ($download) {
$filename = clean_filename("$course->shortname ".format_string($scorm->name, true, $formattextoptions));
}
// Define table columns.
$columns = array();
$headers = array();
if (!$download && $candelete) {
$columns[] = 'checkbox';
$headers[] = $this->generate_master_checkbox();
}
if (!$download && $CFG->grade_report_showuserimage) {
$columns[] = 'picture';
$headers[] = '';
}
$columns[] = 'fullname';
$headers[] = get_string('name');
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core_user\fields::get_identity_fields($coursecontext, false);
foreach ($extrafields as $field) {
$columns[] = $field;
$headers[] = \core_user\fields::get_display_name($field);
}
$columns[] = 'attempt';
$headers[] = get_string('attempt', 'scorm');
$columns[] = 'start';
$headers[] = get_string('started', 'scorm');
$columns[] = 'finish';
$headers[] = get_string('last', 'scorm');
$columns[] = 'score';
$headers[] = get_string('score', 'scorm');
$scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id');
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$columns[] = 'scograde'.$sco->id;
$headers[] = format_string($sco->title, '', $formattextoptions);
}
}
// Construct the SQL.
$select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(sa.attempt, 0)').' AS uniqueid, ';
// TODO Does not support custom user profile fields (MDL-70456).
$userfields = \core_user\fields::for_identity($coursecontext, false)->with_userpic()->including('idnumber');
$selectfields = $userfields->get_sql('u', false, '', 'userid')->selects;
$select .= 'sa.scormid AS scormid, sa.attempt AS attempt ' . $selectfields . ' ';
// This part is the same for all cases - join users and user tracking tables.
$from = 'FROM {user} u ';
$from .= 'LEFT JOIN {scorm_attempt} sa ON sa.userid = u.id AND sa.scormid = '.$scorm->id;
switch ($attemptsmode) {
case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
// Show only students with attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND sa.userid IS NOT NULL";
break;
case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
// Show only students without attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND sa.userid IS NULL";
break;
case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
// Show all students with or without attempts.
$where = " WHERE u.id IN ({$allowedlistsql}) AND (sa.userid IS NOT NULL OR sa.userid IS NULL)";
break;
}
$countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(sa.attempt, 0)').')) AS nbresults, ';
$countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'sa.attempt').')) AS nbattempts, ';
$countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
$countsql .= $from.$where;
$nbmaincolumns = count($columns); // Get number of main columns used.
$objectives = get_scorm_objectives($scorm->id);
$nosort = array();
foreach ($objectives as $scoid => $sco) {
foreach ($sco as $id => $objectivename) {
$colid = $scoid.'objectivestatus' . $id;
$columns[] = $colid;
$nosort[] = $colid;
if (!$displayoptions['objectivescore']) {
// Display the objective name only.
$headers[] = $objectivename;
} else {
// Display the objective status header with a "status" suffix to avoid confusion.
$headers[] = $objectivename. ' '. get_string('status', 'scormreport_objectives');
// Now print objective score headers.
$colid = $scoid.'objectivescore' . $id;
$columns[] = $colid;
$nosort[] = $colid;
$headers[] = $objectivename. ' '. get_string('score', 'scormreport_objectives');
}
}
}
$emptycell = ''; // Used when an empty cell is being printed - in html we add a space.
if (!$download) {
$emptycell = '&nbsp;';
$table = new \flexible_table('mod-scorm-report');
$table->define_columns($columns);
$table->define_headers($headers);
$table->define_baseurl($PAGE->url);
$table->sortable(true);
$table->collapsible(true);
// This is done to prevent redundant data, when a user has multiple attempts.
$table->column_suppress('picture');
$table->column_suppress('fullname');
foreach ($extrafields as $field) {
$table->column_suppress($field);
}
foreach ($nosort as $field) {
$table->no_sorting($field);
}
$table->no_sorting('start');
$table->no_sorting('finish');
$table->no_sorting('score');
$table->no_sorting('checkbox');
$table->no_sorting('picture');
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$table->no_sorting('scograde'.$sco->id);
}
}
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'bold');
$table->column_class('score', 'bold');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else if ($download == 'ODS') {
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
// Creating a workbook.
$workbook = new \MoodleODSWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers.
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else if ($download == 'Excel') {
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
// Creating a workbook.
$workbook = new \MoodleExcelWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else if ($download == 'CSV') {
$csvexport = new \csv_export_writer("tab");
$csvexport->set_filename($filename, ".txt");
$csvexport->add_data($headers);
}
if (!$download) {
$sort = $table->get_sql_sort();
} else {
$sort = '';
}
// Fix some wired sorting.
if (empty($sort)) {
$sort = ' ORDER BY uniqueid';
} else {
$sort = ' ORDER BY '.$sort;
}
if (!$download) {
// Add extra limits due to initials bar.
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$where .= ' AND '.$twhere; // Initial bar.
$params = array_merge($params, $tparams);
}
if (!empty($countsql)) {
$count = $DB->get_record_sql($countsql, $params);
$totalinitials = $count->nbresults;
if ($twhere) {
$countsql .= ' AND '.$twhere;
}
$count = $DB->get_record_sql($countsql, $params);
$total = $count->nbresults;
}
$table->pagesize($pagesize, $total);
echo \html_writer::start_div('scormattemptcounts');
if ( $count->nbresults == $count->nbattempts ) {
echo get_string('reportcountattempts', 'scorm', $count);
} else if ( $count->nbattempts > 0 ) {
echo get_string('reportcountallattempts', 'scorm', $count);
} else {
echo $count->nbusers.' '.get_string('users');
}
echo \html_writer::end_div();
}
// Fetch the attempts.
if (!$download) {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
$table->get_page_start(), $table->get_page_size());
echo \html_writer::start_div('', array('id' => 'scormtablecontainer'));
if ($candelete) {
// Start form.
$strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post',
'action' => $PAGE->url->out(false),
'onsubmit' => 'return confirm("'.$strreallydel.'");'));
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo \html_writer::start_div('', array('style' => 'display: none;'));
echo \html_writer::input_hidden_params($PAGE->url);
echo \html_writer::end_div();
echo \html_writer::start_div();
}
$table->initialbars($totalinitials > 20); // Build table rows.
} else {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
}
if ($attempts) {
foreach ($attempts as $scouser) {
$row = array();
if (!empty($scouser->attempt)) {
$timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
} else {
$timetracks = '';
}
if (in_array('checkbox', $columns)) {
if ($candelete && !empty($timetracks->start)) {
$row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
} else if ($candelete) {
$row[] = '';
}
}
if (in_array('picture', $columns)) {
$user = new \stdClass();
$additionalfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
$user->id = $scouser->userid;
$row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id));
}
if (!$download) {
$url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id));
$row[] = \html_writer::link($url, fullname($scouser));
} else {
$row[] = fullname($scouser);
}
foreach ($extrafields as $field) {
$row[] = s($scouser->{$field});
}
if (empty($timetracks->start)) {
$row[] = '-';
$row[] = '-';
$row[] = '-';
$row[] = '-';
} else {
if (!$download) {
$url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id,
'user' => $scouser->userid, 'attempt' => $scouser->attempt, 'mode' => 'objectives'));
$row[] = \html_writer::link($url, $scouser->attempt);
} else {
$row[] = $scouser->attempt;
}
if ($download == 'ODS' || $download == 'Excel' ) {
$row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
} else {
$row[] = userdate($timetracks->start);
}
if ($download == 'ODS' || $download == 'Excel' ) {
$row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
} else {
$row[] = userdate($timetracks->finish);
}
$row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
}
// Print out all scores of attempt.
foreach ($scoes as $sco) {
if ($sco->launch != '') {
if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
if ($trackdata->status == '') {
$trackdata->status = 'notattempted';
}
$strstatus = get_string($trackdata->status, 'scorm');
if ($trackdata->score_raw != '') { // If raw score exists, print it.
$score = $trackdata->score_raw;
// Add max score if it exists.
if (isset($trackdata->score_max)) {
$score .= '/'.$trackdata->score_max;
}
} else { // ...else print out status.
$score = $strstatus;
}
if (!$download) {
$url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id,
'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt,
'mode' => 'objectives'));
$row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '<br>' .
\html_writer::link($url, $score, array('title' => get_string('details', 'scorm')));
} else {
$row[] = $score;
}
// Iterate over tracks and match objective id against values.
$scorm2004 = false;
if (scorm_version_check($scorm->version, SCORM_13)) {
$scorm2004 = true;
$objectiveprefix = "cmi.objectives.";
} else {
$objectiveprefix = "cmi.objectives_";
}
$keywords = array(".id", $objectiveprefix);
$objectivestatus = array();
$objectivescore = array();
foreach ($trackdata as $name => $value) {
if (strpos($name, $objectiveprefix) === 0 && strrpos($name, '.id') !== false) {
$num = trim(str_ireplace($keywords, '', $name));
if (is_numeric($num)) {
if ($scorm2004) {
$element = $objectiveprefix.$num.'.completion_status';
} else {
$element = $objectiveprefix.$num.'.status';
}
if (isset($trackdata->$element)) {
$objectivestatus[$value] = $trackdata->$element;
} else {
$objectivestatus[$value] = '';
}
if ($displayoptions['objectivescore']) {
$element = $objectiveprefix.$num.'.score.raw';
if (isset($trackdata->$element)) {
$objectivescore[$value] = $trackdata->$element;
} else {
$objectivescore[$value] = '';
}
}
}
}
}
// Interaction data.
if (!empty($objectives[$trackdata->scoid])) {
foreach ($objectives[$trackdata->scoid] as $name) {
if (isset($objectivestatus[$name])) {
$row[] = s($objectivestatus[$name]);
} else {
$row[] = $emptycell;
}
if ($displayoptions['objectivescore']) {
if (isset($objectivescore[$name])) {
$row[] = s($objectivescore[$name]);
} else {
$row[] = $emptycell;
}
}
}
}
// End of interaction data.
} else {
// If we don't have track data, we haven't attempted yet.
$strstatus = get_string('notattempted', 'scorm');
if (!$download) {
$row[] = $OUTPUT->pix_icon('notattempted', $strstatus, 'scorm') . '<br>' . $strstatus;
} else {
$row[] = $strstatus;
}
// Complete the empty cells.
for ($i = 0; $i < count($columns) - $nbmaincolumns; $i++) {
$row[] = $emptycell;
}
}
}
}
if (!$download) {
$table->add_data($row);
} else if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
foreach ($row as $item) {
$myxls->write($rownum, $colnum, $item, $format);
$colnum++;
}
$rownum++;
} else if ($download == 'CSV') {
$csvexport->add_data($row);
}
}
if (!$download) {
$table->finish_output();
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
echo $this->generate_delete_selected_button();
echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
// Close form.
echo \html_writer::end_tag('div');
echo \html_writer::end_tag('form');
}
}
} else {
if ($candelete && !$download) {
echo \html_writer::end_div();
echo \html_writer::end_tag('form');
$table->finish_output();
}
echo \html_writer::end_div();
}
// Show preferences form irrespective of attempts are there to report or not.
if (!$download) {
$mform->set_data(compact('pagesize', 'attemptsmode'));
$mform->display();
}
if ($download == 'Excel' or $download == 'ODS') {
$workbook->close();
exit;
} else if ($download == 'CSV') {
$csvexport->download_file();
exit;
}
} else {
echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
}
}// Function ends.
}
/**
* Returns The maximum numbers of Objectives associated with an Scorm Pack
*
* @param int $scormid Scorm instance id
* @return array an array of possible objectives.
*/
function get_scorm_objectives($scormid) {
global $DB;
$objectives = [];
$params = ['scormid' => $scormid, 'search' => 'cmi.objectives%.id'];
$value = $DB->sql_compare_text('v.value');
$sql = "SELECT DISTINCT $value as value, ss.id
FROM {scorm_scoes_value} v
JOIN {scorm_scoes} ss ON ss.id = v.scoid AND ss.scorm = :scormid
JOIN {scorm_element} e ON v.elementid = e.id
WHERE ".$DB->sql_like("element", ":search", false);
$rs = $DB->get_records_sql($sql, $params);
foreach ($rs as $record) {
$objectives[$record->scoid][] = $record->value;
}
// Now naturally sort the sco arrays.
foreach ($objectives as $scoid => $sco) {
natsort($objectives[$scoid]);
}
return $objectives;
}
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'scorm_objectives' report plugin
*
* @package scormreport_objectives
* @author Dan Marsden <dan@danmarsden.com>
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Objectives report';
$string['privacy:metadata:preference:scorm_report_objectives_score'] = 'Whether to display the objective score in the SCORM report';
$string['privacy:metadata:preference:scorm_report_pagesize'] = 'Number of users to display in the SCORM reports';
$string['objectivex'] = 'Objective {$a}';
$string['objectivescore'] = 'Show objective score';
$string['score'] = 'score';
$string['status'] = 'status';
@@ -0,0 +1,60 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of scorm_objectives
* @package scormreport_objectives
* @author Dan Marsden <dan@danmarsden.com>
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/formslib.php");
/**
* A form that displays the objective report settings
*
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_scorm_report_objectives_settings extends moodleform {
/**
* Definition of the setting form elements
*/
protected function definition() {
global $COURSE;
$mform =& $this->_form;
$mform->addElement('header', 'preferencespage', get_string('preferencespage', 'scorm'));
$options = array();
if ($COURSE->id != SITEID) {
$options[SCORM_REPORT_ATTEMPTS_ALL_STUDENTS] = get_string('optallstudents', 'scorm');
$options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH] = get_string('optattemptsonly', 'scorm');
$options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'scorm');
}
$mform->addElement('select', 'attemptsmode', get_string('show', 'scorm'), $options);
$mform->addElement('advcheckbox', 'objectivescore', '', get_string('objectivescore', 'scormreport_objectives'));
$mform->addElement('header', 'preferencesuser', get_string('preferencesuser', 'scorm'));
$mform->addElement('text', 'pagesize', get_string('pagesize', 'scorm'));
$mform->setType('pagesize', PARAM_INT);
$this->add_action_buttons(false, get_string('savepreferences'));
}
}
@@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the scormreport_objectives implementation of the privacy API.
*
* @package scormreport_objectives
* @category test
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace scormreport_objectives\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\request\writer;
use scormreport_objectives\privacy\provider;
/**
* Unit tests for the scormreport_objectives implementation of the privacy API.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Basic setup for these tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
}
/**
* Ensure that export_user_preferences returns no data if the user has no data.
*/
public function test_export_user_preferences_not_defined(): void {
$user = \core_user::get_user_by_username('admin');
provider::export_user_preferences($user->id);
$writer = writer::with_context(\context_system::instance());
$this->assertFalse($writer->has_any_data());
}
/**
* Ensure that export_user_preferences returns single preferences.
*/
public function test_export_user_preferences_single(): void {
// Define a user preference.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
set_user_preference('scorm_report_pagesize', 50);
set_user_preference('scorm_report_objectives_score', 1);
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('scormreport_objectives');
$this->assertCount(2, (array) $prefs);
$this->assertEquals(
get_string('privacy:metadata:preference:scorm_report_pagesize', 'scormreport_objectives'),
$prefs->scorm_report_pagesize->description
);
$this->assertEquals(50, $prefs->scorm_report_pagesize->value);
$this->assertEquals(
get_string('privacy:metadata:preference:scorm_report_objectives_score', 'scormreport_objectives'),
$prefs->scorm_report_objectives_score->description
);
$this->assertEquals(get_string('yes'), $prefs->scorm_report_objectives_score->value);
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of scorm_objectives
* @package scormreport_objectives
* @author Dan Marsden <dan@danmarsden.com>
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->component = 'scormreport_objectives';
+101
View File
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Returns an array of reports to which are currently readable.
* @package mod_scorm
* @author Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/* Generates and returns list of available Scorm report sub-plugins
*
* @param context context level to check caps against
* @return array list of valid reports present
*/
function scorm_report_list($context) {
global $CFG;
static $reportlist;
if (!empty($reportlist)) {
return $reportlist;
}
$installed = core_component::get_plugin_list('scormreport');
foreach ($installed as $reportname => $notused) {
// Moodle 2.8+ style of autoloaded classes.
$classname = "scormreport_$reportname\\report";
if (class_exists($classname)) {
$report = new $classname();
if ($report->canview($context)) {
$reportlist[] = $reportname;
}
continue;
}
// Legacy style of naming classes.
$pluginfile = $CFG->dirroot.'/mod/scorm/report/'.$reportname.'/report.php';
if (is_readable($pluginfile)) {
debugging("Please use autoloaded classnames for your plugin. Refer MDL-46469 for details", DEBUG_DEVELOPER);
include_once($pluginfile);
$reportclassname = "scorm_{$reportname}_report";
if (class_exists($reportclassname)) {
$report = new $reportclassname();
if ($report->canview($context)) {
$reportlist[] = $reportname;
}
}
}
}
return $reportlist;
}
/**
* Returns The maximum numbers of Questions associated with an Scorm Pack
*
* @param int Scorm ID
* @return int an integer representing the question count
*/
function get_scorm_question_count($scormid) {
global $DB;
$count = 0;
$params = array();
$sql = "SELECT DISTINCT e.id, e.element
FROM {scorm_element} e
JOIN {scorm_scoes_value} v ON e.id = v.elementid
JOIN {scorm_attempt} a ON a.id = v.attemptid
WHERE a.scormid = ? AND ". $DB->sql_like("element", "?", false) .
" ORDER BY e.element";
$params[] = $scormid;
$params[] = "cmi.interactions_%.id";
$rs = $DB->get_recordset_sql($sql, $params);
$keywords = array("cmi.interactions_", ".id");
if ($rs->valid()) {
foreach ($rs as $record) {
$num = trim(str_ireplace($keywords, '', $record->element));
if (is_numeric($num) && $num > $count) {
$count = $num;
}
}
// Done as interactions start at 0 (do only if we have something to report).
$count++;
}
$rs->close(); // Closing recordset.
return $count;
}
+149
View File
@@ -0,0 +1,149 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page displays the user data from a single attempt
*
* @package mod_scorm
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../../config.php");
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
$id = required_param('id', PARAM_INT); // Course Module ID.
$userid = required_param('user', PARAM_INT); // User ID.
$attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
$mode = optional_param('mode', '', PARAM_ALPHA); // Scorm mode from which reached here.
// Building the url to use for links.+ data details buildup.
$url = new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id,
'user' => $userid,
'attempt' => $attempt));
$tracksurl = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
'user' => $userid,
'attempt' => $attempt,
'mode' => $mode));
$cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
// Get list of attempts this user has made.
$attemptids = scorm_get_all_attempts($scorm->id, $userid);
$PAGE->set_url($url);
$PAGE->set_secondary_active_tab('scormreport');
// END of url setting + data buildup.
// Checking login +logging +getting context.
require_login($course, false, $cm);
$contextmodule = context_module::instance($cm->id);
require_capability('mod/scorm:viewreport', $contextmodule);
// Check user has group access.
if (!groups_user_groups_visible($course, $userid, $cm)) {
throw new moodle_exception('nopermissiontoshow');
}
// Trigger a user report viewed event.
$event = \mod_scorm\event\user_report_viewed::create(array(
'context' => $contextmodule,
'relateduserid' => $userid,
'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id)
));
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('scorm', $scorm);
$event->trigger();
// Print the page header.
$strreport = get_string('report', 'scorm');
$strattempt = get_string('attempt', 'scorm');
$PAGE->set_title("$course->shortname: ".format_string($scorm->name));
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
$PAGE->navbar->add(fullname($user). " - $strattempt $attempt");
$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);
echo $OUTPUT->header();
// End of Print the page header.
$currenttab = 'scoes';
$renderer = $PAGE->get_renderer('mod_scorm');
$useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'learning', $mode);
echo $renderer->user_report_actionbar($useractionreport);
// Printing user details.
$output = $PAGE->get_renderer('mod_scorm');
echo $output->view_user_heading($user, $course, $PAGE->url, $attempt, $attemptids);
if ($scoes = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id), 'sortorder, id')) {
// Print general score data.
$table = new html_table();
$table->head = array(
get_string('title', 'scorm'),
get_string('status', 'scorm'),
get_string('time', 'scorm'),
get_string('score', 'scorm'),
'');
$table->align = array('left', 'center', 'center', 'right', 'left');
$table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
$table->width = '80%';
$table->size = array('*', '*', '*', '*', '*');
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$row = array();
$score = '&nbsp;';
if ($trackdata = scorm_get_tracks($sco->id, $userid, $attempt)) {
if ($trackdata->score_raw != '') {
$score = $trackdata->score_raw;
}
if ($trackdata->status == '') {
if (!empty($trackdata->progress)) {
$trackdata->status = $trackdata->progress;
} else {
$trackdata->status = 'notattempted';
}
}
$tracksurl->param('scoid', $sco->id);
$detailslink = html_writer::link($tracksurl, get_string('details', 'scorm'));
} else {
$trackdata = new stdClass();
$trackdata->status = 'notattempted';
$trackdata->total_time = '&nbsp;';
$detailslink = '&nbsp;';
}
$strstatus = get_string($trackdata->status, 'scorm');
$row[] = $OUTPUT->pix_icon($trackdata->status, $strstatus, 'scorm') . '&nbsp;'.format_string($sco->title);
$row[] = get_string($trackdata->status, 'scorm');
$row[] = scorm_format_duration($trackdata->total_time);
$row[] = $score;
$row[] = $detailslink;
} else {
$row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
}
$table->data[] = $row;
}
echo html_writer::table($table);
}
// Print footer.
echo $OUTPUT->footer();
+181
View File
@@ -0,0 +1,181 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page displays the user data from a single attempt
*
* @package mod_scorm
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../../config.php");
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php');
require_once($CFG->libdir . '/tablelib.php');
$id = required_param('id', PARAM_INT); // Course Module ID.
$userid = required_param('user', PARAM_INT); // User ID.
$attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
$download = optional_param('download', '', PARAM_ALPHA);
$mode = optional_param('mode', '', PARAM_ALPHA); // Scorm mode from which reached here.
// Building the url to use for links.+ data details buildup.
$url = new moodle_url('/mod/scorm/report/userreportinteractions.php', array('id' => $id,
'user' => $userid,
'attempt' => $attempt));
$cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
// Get list of attempts this user has made.
$attemptids = scorm_get_all_attempts($scorm->id, $userid);
$PAGE->set_url($url);
$PAGE->set_secondary_active_tab('scormreport');
// END of url setting + data buildup.
// Checking login +logging +getting context.
require_login($course, false, $cm);
$contextmodule = context_module::instance($cm->id);
require_capability('mod/scorm:viewreport', $contextmodule);
// Check user has group access.
if (!groups_user_groups_visible($course, $userid, $cm)) {
throw new moodle_exception('nopermissiontoshow');
}
// Trigger a user interactions viewed event.
$event = \mod_scorm\event\interactions_viewed::create(array(
'context' => $contextmodule,
'relateduserid' => $userid,
'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id)
));
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('scorm', $scorm);
$event->trigger();
$sql = "SELECT a.id, a.userid, a.scormid, v.scoid, a.attempt, v.value, v.timemodified, e.element
FROM {scorm_attempt} a
JOIN {scorm_scoes_value} v ON v.attemptid = a.id
JOIN {scorm_element} e ON e.id = v.elementid
WHERE a.userid = :userid AND a.scormid = :scormid AND a.attempt = :attempt";
$trackdata = $DB->get_records_sql($sql, ['userid' => $userid, 'scormid' => $scorm->id, 'attempt' => $attempt]);
$usertrack = scorm_format_interactions($trackdata);
$questioncount = get_scorm_question_count($scorm->id);
$courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id)));
$exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('interactions', 'scorm');
// Set up the table.
$table = new flexible_table('mod-scorm-userreport-interactions');
if (!$table->is_downloading($download, $exportfilename)) {
// Print the page header.
$strattempt = get_string('attempt', 'scorm');
$strreport = get_string('report', 'scorm');
$PAGE->set_title("$course->shortname: ".format_string($scorm->name));
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
$PAGE->navbar->add(fullname($user). " - $strattempt $attempt");
$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);
echo $OUTPUT->header();
// End of Print the page header.
$currenttab = 'interactions';
$renderer = $PAGE->get_renderer('mod_scorm');
$useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'interact', $mode);
echo $renderer->user_report_actionbar($useractionreport);
// Printing user details.
$output = $PAGE->get_renderer('mod_scorm');
echo $output->view_user_heading($user, $course, $PAGE->url, $attempt, $attemptids);
}
$table->define_baseurl($PAGE->url);
$table->define_columns(array('id', 'studentanswer', 'correctanswer', 'result', 'calcweight'));
$table->define_headers(array(get_string('trackid', 'scorm'), get_string('response', 'scorm'),
get_string('rightanswer', 'scorm'), get_string('result', 'scorm'),
get_string('calculatedweight', 'scorm')));
$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
$table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$table->setup();
for ($i = 0; $i < $questioncount; $i++) {
$row = array();
$element = 'cmi.interactions_'.$i.'.id';
if (isset($usertrack->$element)) {
$row[] = s($usertrack->$element);
$element = 'cmi.interactions_'.$i.'.student_response';
if (isset($usertrack->$element)) {
$row[] = s($usertrack->$element);
} else {
$row[] = '&nbsp;';
}
$j = 0;
$element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
$rightans = '';
if (isset($usertrack->$element)) {
while (isset($usertrack->$element)) {
if ($j > 0) {
$rightans .= ',';
}
$rightans .= s($usertrack->$element);
$j++;
$element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
}
$row[] = $rightans;
} else {
$row[] = '&nbsp;';
}
$element = 'cmi.interactions_'.$i.'.result';
$weighting = 'cmi.interactions_'.$i.'.weighting';
if (isset($usertrack->$element)) {
$row[] = s($usertrack->$element);
if ($usertrack->$element == 'correct' &&
isset($usertrack->$weighting)) {
$row[] = s($usertrack->$weighting);
} else {
$row[] = '0';
}
} else {
$row[] = '&nbsp;';
}
$table->add_data($row);
}
}
$table->finish_output();
if (!$table->is_downloading()) {
echo $OUTPUT->footer();
}
+172
View File
@@ -0,0 +1,172 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page displays the user data from a single attempt
*
* @package mod_scorm
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../../config.php");
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
require_once($CFG->libdir.'/tablelib.php');
$id = required_param('id', PARAM_INT); // Course Module ID.
$userid = required_param('user', PARAM_INT); // User ID.
$scoid = required_param('scoid', PARAM_INT); // SCO ID.
$mode = required_param('mode', PARAM_ALPHA); // Scorm mode.
$attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
$download = optional_param('download', '', PARAM_ALPHA);
// Building the url to use for links.+ data details buildup.
$url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $id,
'user' => $userid,
'attempt' => $attempt,
'scoid' => $scoid,
'mode' => $mode));
$cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid), implode(',', \core_user\fields::get_picture_fields()), MUST_EXIST);
$selsco = $DB->get_record('scorm_scoes', array('id' => $scoid), '*', MUST_EXIST);
$PAGE->set_url($url);
// END of url setting + data buildup.
// Checking login +logging +getting context.
require_login($course, false, $cm);
$contextmodule = context_module::instance($cm->id);
require_capability('mod/scorm:viewreport', $contextmodule);
// Check user has group access.
if (!groups_user_groups_visible($course, $userid, $cm)) {
throw new moodle_exception('nopermissiontoshow');
}
// Trigger a tracks viewed event.
$event = \mod_scorm\event\tracks_viewed::create(array(
'context' => $contextmodule,
'relateduserid' => $userid,
'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id, 'scoid' => $scoid, 'mode' => $mode)
));
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('scorm', $scorm);
$event->trigger();
// Print the page header.
$strreport = get_string('report', 'scorm');
$strattempt = get_string('attempt', 'scorm');
$PAGE->set_title("$course->shortname: ".format_string($scorm->name));
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
$PAGE->navbar->add("$strattempt $attempt - ".fullname($user),
new moodle_url('/mod/scorm/report/userreport.php', array('id' => $id, 'user' => $userid, 'attempt' => $attempt)));
$PAGE->navbar->add($selsco->title . ' - '. get_string('details', 'scorm'));
$PAGE->set_secondary_active_tab('scormreport');
if ($trackdata = scorm_get_tracks($selsco->id, $userid, $attempt)) {
if ($trackdata->status == '') {
$trackdata->status = 'notattempted';
}
} else {
$trackdata = new stdClass();
$trackdata->status = 'notattempted';
$trackdata->total_time = '';
}
$courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id)));
$exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('details', 'scorm');
$table = new flexible_table('mod_scorm-userreporttracks');
if (!$table->is_downloading($download, $exportfilename)) {
$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);
echo $OUTPUT->header();
$currenttab = '';
$renderer = $PAGE->get_renderer('mod_scorm');
$useractionreport = new \mod_scorm\output\userreportsactionbar($id, $userid, $attempt, 'attempt', $mode, $scoid);
echo $renderer->user_report_actionbar($useractionreport);
echo $OUTPUT->box_start('generalbox boxaligncenter');
echo $OUTPUT->heading("$strattempt $attempt - ". fullname($user).': '.
format_string($selsco->title). ' - '. get_string('details', 'scorm'), 3);
}
$table->define_baseurl($PAGE->url);
$table->define_columns(array('element', 'value'));
$table->define_headers(array(get_string('element', 'scorm'), get_string('value', 'scorm')));
$table->set_attribute('class', 'generaltable generalbox boxaligncenter scormtrackreport');
$table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$table->setup();
foreach ($trackdata as $element => $value) {
if (substr($element, 0, 3) == 'cmi') {
$existelements = true;
$row = array();
$string = false;
if (stristr($element, '.id') !== false) {
$string = "trackid";
} else if (stristr($element, '.result') !== false) {
$string = "trackresult";
} else if (stristr($element, '.student_response') !== false or // SCORM 1.2 value.
stristr($element, '.learner_response') !== false) { // SCORM 2004 value.
$string = "trackresponse";
} else if (stristr($element, '.type') !== false) {
$string = "tracktype";
} else if (stristr($element, '.weighting') !== false) {
$string = "trackweight";
} else if (stristr($element, '.time') !== false) {
$string = "tracktime";
} else if (stristr($element, '.correct_responses._count') !== false) {
$string = "trackcorrectcount";
} else if (stristr($element, '.score.min') !== false) {
$string = "trackscoremin";
} else if (stristr($element, '.score.max') !== false) {
$string = "trackscoremax";
} else if (stristr($element, '.score.raw') !== false) {
$string = "trackscoreraw";
} else if (stristr($element, '.latency') !== false) {
$string = "tracklatency";
} else if (stristr($element, '.pattern') !== false) {
$string = "trackpattern";
} else if (stristr($element, '.suspend_data') !== false) {
$string = "tracksuspenddata";
}
if (empty($string) || $table->is_downloading()) {
$row[] = s($element);
} else {
$row[] = s($element) . $OUTPUT->help_icon($string, 'scorm');
}
if (strpos($element, '_time') === false) {
$row[] = s($value);
} else {
$row[] = s(scorm_format_duration($value));
}
$table->add_data($row);
}
}
$table->finish_output();
if (!$table->is_downloading()) {
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
}