Permalink
Browse files

MDL-27523 SCORM move plugin links to tabs page and only show if more …

…than one plugin is installed, move delete attempts code into plugin as it may not be supported in all plugins, general tidy up - good work Ankit!
  • Loading branch information...
1 parent 62b82cb commit b2614417a5c9a1a03dabc6f0a131a7004bfe539b @danmarsden danmarsden committed Jul 11, 2011
@@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * 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}
View
@@ -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,14 +51,18 @@
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)) {
$noheader = true;
}
/// 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 '<div class="plugin">';
- echo $html;
- echo '</div>';
- }
- }
-//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
@@ -15,12 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * 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';
@@ -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 '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) .
- '" onsubmit="return confirm(\''.$strreallydel.'\');">';
+ echo '<form id="attemptsform" method="post" action="' . $PAGE->url .
+ '" onsubmit="return confirm(\''.$strreallydel.'\');">';
echo '<input type="hidden" name="action" value="delete"/>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<div style="display: none;">';
- echo html_writer::input_hidden_params($reporturlwithdisplayoptions);
+ echo html_writer::input_hidden_params($PAGE->url);
echo '</div>';
echo '<div>';
}
@@ -485,21 +486,25 @@ function display($scorm, $cm, $course, $attemptids, $action, $download) {
if (!empty($attempts)) {
echo '<table class="boxaligncenter"><tr>';
echo '<td>';
- 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 "</td>\n";
echo '<td>';
- 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 "</td>\n";
echo '<td>';
- 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 "</td>\n";
echo "<td>";
echo "</td>\n";
echo '</tr></table>';
}
}
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 = '<p>';
- $return.= '<a href="'.$CFG->wwwroot.'/mod/scorm/report.php?mode=basic&id='.$id.'">'.get_string('pluginname', 'scorm_basic').'</a>';
- $return.= '</p>';
- 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;
}
@@ -25,4 +25,5 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 0.3;
+$plugin->version = 2011071100;
+$plugin->requires = 2011070800;
@@ -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;
- }
}
@@ -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;
}
@@ -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);
//-------------------------------------------------------------------------------
Oops, something went wrong.

0 comments on commit b261441

Please sign in to comment.