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!

This commit is contained in:
Dan Marsden 2011-07-11 12:29:42 +12:00
parent 62b82cbcff
commit b2614417a5
9 changed files with 104 additions and 114 deletions

View File

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // 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 * @package scorm
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}

View File

@ -22,24 +22,18 @@ require_once($CFG->dirroot.'/mod/scorm/locallib.php');
require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php'); require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php');
require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php'); require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php');
require_once($CFG->libdir.'/formslib.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_DEFAULT_PAGE_SIZE', 20);
define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0); define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0);
define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1); define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1);
define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2); define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2);
$id = required_param('id', PARAM_INT);// Course Module ID, or $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); $download = optional_param('download', '', PARAM_RAW);
$mode = optional_param('mode', '', PARAM_ALPHA); // Report mode $mode = optional_param('mode', '', PARAM_ALPHA); // Report mode
$url = new moodle_url('/mod/scorm/report.php'); $url = new moodle_url('/mod/scorm/report.php');
if ($action !== '') {
$url->param('action', $action);
}
if ($mode !== '') { if ($mode !== '') {
$url->param('mode', $mode); $url->param('mode', $mode);
} }
@ -48,7 +42,7 @@ $url->param('id', $id);
$cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST); $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
$scorm = $DB->get_record('scorm', array('id'=>$cm->instance), '*', MUST_EXIST); $scorm = $DB->get_record('scorm', array('id'=>$cm->instance), '*', MUST_EXIST);
$PAGE->set_url($url); $PAGE->set_url($url);
require_login($course->id, false, $cm); require_login($course->id, false, $cm);
@ -57,6 +51,11 @@ $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/scorm:viewreport', $contextmodule); 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); add_to_log($course->id, 'scorm', 'report', 'report.php?id='.$cm->id, $scorm->id, $cm->id);
$userdata = null; $userdata = null;
if (!empty($download)) { if (!empty($download)) {
@ -64,7 +63,6 @@ if (!empty($download)) {
} }
/// Print the page header /// Print the page header
if (empty($noheader)) { if (empty($noheader)) {
$strreport = get_string('report', 'scorm'); $strreport = get_string('report', 'scorm');
$strattempt = get_string('attempt', 'scorm'); $strattempt = get_string('attempt', 'scorm');
@ -78,51 +76,16 @@ if (empty($noheader)) {
echo $OUTPUT->heading(format_string($scorm->name)); 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)) { if (empty($mode)) {
// Default to listing of plugins. $mode = reset($reportlist);
foreach ($reportlist as $reportname) { } else if (!in_array($mode, $reportlist)) {
$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)){
print_error('erroraccessingreport', 'scorm'); print_error('erroraccessingreport', 'scorm');
} }
// Open the selected Scorm report and display it
// DISPLAY PLUGIN REPORT // Open the selected Scorm report and display it
if(!empty($mode)) $reportclassname = "scorm_{$mode}_report";
{ $report = new $reportclassname();
$reportclassname = "scorm_{$mode}_report"; $report->display($scorm, $cm, $course, $download); // Run the 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');
}
}
// Print footer // Print footer

View File

@ -15,12 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // 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 * @package scorm_basic
* @author Ankit Kumar Agarwal * @author Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$string['pluginname'] = 'Basic Reporting'; $string['pluginname'] = 'Basic Report';

View File

@ -20,29 +20,35 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
if (!defined('MOODLE_INTERNAL')) { defined('MOODLE_INTERNAL') || die();
die('Direct access to this script is forbidden.');// It must be included from a Moodle page
}
class scorm_basic_report extends scorm_default_report { 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) { function display($scorm, $cm, $course, $download) {
global $CFG, $DB, $OUTPUT; global $CFG, $DB, $OUTPUT, $PAGE;
$contextmodule= get_context_instance(CONTEXT_MODULE, $cm->id); $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 if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
$pageoptions = array(); if (scorm_delete_responses($attemptids, $scorm)) { //delete responses.
$pageoptions['id'] = $cm->id; add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
$pageoptions['mode'] = "basic"; echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
$reporturl = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $pageoptions); }
}
// detailed report // 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()) { if ($fromform = $mform->get_data()) {
$detailedrep = $fromform->detailedrep; $detailedrep = $fromform->detailedrep;
$pagesize = $fromform->pagesize; $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_detailed', $detailedrep);
set_user_preference('scorm_report_pagesize', $pagesize); set_user_preference('scorm_report_pagesize', $pagesize);
} else { } else {
@ -55,15 +61,10 @@ class scorm_basic_report extends scorm_default_report {
} }
// select group menu // select group menu
$displayoptions = array(); $PAGE->url->param('attemptsmode', $attemptsmode);
$displayoptions['id'] = $cm->id;
$displayoptions['mode'] = "basic";
$displayoptions['attemptsmode'] = $attemptsmode;
$reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $displayoptions);
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if (!$download) { if (!$download) {
groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out()); groups_print_activity_menu($cm, $PAGE->url);
} }
} }
@ -141,7 +142,7 @@ class scorm_basic_report extends scorm_default_report {
$table->define_columns($columns); $table->define_columns($columns);
$table->define_headers($headers); $table->define_headers($headers);
$table->define_baseurl($reporturlwithdisplayoptions->out()); $table->define_baseurl($PAGE->url);
$table->sortable(true); $table->sortable(true);
$table->collapsible(true); $table->collapsible(true);
@ -338,12 +339,12 @@ class scorm_basic_report extends scorm_default_report {
if ($candelete) { if ($candelete) {
// Start form // Start form
$strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm')); $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) . echo '<form id="attemptsform" method="post" action="' . $PAGE->url .
'" onsubmit="return confirm(\''.$strreallydel.'\');">'; '" onsubmit="return confirm(\''.$strreallydel.'\');">';
echo '<input type="hidden" name="action" value="delete"/>'; echo '<input type="hidden" name="action" value="delete"/>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<div style="display: none;">'; echo '<div style="display: none;">';
echo html_writer::input_hidden_params($reporturlwithdisplayoptions); echo html_writer::input_hidden_params($PAGE->url);
echo '</div>'; echo '</div>';
echo '<div>'; echo '<div>';
} }
@ -485,13 +486,17 @@ class scorm_basic_report extends scorm_default_report {
if (!empty($attempts)) { if (!empty($attempts)) {
echo '<table class="boxaligncenter"><tr>'; echo '<table class="boxaligncenter"><tr>';
echo '<td>'; 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>\n";
echo '<td>'; 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>\n";
echo '<td>'; 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>\n";
echo "<td>"; echo "<td>";
echo "</td>\n"; echo "</td>\n";
@ -499,7 +504,7 @@ class scorm_basic_report extends scorm_default_report {
} }
} }
if (!$download) { if (!$download) {
$mform->set_data($displayoptions + compact('detailedrep', 'pagesize')); $mform->set_data(compact('detailedrep', 'pagesize'));
$mform->display(); $mform->display();
} }
} else { } else {
@ -514,15 +519,16 @@ class scorm_basic_report extends scorm_default_report {
} else { } else {
echo $OUTPUT->notification(get_string('noactivity', 'scorm')); echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
} }
return 1;
}// function ends }// function ends
function canview($id, $contextmodule) {
global $CFG; /**
if (has_capability('mod/scorm:viewreport', $contextmodule)) { * only users with mod/scorm:viewreport can see this plugin.
$return = '<p>'; * @param stdclass $context - context object
$return.= '<a href="'.$CFG->wwwroot.'/mod/scorm/report.php?mode=basic&id='.$id.'">'.get_string('pluginname', 'scorm_basic').'</a>'; * @return boolean
$return.= '</p>'; */
return $return; function canview($context) {
if (has_capability('mod/scorm:viewreport', $context)) {
return true;
} }
return false; return false;
} }

