diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index 001315a31b227..2a3f6afead490 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Strings for component 'scorm', language 'en', branch 'MOODLE_20_STABLE' + * Strings for component 'scorm', language 'en' * * @package scorm * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} diff --git a/mod/scorm/report.php b/mod/scorm/report.php index c9e71a4ae8cc2..ca6618f77903c 100644 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -22,24 +22,18 @@ require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php'); require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php'); require_once($CFG->libdir.'/formslib.php'); -include_once("report/default.php"); // Parent class +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); define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2); $id = required_param('id', PARAM_INT);// Course Module ID, or - -$action = optional_param('action', '', PARAM_ALPHA); -$attemptids = optional_param('attemptid', array(), PARAM_RAW); $download = optional_param('download', '', PARAM_RAW); $mode = optional_param('mode', '', PARAM_ALPHA); // Report mode $url = new moodle_url('/mod/scorm/report.php'); -if ($action !== '') { - $url->param('action', $action); -} if ($mode !== '') { $url->param('mode', $mode); } @@ -48,7 +42,7 @@ $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); $scorm = $DB->get_record('scorm', array('id'=>$cm->instance), '*', MUST_EXIST); - + $PAGE->set_url($url); require_login($course->id, false, $cm); @@ -57,6 +51,11 @@ require_capability('mod/scorm:viewreport', $contextmodule); +$reportlist = scorm_report_list($contextmodule); +if (count($reportlist) < 1) { + print_error('erroraccessingreport', 'scorm'); +} + add_to_log($course->id, 'scorm', 'report', 'report.php?id='.$cm->id, $scorm->id, $cm->id); $userdata = null; if (!empty($download)) { @@ -64,7 +63,6 @@ } /// Print the page header if (empty($noheader)) { - $strreport = get_string('report', 'scorm'); $strattempt = get_string('attempt', 'scorm'); @@ -78,51 +76,16 @@ echo $OUTPUT->heading(format_string($scorm->name)); } -if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { - if (scorm_delete_responses($attemptids, $scorm)) { //delete responses. - add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id); - echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); - } -} -$reportlist = scorm_report_list($contextmodule); -if (count($reportlist)==0){ - print_error('erroraccessingreport', 'scorm'); -} - if (empty($mode)) { -// Default to listing of plugins. - foreach ($reportlist as $reportname) { - $reportclassname = "scorm_{$reportname}_report"; - $report = new $reportclassname(); - $html = $report->canview($id,$contextmodule); - if (!empty($html)) { - echo '
'; - echo $html; - echo '
'; - } - } -//end of default mode condition. -} else if (!in_array($mode, $reportlist)){ + $mode = reset($reportlist); +} else if (!in_array($mode, $reportlist)) { print_error('erroraccessingreport', 'scorm'); } -// Open the selected Scorm report and display it -// DISPLAY PLUGIN REPORT -if(!empty($mode)) -{ - $reportclassname = "scorm_{$mode}_report"; - if (!class_exists($reportclassname)) { - print_error('reportnotfound', 'scorm', '', $mode); - } - $report = new $reportclassname(); - - if (!$report->display($scorm, $cm, $course, $attemptids, $action, $download)) { // Run the report! - print_error("preprocesserror", 'scorm'); - } - if (!$report->settings($scorm, $cm, $course)) { // Run the report! - print_error("preprocesserror", 'scorm'); - } -} +// Open the selected Scorm report and display it +$reportclassname = "scorm_{$mode}_report"; +$report = new $reportclassname(); +$report->display($scorm, $cm, $course, $download); // Run the report! // Print footer diff --git a/mod/scorm/report/basic/lang/en/scorm_basic.php b/mod/scorm/report/basic/lang/en/scorm_basic.php index 8d89e6333ef8d..76eb35a8ef4b7 100644 --- a/mod/scorm/report/basic/lang/en/scorm_basic.php +++ b/mod/scorm/report/basic/lang/en/scorm_basic.php @@ -15,12 +15,12 @@ // along with Moodle. If not, see . /** - * Strings for component 'scorm_basic', language 'en', branch 'MOODLE_20_STABLE' + * Strings for component 'scorm_basic' report plugin * * @package scorm_basic * @author Ankit Kumar Agarwal * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['pluginname'] = 'Basic Reporting'; +$string['pluginname'] = 'Basic Report'; diff --git a/mod/scorm/report/basic/report.php b/mod/scorm/report/basic/report.php index 5cc7b548aa552..836eb56096674 100644 --- a/mod/scorm/report/basic/report.php +++ b/mod/scorm/report/basic/report.php @@ -20,29 +20,35 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.');// It must be included from a Moodle page -} +defined('MOODLE_INTERNAL') || die(); + class scorm_basic_report extends scorm_default_report { /** - * Displays the 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 */ - function display($scorm, $cm, $course, $attemptids, $action, $download) { - global $CFG, $DB, $OUTPUT; + function display($scorm, $cm, $course, $download) { + global $CFG, $DB, $OUTPUT, $PAGE; $contextmodule= get_context_instance(CONTEXT_MODULE, $cm->id); + $action = optional_param('action', '', PARAM_ALPHA); + $attemptids = optional_param('attemptid', array(), PARAM_RAW); - // No options, show the global scorm report - $pageoptions = array(); - $pageoptions['id'] = $cm->id; - $pageoptions['mode'] = "basic"; - $reporturl = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $pageoptions); + if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { + if (scorm_delete_responses($attemptids, $scorm)) { //delete responses. + add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id); + echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); + } + } // detailed report - $mform = new mod_scorm_report_settings( $reporturl, compact('currentgroup') ); + $mform = new mod_scorm_report_settings($PAGE->url, compact('currentgroup')); if ($fromform = $mform->get_data()) { $detailedrep = $fromform->detailedrep; $pagesize = $fromform->pagesize; - $attemptsmode = $fromform->attemptsmode; + $attemptsmode = !empty($fromform->attemptsmode) ? $fromform->attemptsmode : SCORM_REPORT_ATTEMPTS_ALL_STUDENTS; set_user_preference('scorm_report_detailed', $detailedrep); set_user_preference('scorm_report_pagesize', $pagesize); } else { @@ -55,15 +61,10 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) { } // select group menu - $displayoptions = array(); - $displayoptions['id'] = $cm->id; - $displayoptions['mode'] = "basic"; - $displayoptions['attemptsmode'] = $attemptsmode; - $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $displayoptions); - + $PAGE->url->param('attemptsmode', $attemptsmode); if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if (!$download) { - groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out()); + groups_print_activity_menu($cm, $PAGE->url); } } @@ -141,7 +142,7 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) { $table->define_columns($columns); $table->define_headers($headers); - $table->define_baseurl($reporturlwithdisplayoptions->out()); + $table->define_baseurl($PAGE->url); $table->sortable(true); $table->collapsible(true); @@ -338,12 +339,12 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) { if ($candelete) { // Start form $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm')); - echo '
'; + echo ''; echo ''; echo ''; echo '
'; - echo html_writer::input_hidden_params($reporturlwithdisplayoptions); + echo html_writer::input_hidden_params($PAGE->url); echo '
'; echo '
'; } @@ -485,13 +486,17 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) { if (!empty($attempts)) { echo ''; echo '\n"; echo '\n"; echo '\n"; echo "\n"; @@ -499,7 +504,7 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) { } } if (!$download) { - $mform->set_data($displayoptions + compact('detailedrep', 'pagesize')); + $mform->set_data(compact('detailedrep', 'pagesize')); $mform->display(); } } else { @@ -514,15 +519,16 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) { } else { echo $OUTPUT->notification(get_string('noactivity', 'scorm')); } - return 1; }// function ends - function canview($id, $contextmodule) { - global $CFG; - if (has_capability('mod/scorm:viewreport', $contextmodule)) { - $return = '

