diff --git a/mod/scorm/report/default.php b/mod/scorm/classes/report.php similarity index 95% rename from mod/scorm/report/default.php rename to mod/scorm/classes/report.php index 97b7235f640..60be5f32929 100644 --- a/mod/scorm/report/default.php +++ b/mod/scorm/classes/report.php @@ -19,11 +19,13 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_scorm; + /*******************************************************************/ // Default class for Scorm plugins // // Doesn't do anything on it's own -- it needs to be extended. -// This class displays scorm reports. Because it is called from +// This class displays scorm reports. Because it is called from // within /mod/scorm/report.php you can assume that the page header // and footer are taken care of. // @@ -33,7 +35,7 @@ defined('MOODLE_INTERNAL') || die(); -class scorm_default_report { +class report { /** * displays the full report * @param stdClass $scorm full SCORM object diff --git a/mod/scorm/db/renamedclasses.php b/mod/scorm/db/renamedclasses.php new file mode 100644 index 00000000000..9754028470d --- /dev/null +++ b/mod/scorm/db/renamedclasses.php @@ -0,0 +1,40 @@ +. + +/** + * This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader. + * + * Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a + * close structure, OR where lots of classes get included and not necessarily used, or checked for often. + * + * When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that + * component. + * This way we don't need to keep around old classes, instead creating aliases only when required. + * One big advantage to this method is that we provide consistent debugging for renamed classes when they are used. + * + * @package mod_scorm + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// Like other files in the db directory this file uses an array. +// The old class name is the key, the new class name is the value. +// The array must be called $renamedclasses. +$renamedclasses = array( + 'scorm_default_report' => 'mod_scorm\report' +); diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 3c6d647d080..593589c698c 100644 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -22,7 +22,7 @@ require_once($CFG->dirroot.'/mod/scorm/locallib.php'); require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php'); require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php'); require_once($CFG->libdir.'/formslib.php'); -require_once($CFG->dirroot.'/mod/scorm/report/default.php'); // Parent class. + define('SCORM_REPORT_DEFAULT_PAGE_SIZE', 20); define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0); define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1); @@ -91,8 +91,9 @@ if (empty($noheader)) { } // Open the selected Scorm report and display it. -$reportclassname = "scorm_{$mode}_report"; -$report = new $reportclassname(); +$classname = "scormreport_{$mode}\\report"; +$legacyclassname = "scorm_{$mode}_report"; +$report = class_exists($classname) ? new $classname() : new $legacyclassname(); $report->display($scorm, $cm, $course, $download); // Run the report! // Print footer. diff --git a/mod/scorm/report/basic/report.php b/mod/scorm/report/basic/classes/report.php similarity index 82% rename from mod/scorm/report/basic/report.php rename to mod/scorm/report/basic/classes/report.php index 6e7035764ee..3ad99807ab1 100644 --- a/mod/scorm/report/basic/report.php +++ b/mod/scorm/report/basic/classes/report.php @@ -21,25 +21,27 @@ * @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 scorm_basic_report extends scorm_default_report { +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 \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); + $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))); + $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. @@ -50,7 +52,7 @@ class scorm_basic_report extends scorm_default_report { $currentgroup = groups_get_activity_group($cm, true); // Detailed report. - $mform = new mod_scorm_report_settings($PAGE->url, compact('currentgroup')); + $mform = new \mod_scorm_report_settings($PAGE->url, compact('currentgroup')); if ($fromform = $mform->get_data()) { $detailedrep = $fromform->detailedrep; $pagesize = $fromform->pagesize; @@ -69,7 +71,7 @@ class scorm_basic_report extends scorm_default_report { $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)); + groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions)); } } @@ -104,7 +106,7 @@ class scorm_basic_report extends scorm_default_report { if ( !$nostudents ) { // Now check if asked download of data. - $coursecontext = context_course::instance($course->id); + $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)); @@ -149,7 +151,7 @@ class scorm_basic_report extends scorm_default_report { } if (!$download) { - $table = new flexible_table('mod-scorm-report'); + $table = new \flexible_table('mod-scorm-report'); $table->define_columns($columns); $table->define_headers($headers); @@ -194,7 +196,7 @@ class scorm_basic_report extends scorm_default_report { $filename .= ".ods"; // Creating a workbook. - $workbook = new MoodleODSWorkbook("-"); + $workbook = new \MoodleODSWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. @@ -233,7 +235,7 @@ class scorm_basic_report extends scorm_default_report { $filename .= ".xls"; // Creating a workbook. - $workbook = new MoodleExcelWorkbook("-"); + $workbook = new \MoodleExcelWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. @@ -267,7 +269,7 @@ class scorm_basic_report extends scorm_default_report { } $rownum = 1; } else if ($download == 'CSV') { - $csvexport = new csv_export_writer("tab"); + $csvexport = new \csv_export_writer("tab"); $csvexport->set_filename($filename, ".txt"); $csvexport->add_data($headers); } @@ -276,7 +278,7 @@ class scorm_basic_report extends scorm_default_report { // Construct the SQL. $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . - user_picture::fields('u', array('idnumber'), 'userid') . + \user_picture::fields('u', array('idnumber'), 'userid') . get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' '; // This part is the same for all cases - join users and scorm_scoes_track tables. @@ -334,7 +336,7 @@ class scorm_basic_report extends scorm_default_report { $table->pagesize($pagesize, $total); - echo html_writer::start_div('scormattemptcounts'); + echo \html_writer::start_div('scormattemptcounts'); if ( $count->nbresults == $count->nbattempts ) { echo get_string('reportcountattempts', 'scorm', $count); } else if ( $count->nbattempts > 0 ) { @@ -342,26 +344,26 @@ class scorm_basic_report extends scorm_default_report { } else { echo $count->nbusers.' '.get_string('users'); } - echo html_writer::end_div(); + 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')); + 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', + 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(); + 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 { @@ -378,21 +380,21 @@ class scorm_basic_report extends scorm_default_report { } if (in_array('checkbox', $columns)) { if ($candelete && !empty($timetracks->start)) { - $row[] = html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); + $row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); } else if ($candelete) { $row[] = ''; } } if (in_array('picture', $columns)) { - $user = new stdClass(); - $additionalfields = explode(',', user_picture::fields()); + $user = new \stdClass(); + $additionalfields = explode(',', \user_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)); + $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); } @@ -406,11 +408,9 @@ class scorm_basic_report extends scorm_default_report { $row[] = '-'; } else { if (!$download) { - $url = new moodle_url('/mod/scorm/report/userreport.php', - array('id' => $cm->id, - 'user' => $scouser->userid, - 'attempt' => $scouser->attempt)); - $row[] = html_writer::link($url, $scouser->attempt); + $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, + 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; } @@ -452,11 +452,11 @@ class scorm_basic_report extends scorm_default_report { $score = $strstatus; } if (!$download) { - $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, + $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); - $row[] = html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, - array('title' => $strstatus)) . html_writer::empty_tag('br') . - html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); + $row[] = \html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, + array('title' => $strstatus)) . \html_writer::empty_tag('br') . + \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { $row[] = $score; } @@ -464,8 +464,8 @@ class scorm_basic_report extends scorm_default_report { // If we don't have track data, we haven't attempted yet. $strstatus = get_string('notattempted', 'scorm'); if (!$download) { - $row[] = html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, - array('title' => $strstatus)).html_writer::empty_tag('br').$strstatus; + $row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, + array('title' => $strstatus)).\html_writer::empty_tag('br').$strstatus; } else { $row[] = $strstatus; } @@ -490,50 +490,50 @@ class scorm_basic_report extends scorm_default_report { 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 html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', + echo \html_writer::start_tag('table', array('id' => 'commands')); + echo \html_writer::start_tag('tr').\html_writer::start_tag('td'); + echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')).' / '; - echo html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', + echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm')); echo '  '; - echo html_writer::empty_tag('input', array('type' => 'submit', + echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'quiz_overview'))); - echo html_writer::end_tag('td').html_writer::end_tag('tr').html_writer::end_tag('table'); + 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'); + echo \html_writer::end_tag('div'); + echo \html_writer::end_tag('form'); } - echo html_writer::end_div(); + echo \html_writer::end_div(); if (!empty($attempts)) { - echo html_writer::start_tag('table', array('class' => 'boxaligncenter')).html_writer::start_tag('tr'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo html_writer::end_tag('td'); - echo html_writer::end_tag('tr').html_writer::end_tag('table'); + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo \html_writer::end_tag('td'); + echo \html_writer::end_tag('tr').\html_writer::end_tag('table'); } } } else { if ($candelete && !$download) { - echo html_writer::end_div(); - echo html_writer::end_tag('form'); + echo \html_writer::end_div(); + echo \html_writer::end_tag('form'); $table->finish_output(); } - echo html_writer::end_div(); + echo \html_writer::end_div(); } // Show preferences form irrespective of attempts are there to report or not. if (!$download) { diff --git a/mod/scorm/report/basic/db/renamedclasses.php b/mod/scorm/report/basic/db/renamedclasses.php new file mode 100644 index 00000000000..f5f7b6c60af --- /dev/null +++ b/mod/scorm/report/basic/db/renamedclasses.php @@ -0,0 +1,40 @@ +. + +/** + * This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader. + * + * Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a + * close structure, OR where lots of classes get included and not necessarily used, or checked for often. + * + * When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that + * component. + * This way we don't need to keep around old classes, instead creating aliases only when required. + * One big advantage to this method is that we provide consistent debugging for renamed classes when they are used. + * + * @package scormreport_basic + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// Like other files in the db directory this file uses an array. +// The old class name is the key, the new class name is the value. +// The array must be called $renamedclasses. +$renamedclasses = array( + 'scorm_basic_report' => 'scormreport_basic\report' +); diff --git a/mod/scorm/report/graphs/report.php b/mod/scorm/report/graphs/classes/report.php similarity index 77% rename from mod/scorm/report/graphs/report.php rename to mod/scorm/report/graphs/classes/report.php index 376bc20b06c..4a4b263c9dd 100644 --- a/mod/scorm/report/graphs/report.php +++ b/mod/scorm/report/graphs/classes/report.php @@ -21,6 +21,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace scormreport_graphs; + defined('MOODLE_INTERNAL') || die(); /** * Main class to control the graphs reporting @@ -30,30 +32,30 @@ defined('MOODLE_INTERNAL') || die(); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scorm_graphs_report extends scorm_default_report { +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 \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 $DB, $OUTPUT, $PAGE; - if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. - groups_print_activity_menu($cm, new moodle_url($PAGE->url)); + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. + groups_print_activity_menu($cm, new \moodle_url($PAGE->url)); } if ($scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id')) { foreach ($scoes as $sco) { if ($sco->launch != '') { - $imageurl = new moodle_url('/mod/scorm/report/graphs/graph.php', + $imageurl = new \moodle_url('/mod/scorm/report/graphs/graph.php', array('scoid' => $sco->id)); $graphname = $sco->title; echo $OUTPUT->heading($graphname, 3); - echo html_writer::tag('div', html_writer::empty_tag('img', + echo \html_writer::tag('div', \html_writer::empty_tag('img', array('src' => $imageurl, 'alt' => $graphname)), array('class' => 'graph')); } diff --git a/mod/scorm/report/graphs/db/renamedclasses.php b/mod/scorm/report/graphs/db/renamedclasses.php new file mode 100644 index 00000000000..de84d931f37 --- /dev/null +++ b/mod/scorm/report/graphs/db/renamedclasses.php @@ -0,0 +1,40 @@ +. + +/** + * This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader. + * + * Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a + * close structure, OR where lots of classes get included and not necessarily used, or checked for often. + * + * When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that + * component. + * This way we don't need to keep around old classes, instead creating aliases only when required. + * One big advantage to this method is that we provide consistent debugging for renamed classes when they are used. + * + * @package scormreport_graph + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// Like other files in the db directory this file uses an array. +// The old class name is the key, the new class name is the value. +// The array must be called $renamedclasses. +$renamedclasses = array( + 'scorm_graph_report' => 'scormreport_graph\report' +); diff --git a/mod/scorm/report/interactions/report.php b/mod/scorm/report/interactions/classes/report.php similarity index 84% rename from mod/scorm/report/interactions/report.php rename to mod/scorm/report/interactions/classes/report.php index 40025d0493d..8e29511669c 100644 --- a/mod/scorm/report/interactions/report.php +++ b/mod/scorm/report/interactions/classes/report.php @@ -21,26 +21,28 @@ * @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 scorm_interactions_report extends scorm_default_report { +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 \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); + $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))); + $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. @@ -51,7 +53,7 @@ class scorm_interactions_report extends scorm_default_report { $currentgroup = groups_get_activity_group($cm, true); // Detailed report. - $mform = new mod_scorm_report_interactions_settings($PAGE->url, compact('currentgroup')); + $mform = new \mod_scorm_report_interactions_settings($PAGE->url, compact('currentgroup')); if ($fromform = $mform->get_data()) { $pagesize = $fromform->pagesize; $includeqtext = $fromform->qtext; @@ -81,10 +83,10 @@ class scorm_interactions_report extends scorm_default_report { $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)); + groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions)); } } - $formattextoptions = array('context' => context_course::instance($course->id)); + $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. @@ -117,7 +119,7 @@ class scorm_interactions_report extends scorm_default_report { } if ( !$nostudents ) { // Now check if asked download of data. - $coursecontext = context_course::instance($course->id); + $coursecontext = \context_course::instance($course->id); if ($download) { $filename = clean_filename("$course->shortname ".format_string($scorm->name, true, $formattextoptions)); } @@ -162,7 +164,7 @@ class scorm_interactions_report extends scorm_default_report { // Construct the SQL. $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . - user_picture::fields('u', array('idnumber'), 'userid') . + \user_picture::fields('u', array('idnumber'), 'userid') . get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' '; // This part is the same for all cases - join users and scorm_scoes_track tables. @@ -205,7 +207,7 @@ class scorm_interactions_report extends scorm_default_report { } if (!$download) { - $table = new flexible_table('mod-scorm-report'); + $table = new \flexible_table('mod-scorm-report'); $table->define_columns($columns); $table->define_headers($headers); @@ -260,7 +262,7 @@ class scorm_interactions_report extends scorm_default_report { $filename .= ".ods"; // Creating a workbook. - $workbook = new MoodleODSWorkbook("-"); + $workbook = new \MoodleODSWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. @@ -299,7 +301,7 @@ class scorm_interactions_report extends scorm_default_report { $filename .= ".xls"; // Creating a workbook. - $workbook = new MoodleExcelWorkbook("-"); + $workbook = new \MoodleExcelWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. @@ -333,7 +335,7 @@ class scorm_interactions_report extends scorm_default_report { } $rownum = 1; } else if ($download == 'CSV') { - $csvexport = new csv_export_writer("tab"); + $csvexport = new \csv_export_writer("tab"); $csvexport->set_filename($filename, ".txt"); $csvexport->add_data($headers); } @@ -370,7 +372,7 @@ class scorm_interactions_report extends scorm_default_report { $table->pagesize($pagesize, $total); - echo html_writer::start_div('scormattemptcounts'); + echo \html_writer::start_div('scormattemptcounts'); if ( $count->nbresults == $count->nbattempts ) { echo get_string('reportcountattempts', 'scorm', $count); } else if ( $count->nbattempts > 0 ) { @@ -378,26 +380,26 @@ class scorm_interactions_report extends scorm_default_report { } else { echo $count->nbusers.' '.get_string('users'); } - echo html_writer::end_div(); + 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')); + 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', + 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(); + 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 { @@ -413,21 +415,21 @@ class scorm_interactions_report extends scorm_default_report { } if (in_array('checkbox', $columns)) { if ($candelete && !empty($timetracks->start)) { - $row[] = html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); + $row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); } else if ($candelete) { $row[] = ''; } } if (in_array('picture', $columns)) { - $user = new stdClass(); - $additionalfields = explode(',', user_picture::fields()); + $user = new \stdClass(); + $additionalfields = explode(',', \user_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)); + $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); } @@ -441,11 +443,11 @@ class scorm_interactions_report extends scorm_default_report { $row[] = '-'; } else { if (!$download) { - $url = new moodle_url('/mod/scorm/report/userreport.php', + $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); - $row[] = html_writer::link($url, $scouser->attempt); + $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; } @@ -480,11 +482,11 @@ class scorm_interactions_report extends scorm_default_report { $score = $strstatus; } if (!$download) { - $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, + $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); - $row[] = html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, - array('title' => $strstatus)) . html_writer::empty_tag('br') . - html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); + $row[] = \html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, + array('title' => $strstatus)) . \html_writer::empty_tag('br') . + \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { $row[] = $score; } @@ -530,8 +532,8 @@ class scorm_interactions_report extends scorm_default_report { // If we don't have track data, we haven't attempted yet. $strstatus = get_string('notattempted', 'scorm'); if (!$download) { - $row[] = html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, - array('title' => $strstatus)).html_writer::empty_tag('br').$strstatus; + $row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, + array('title' => $strstatus)).\html_writer::empty_tag('br').$strstatus; } else { $row[] = $strstatus; } @@ -559,50 +561,50 @@ class scorm_interactions_report extends scorm_default_report { 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 html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', + echo \html_writer::start_tag('table', array('id' => 'commands')); + echo \html_writer::start_tag('tr').\html_writer::start_tag('td'); + echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')).' / '; - echo html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', + echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm')); echo '  '; - echo html_writer::empty_tag('input', array('type' => 'submit', + echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'quiz_overview'))); - echo html_writer::end_tag('td').html_writer::end_tag('tr').html_writer::end_tag('table'); + 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'); + echo \html_writer::end_tag('div'); + echo \html_writer::end_tag('form'); } - echo html_writer::end_div(); + echo \html_writer::end_div(); if (!empty($attempts)) { - echo html_writer::start_tag('table', array('class' => 'boxaligncenter')).html_writer::start_tag('tr'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo html_writer::end_tag('td'); - echo html_writer::end_tag('tr').html_writer::end_tag('table'); + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo \html_writer::end_tag('td'); + echo \html_writer::end_tag('tr').\html_writer::end_tag('table'); } } } else { if ($candelete && !$download) { - echo html_writer::end_div(); - echo html_writer::end_tag('form'); + echo \html_writer::end_div(); + echo \html_writer::end_tag('form'); $table->finish_output(); } - echo html_writer::end_div(); + echo \html_writer::end_div(); } // Show preferences form irrespective of attempts are there to report or not. if (!$download) { diff --git a/mod/scorm/report/interactions/db/renamedclasses.php b/mod/scorm/report/interactions/db/renamedclasses.php new file mode 100644 index 00000000000..203be5c2c61 --- /dev/null +++ b/mod/scorm/report/interactions/db/renamedclasses.php @@ -0,0 +1,40 @@ +. + +/** + * This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader. + * + * Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a + * close structure, OR where lots of classes get included and not necessarily used, or checked for often. + * + * When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that + * component. + * This way we don't need to keep around old classes, instead creating aliases only when required. + * One big advantage to this method is that we provide consistent debugging for renamed classes when they are used. + * + * @package scormreport_interactions + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// Like other files in the db directory this file uses an array. +// The old class name is the key, the new class name is the value. +// The array must be called $renamedclasses. +$renamedclasses = array( + 'scorm_interactions_report' => 'scormreport_objectives\report' +); diff --git a/mod/scorm/report/objectives/report.php b/mod/scorm/report/objectives/classes/report.php similarity index 84% rename from mod/scorm/report/objectives/report.php rename to mod/scorm/report/objectives/classes/report.php index efd4fdda1e1..368bc47b838 100644 --- a/mod/scorm/report/objectives/report.php +++ b/mod/scorm/report/objectives/classes/report.php @@ -21,6 +21,8 @@ * @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'); @@ -31,22 +33,22 @@ require_once($CFG->dirroot.'/mod/scorm/report/objectives/responsessettings_form. * @copyright 2013 Dan Marsden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scorm_objectives_report extends scorm_default_report { +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 \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); + $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))); + $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. @@ -57,7 +59,7 @@ class scorm_objectives_report extends scorm_default_report { $currentgroup = groups_get_activity_group($cm, true); // Detailed report. - $mform = new mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup')); + $mform = new \mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup')); if ($fromform = $mform->get_data()) { $pagesize = $fromform->pagesize; $showobjectivescore = $fromform->objectivescore; @@ -79,10 +81,10 @@ class scorm_objectives_report extends scorm_default_report { $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)); + groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions)); } } - $formattextoptions = array('context' => context_course::instance($course->id)); + $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. @@ -115,7 +117,7 @@ class scorm_objectives_report extends scorm_default_report { } if ( !$nostudents ) { // Now check if asked download of data. - $coursecontext = context_course::instance($course->id); + $coursecontext = \context_course::instance($course->id); if ($download) { $filename = clean_filename("$course->shortname ".format_string($scorm->name, true, $formattextoptions)); } @@ -160,7 +162,7 @@ class scorm_objectives_report extends scorm_default_report { // Construct the SQL. $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . - user_picture::fields('u', array('idnumber'), 'userid') . + \user_picture::fields('u', array('idnumber'), 'userid') . get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' '; // This part is the same for all cases - join users and scorm_scoes_track tables. @@ -215,7 +217,7 @@ class scorm_objectives_report extends scorm_default_report { $emptycell = ''; // Used when an empty cell is being printed - in html we add a space. if (!$download) { $emptycell = ' '; - $table = new flexible_table('mod-scorm-report'); + $table = new \flexible_table('mod-scorm-report'); $table->define_columns($columns); $table->define_headers($headers); @@ -261,7 +263,7 @@ class scorm_objectives_report extends scorm_default_report { $filename .= ".ods"; // Creating a workbook. - $workbook = new MoodleODSWorkbook("-"); + $workbook = new \MoodleODSWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. @@ -300,7 +302,7 @@ class scorm_objectives_report extends scorm_default_report { $filename .= ".xls"; // Creating a workbook. - $workbook = new MoodleExcelWorkbook("-"); + $workbook = new \MoodleExcelWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. @@ -334,7 +336,7 @@ class scorm_objectives_report extends scorm_default_report { } $rownum = 1; } else if ($download == 'CSV') { - $csvexport = new csv_export_writer("tab"); + $csvexport = new \csv_export_writer("tab"); $csvexport->set_filename($filename, ".txt"); $csvexport->add_data($headers); } @@ -371,7 +373,7 @@ class scorm_objectives_report extends scorm_default_report { $table->pagesize($pagesize, $total); - echo html_writer::start_div('scormattemptcounts'); + echo \html_writer::start_div('scormattemptcounts'); if ( $count->nbresults == $count->nbattempts ) { echo get_string('reportcountattempts', 'scorm', $count); } else if ( $count->nbattempts > 0 ) { @@ -379,26 +381,26 @@ class scorm_objectives_report extends scorm_default_report { } else { echo $count->nbusers.' '.get_string('users'); } - echo html_writer::end_div(); + 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')); + 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', + 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(); + 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 { @@ -414,21 +416,21 @@ class scorm_objectives_report extends scorm_default_report { } if (in_array('checkbox', $columns)) { if ($candelete && !empty($timetracks->start)) { - $row[] = html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); + $row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); } else if ($candelete) { $row[] = ''; } } if (in_array('picture', $columns)) { - $user = new stdClass(); - $additionalfields = explode(',', user_picture::fields()); + $user = new \stdClass(); + $additionalfields = explode(',', \user_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)); + $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); } @@ -442,11 +444,9 @@ class scorm_objectives_report extends scorm_default_report { $row[] = '-'; } else { if (!$download) { - $url = new moodle_url('/mod/scorm/report/userreport.php', - array('id' => $cm->id, - 'user' => $scouser->userid, - 'attempt' => $scouser->attempt)); - $row[] = html_writer::link($url, $scouser->attempt); + $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, + 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); + $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; } @@ -482,11 +482,11 @@ class scorm_objectives_report extends scorm_default_report { $score = $strstatus; } if (!$download) { - $url = new moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, + $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); - $row[] = html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, - array('title' => $strstatus)) . html_writer::empty_tag('br') . - html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); + $row[] = \html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, + array('title' => $strstatus)) . \html_writer::empty_tag('br') . + \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { $row[] = $score; } @@ -543,8 +543,8 @@ class scorm_objectives_report extends scorm_default_report { // If we don't have track data, we haven't attempted yet. $strstatus = get_string('notattempted', 'scorm'); if (!$download) { - $row[] = html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, - array('title' => $strstatus)).html_writer::empty_tag('br').$strstatus; + $row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, + array('title' => $strstatus)).\html_writer::empty_tag('br').$strstatus; } else { $row[] = $strstatus; } @@ -572,50 +572,50 @@ class scorm_objectives_report extends scorm_default_report { 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 html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', + echo \html_writer::start_tag('table', array('id' => 'commands')); + echo \html_writer::start_tag('tr').\html_writer::start_tag('td'); + echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')).' / '; - echo html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', + echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm')); echo '  '; - echo html_writer::empty_tag('input', array('type' => 'submit', + echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'quiz_overview'))); - echo html_writer::end_tag('td').html_writer::end_tag('tr').html_writer::end_tag('table'); + 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'); + echo \html_writer::end_tag('div'); + echo \html_writer::end_tag('form'); } - echo html_writer::end_div(); + echo \html_writer::end_div(); if (!empty($attempts)) { - echo html_writer::start_tag('table', array('class' => 'boxaligncenter')).html_writer::start_tag('tr'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')).\html_writer::start_tag('tr'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo $OUTPUT->single_button(new moodle_url($PAGE->url, + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext')); - echo html_writer::end_tag('td'); - echo html_writer::start_tag('td'); - echo html_writer::end_tag('td'); - echo html_writer::end_tag('tr').html_writer::end_tag('table'); + echo \html_writer::end_tag('td'); + echo \html_writer::start_tag('td'); + echo \html_writer::end_tag('td'); + echo \html_writer::end_tag('tr').\html_writer::end_tag('table'); } } } else { if ($candelete && !$download) { - echo html_writer::end_div(); - echo html_writer::end_tag('form'); + echo \html_writer::end_div(); + echo \html_writer::end_tag('form'); $table->finish_output(); } - echo html_writer::end_div(); + echo \html_writer::end_div(); } // Show preferences form irrespective of attempts are there to report or not. if (!$download) { diff --git a/mod/scorm/report/objectives/db/renamedclasses.php b/mod/scorm/report/objectives/db/renamedclasses.php new file mode 100644 index 00000000000..054f278204e --- /dev/null +++ b/mod/scorm/report/objectives/db/renamedclasses.php @@ -0,0 +1,40 @@ +. + +/** + * This file contains mappings for classes that have been renamed so that they meet the requirements of the autoloader. + * + * Renaming isn't always the recommended approach, but can provide benefit in situations where we've already got a + * close structure, OR where lots of classes get included and not necessarily used, or checked for often. + * + * When renaming a class delete the original class and add an entry to the db/renamedclasses.php directory for that + * component. + * This way we don't need to keep around old classes, instead creating aliases only when required. + * One big advantage to this method is that we provide consistent debugging for renamed classes when they are used. + * + * @package scormreport_objectives + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// Like other files in the db directory this file uses an array. +// The old class name is the key, the new class name is the value. +// The array must be called $renamedclasses. +$renamedclasses = array( + 'scorm_objectives_report' => 'scormreport_objectives\report' +); diff --git a/mod/scorm/report/reportlib.php b/mod/scorm/report/reportlib.php index 8be75d51667..73c1aaf367a 100644 --- a/mod/scorm/report/reportlib.php +++ b/mod/scorm/report/reportlib.php @@ -36,8 +36,22 @@ function scorm_report_list($context) { } $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)) { diff --git a/mod/scorm/upgrade.txt b/mod/scorm/upgrade.txt index b2f8cdb8aaa..00ea92945ac 100644 --- a/mod/scorm/upgrade.txt +++ b/mod/scorm/upgrade.txt @@ -4,3 +4,5 @@ This files describes API changes in the mod_scorm code. * Coding style fixes. A large number of coding style issues were fixed in MDL-45887. This means any local modifications to mod_scorm are likely to conflict. + +* All scorm report plugins should use namespaced classnames now. Refer MDL-46469 for details.