View File

@ -25,4 +25,5 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 0.3; $plugin->version = 2011071100;
$plugin->requires = 2011070800;

View File

@ -30,18 +30,25 @@
/// to itself - all these will also be globally available. /// 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 /// This function just displays the report
return true; 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; return true;
} }
function canview($id, $contextmodule) {
/// This function just displays the settings
return false;
}
} }

View File

@ -16,28 +16,33 @@
/** /**
* Returns an array of reports to which are currently readable. * Returns an array of reports to which are currently readable.
* @package scorm_basic * @package scorm
* @author Ankit Kumar Agarwal * @author Ankit Kumar Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die();
function scorm_report_list($context) { function scorm_report_list($context) {
global $DB; global $CFG;
static $reportlist = null; static $reportlist;
if (!is_null($reportlist)) { if (!empty($reportlist)) {
return $reportlist; return $reportlist;
} }
$reportdirs = get_plugin_list('scorm'); $reportdirs = get_plugin_list('scorm');
$reportcaps = array();
foreach ($reportdirs as $reportname => $notused) { foreach ($reportdirs as $reportname => $notused) {
$pluginfile = 'report/'.$reportname.'/report.php'; $pluginfile = $CFG->dirroot.'/mod/scorm/report/'.$reportname.'/report.php';
if (is_readable($pluginfile)) { if (is_readable($pluginfile)) {
include_once($pluginfile); include_once($pluginfile);
$reportclassname = "scorm_{$reportname}_report"; $reportclassname = "scorm_{$reportname}_report";
if (class_exists($reportclassname)) { if (class_exists($reportclassname)) {
$reportcaps[] = $reportname; $report = new $reportclassname();
if ($report->canview($context)) {
$reportlist[] = $reportname;
}
} }
} }
} }
return $reportcaps; return $reportlist;
} }

View File

@ -28,11 +28,12 @@ class mod_scorm_report_settings extends moodleform {
$mform->addElement('header', 'preferencespage', get_string('preferencespage', 'scorm')); $mform->addElement('header', 'preferencespage', get_string('preferencespage', 'scorm'));
$options = array(); $options = array();
/*Group support is broken - see MDL-28282
if ($this->_customdata['currentgroup'] || $COURSE->id != SITEID) { if ($this->_customdata['currentgroup'] || $COURSE->id != SITEID) {
$options[SCORM_REPORT_ATTEMPTS_ALL_STUDENTS] = get_string('optallstudents', 'scorm'); $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] = get_string('optattemptsonly', 'scorm');
$options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'scorm'); $options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'scorm');
} }*/
$mform->addElement('select', 'attemptsmode', get_string('show', 'scorm'), $options); $mform->addElement('select', 'attemptsmode', get_string('show', 'scorm'), $options);
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------

View File

@ -15,12 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Sets up the tabs used by the scorm pages based on the users capabilities. * Sets up the tabs used by the scorm pages based on the users capabilities.
* *
* @author Dan Marsden and others. * @author Dan Marsden and others.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package scorm * @package scorm
*/ */
if (empty($scorm)) { if (empty($scorm)) {
error('You cannot call this script in that way'); error('You cannot call this script in that way');
@ -32,7 +32,6 @@ if (!isset($cm)) {
$cm = get_coursemodule_from_instance('scorm', $scorm->id); $cm = get_coursemodule_from_instance('scorm', $scorm->id);
} }
$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id); $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
$tabs = array(); $tabs = array();
@ -53,4 +52,12 @@ if ($currenttab == 'info' && count($row) == 1) {
$tabs[] = $row; $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); print_tabs($tabs, $currenttab, $inactive, $activated);