'; - $return.= ''.get_string('pluginname', 'scorm_basic').''; - $return.= '

'; - return $return; + + /** + * only users with mod/scorm:viewreport can see this plugin. + * @param stdclass $context - context object + * @return boolean + */ + function canview($context) { + if (has_capability('mod/scorm:viewreport', $context)) { + return true; } return false; } diff --git a/mod/scorm/report/basic/version.php b/mod/scorm/report/basic/version.php index 61c67d0a799d2..5612b98bdad23 100644 --- a/mod/scorm/report/basic/version.php +++ b/mod/scorm/report/basic/version.php @@ -25,4 +25,5 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 0.3; +$plugin->version = 2011071100; +$plugin->requires = 2011070800; diff --git a/mod/scorm/report/default.php b/mod/scorm/report/default.php index 049df81c8fcac..12481ac349747 100644 --- a/mod/scorm/report/default.php +++ b/mod/scorm/report/default.php @@ -30,18 +30,25 @@ /// to itself - all these will also be globally available. //////////////////////////////////////////////////////////////////// -class scorm_default_report { +defined('MOODLE_INTERNAL') || die(); - function display($scorm, $cm, $course, $attemptids, $action, $download) { +class scorm_default_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 + */ + function display($scorm, $cm, $course, $download) { /// This function just displays the report return true; } - function settings($cm, $course, $quiz) { - /// This function just displays the settings + /** + * allows the plugin to control who can see this plugin. + * @return boolean + */ + function canview($contextmodule) { return true; } - function canview($id, $contextmodule) { - /// This function just displays the settings - return false; - } } diff --git a/mod/scorm/report/reportlib.php b/mod/scorm/report/reportlib.php index ef5746d688fa5..34783f499b4d7 100644 --- a/mod/scorm/report/reportlib.php +++ b/mod/scorm/report/reportlib.php @@ -16,28 +16,33 @@ /** * Returns an array of reports to which are currently readable. - * @package scorm_basic + * @package scorm * @author Ankit Kumar Agarwal * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + function scorm_report_list($context) { - global $DB; - static $reportlist = null; - if (!is_null($reportlist)) { + global $CFG; + static $reportlist; + if (!empty($reportlist)) { return $reportlist; } $reportdirs = get_plugin_list('scorm'); - $reportcaps = array(); foreach ($reportdirs as $reportname => $notused) { - $pluginfile = 'report/'.$reportname.'/report.php'; + $pluginfile = $CFG->dirroot.'/mod/scorm/report/'.$reportname.'/report.php'; if (is_readable($pluginfile)) { include_once($pluginfile); $reportclassname = "scorm_{$reportname}_report"; if (class_exists($reportclassname)) { - $reportcaps[] = $reportname; + $report = new $reportclassname(); + + if ($report->canview($context)) { + $reportlist[] = $reportname; + } } } } - return $reportcaps; + return $reportlist; } diff --git a/mod/scorm/reportsettings_form.php b/mod/scorm/reportsettings_form.php index 61ed1dc4da918..f01eea4c1ddff 100644 --- a/mod/scorm/reportsettings_form.php +++ b/mod/scorm/reportsettings_form.php @@ -28,11 +28,12 @@ function definition() { $mform->addElement('header', 'preferencespage', get_string('preferencespage', 'scorm')); $options = array(); + /*Group support is broken - see MDL-28282 if ($this->_customdata['currentgroup'] || $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); //------------------------------------------------------------------------------- diff --git a/mod/scorm/tabs.php b/mod/scorm/tabs.php index da25a91419607..8ef0bc285e828 100644 --- a/mod/scorm/tabs.php +++ b/mod/scorm/tabs.php @@ -15,12 +15,12 @@ // along with Moodle. If not, see . /** -* Sets up the tabs used by the scorm pages based on the users capabilities. -* -* @author Dan Marsden and others. -* @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* @package scorm -*/ + * Sets up the tabs used by the scorm pages based on the users capabilities. + * + * @author Dan Marsden and others. + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package scorm + */ if (empty($scorm)) { error('You cannot call this script in that way'); @@ -32,7 +32,6 @@ $cm = get_coursemodule_from_instance('scorm', $scorm->id); } - $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id); $tabs = array(); @@ -53,4 +52,12 @@ $tabs[] = $row; } +if ($currenttab == 'reports' && !empty($reportlist) && count($reportlist) > 1) { + $row2 = array(); + foreach ($reportlist as $rep) { + $row2[] = new tabobject('scorm_'.$rep, $CFG->wwwroot."/mod/scorm/report.php?id=$cm->id&mode=$rep", get_string('pluginname', 'scorm_'.$rep)); + } + $tabs[] = $row2; +} + print_tabs($tabs, $currenttab, $inactive, $activated);
'; - echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'ODS')), get_string('downloadods')); + $PAGE->url->param('download', 'ODS'); + echo $OUTPUT->single_button($PAGE->url, get_string('downloadods')); echo "'; - echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'Excel')), get_string('downloadexcel')); + $PAGE->url->param('download', 'Excel'); + echo $OUTPUT->single_button($PAGE->url, get_string('downloadexcel')); echo "'; - echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'CSV')), get_string('downloadtext')); + $PAGE->url->param('download', 'CSV'); + echo $OUTPUT->single_button($PAGE->url, get_string('downloadtext')); + $PAGE->url->param('download', ''); echo ""; echo "