global $CFG, $USER, $DB;
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
+ if (session_is_loggedinas()) {
+ print_error('notpermittedtojumpas', 'mnet');
+ }
+
// check remote login permissions
if (! has_capability('moodle/site:mnetlogintoremote', get_system_context())
or is_mnet_remote_user($USER)
* @param int $oldquestiontextformat
* @return array
*/
- protected function get_default_numerical_options($oldquestiontextformat) {
+ protected function get_default_numerical_options($oldquestiontextformat, $units) {
global $CFG;
// replay the upgrade step 2009100100 - new table
$options['instructionsformat'] = $oldquestiontextformat;
}
+ // Set a good default, depending on whether there are any units defined.
+ if (empty($units)) {
+ $options['showunits'] = 3;
+ }
+
return $options;
}
$outcome = $restore->process();
if (!$restore->is_independent()) {
if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
- $restore->execute();
+ try {
+ $restore->execute();
+ } catch(Exception $e) {
+ $restore->cleanup();
+ throw new moodle_exception((string)$e);
+ }
} else {
$restore->save_controller();
}
* @return string
*/
public function course_selector(moodle_url $nextstageurl, $wholecourse = true, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) {
- global $CFG;
+ global $CFG, $PAGE;
require_once($CFG->dirroot.'/course/lib.php');
$nextstageurl->param('sesskey', sesskey());
$html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
$html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
$html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
- $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
+ $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'), 'class'=>'newcoursecontinue')));
$html .= html_writer::end_tag('div');
$html .= html_writer::end_tag('form');
+ $config = new stdClass;
+ $config->title = get_string('confirmnewcoursecontinue', 'backup');
+ $config->question = get_string('confirmnewcoursecontinuequestion', 'backup');
+ $config->yesLabel = get_string('continue');
+ $config->noLabel = get_string('cancel');
+ $PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.watch_newcoursecontinue_buttons', array($config));
}
if ($wholecourse && !empty($currentcourse)) {
$this->stage = new restore_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results());
return true;
}
+
+ /**
+ * Delete course which is created by restore process
+ */
+ public function cleanup() {
+ $courseid = $this->controller->get_courseid();
+ if ($this->is_temporary_course_created($courseid)) {
+ delete_course($courseid, false);
+ }
+ }
+
+ /**
+ * Checks if the course is not restored fully and current controller has created it.
+ * @param int $courseid id of the course which needs to be checked
+ * @return bool
+ */
+ protected function is_temporary_course_created($courseid) {
+ global $DB;
+ //Check if current controller instance has created new course.
+ if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) {
+ $results = $DB->record_exists_sql("SELECT bc.itemid
+ FROM {backup_controllers} bc, {course} c
+ WHERE bc.operation = 'restore'
+ AND bc.type = 'course'
+ AND bc.itemid = c.id
+ AND bc.itemid = ?",
+ array($courseid)
+ );
+ return $results;
+ }
+ return false;
+ }
+
/**
* Returns true if enforce_dependencies changed any settings
* @return bool
/**
* Cancels the current restore and redirects the user back to the relevant place
*/
- public function cancel_restore() {
- global $PAGE;
- // Determine the approriate URL to redirect the user to
- if ($PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->cm !== null) {
- $relevanturl = new moodle_url('/mod/'.$PAGE->cm->modname.'/view.php', array('id'=>$PAGE->cm->id));
- } else {
- $relevanturl = new moodle_url('/course/view.php', array('id'=>$PAGE->course->id));
+ public function cancel_process() {
+ //Delete temporary restore course if exists.
+ if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) {
+ $this->cleanup();
}
- redirect($relevanturl);
+ parent::cancel_process();
}
/**
* Gets an array of progress bar items that can be displayed through the restore renderer.
$form = $this->initialise_stage_form();
if ($form->is_cancelled()) {
- $this->ui->cancel_restore();
+ $this->ui->cancel_process();
}
$data = $form->get_data();
});
}
+M.core_backup.watch_newcoursecontinue_buttons = function(config) {
+ Y.all('.newcoursecontinue').each(function(){
+ this._confirmationListener = this._confirmationListener || this.on('click', function(e){
+ // Prevent the default event (sumbit) from firing
+ e.preventDefault();
+ // Create the confirm box
+ var confirm = new M.core.confirm(config);
+ // If the user clicks yes
+ confirm.on('complete-yes', function(e){
+ // Detach the listener for the confirm box so it doesn't fire again.
+ this._confirmationListener.detach();
+ // Simulate the original cancel button click
+ this.simulate('click');
+ }, this);
+ // Show the confirm box
+ confirm.show();
+ }, this);
+ });
+}
+
}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-enrol-notification']});
\ No newline at end of file
return true;
}
+
+ /**
+ * The block should only be dockable when the title of the block is not empty
+ * and when parent allows docking.
+ *
+ * @return bool
+ */
+ public function instance_can_be_docked() {
+ return (!empty($this->config->title) && parent::instance_can_be_docked());
+ }
}
return false;
}
+ if (session_is_loggedinas()) {
+ $this->content = new stdClass();
+ $this->content->footer = html_writer::tag('span',
+ get_string('notpermittedtojumpas', 'mnet'));
+ return $this->content;
+ }
+
// according to start_jump_session,
// remote users can't on-jump
// so don't show this block to them
if (!empty($info->extraclasses)) {
$mod[$seq]->extraclasses = $info->extraclasses;
}
+ if (!empty($info->iconurl)) {
+ $mod[$seq]->iconurl = $info->iconurl;
+ }
if (!empty($info->onclick)) {
$mod[$seq]->onclick = $info->onclick;
}
// Minimise the database size by unsetting default options when they are
// 'empty'. This list corresponds to code in the cm_info constructor.
foreach (array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
- 'indent', 'completion', 'extra', 'extraclasses', 'onclick', 'content',
+ 'indent', 'completion', 'extra', 'extraclasses', 'iconurl', 'onclick', 'content',
'icon', 'iconcomponent', 'customdata', 'showavailability', 'availablefrom',
'availableuntil', 'conditionscompletion', 'conditionsgrade',
'completionview', 'completionexpected', 'score', 'showdescription')
// Get all the possible users
$users = array();
- $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname, u.idnumber', 'lastname ASC, firstname ASC');
+ // Define limitfrom and limitnum for queries below
+ // If $showusers is enabled... don't apply limitfrom and limitnum
+ $limitfrom = empty($showusers) ? 0 : '';
+ $limitnum = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : '';
+
+ $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname ASC', $limitfrom, $limitnum);
if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) {
$showusers = 1;
//course-report-log-live not included as theres no blocks on the live log page
);
return $array;
-}
\ No newline at end of file
+}
$countsql = "SELECT COUNT(DISTINCT(ra.userid))
FROM {role_assignments} ra
+ JOIN {user} u ON u.id = ra.userid
WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid";
$totalcount = $DB->count_records_sql($countsql, $params);
}
}
$this->add_instance($course, $fields);
+ } else {
+ if ($this->get_config('defaultenrol')) {
+ $this->add_default_instance($course);
+ }
}
} else {
$instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'guest'));
Any information you have entered will be lost.';
$string['confirmcancelyes'] = 'Cancel';
$string['confirmcancelno'] = 'Stay';
+$string['confirmnewcoursecontinue'] = 'New course warning';
+$string['confirmnewcoursecontinuequestion'] = 'A temporary (hidden) course will be created by the course restoration process. To abort restoration click cancel. Do not close the browser while restoring.';
$string['coursecategory'] = 'Category the course will be restored into';
$string['courseid'] = 'Original ID';
$string['coursesettings'] = 'Course settings';
$string['notmoodleapplication'] = 'WARNING: This is not a Moodle application, so some of the inspection methods may not work properly.';
$string['notPEM'] = 'This key is not in PEM format. It will not work.';
$string['notpermittedtojump'] = 'You do not have permission to begin a remote session from this Moodle server.';
+$string['notpermittedtojumpas'] = 'You can\'t begin a remote session while you are logged in as another user.';
$string['notpermittedtoland'] = 'You do not have permission to begin a remote session.';
$string['off'] = 'Off';
$string['on'] = 'On';
<node ID="_Freemind_Link_810187762" TEXT=".wmv"/>
<node ID="_Freemind_Link_763870397" TEXT=".asf"/>
<node TEXT=".ogv"/>
+<node TEXT=".f4v"/>
+<node TEXT=".m4v"/>
+<node TEXT=".webm"/>
</node>
<node ID="_Freemind_Link_1019644700" TEXT="non_web_video">
<node ID="_Freemind_Link_190589975" TEXT=".avi"/>
if (this._advButtons.size() > 0) {
this._stateInput = new Y.NodeList(document.getElementsByName('mform_showadvanced_last'));
this._advButtons.on('click', this.switchState, this);
+ this._advButtons.set('type', 'button');
}
},
/**
*/
protected function _fontFamilyCB($m)
{
- $m[1] = preg_replace('/
- \\s*
- (
- "[^"]+" # 1 = family in double qutoes
- |\'[^\']+\' # or 1 = family in single quotes
- |[\\w\\-]+ # or 1 = unquoted family
- )
- \\s*
- /x', '$1', $m[1]);
- return 'font-family:' . $m[1] . $m[2];
+ // Issue 210: must not eliminate WS between words in unquoted families
+ $pieces = preg_split('/(\'[^\']+\'|"[^"]+")/', $m[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+ $out = 'font-family:';
+ while (null !== ($piece = array_shift($pieces))) {
+ if ($piece[0] !== '"' && $piece[0] !== "'") {
+ $piece = preg_replace('/\\s+/', ' ', $piece);
+ $piece = preg_replace('/\\s?,\\s?/', ',', $piece);
+ }
+ $out .= $piece;
+ }
+ return $out . $m[2];
}
}
* Removed .htaccess - Not needed
* Changed config.php - Changed settings to Moodle specific settings incase this
ever gets accidentally used.
+ * Updated lib/Minify/CSS/Compressor.php - Applied an upstream fix for MDL-29864
+ to allow usage of unquoted font-familes with spaces in CSS.
+ http://code.google.com/p/minify/issues/detail?id=210
*/
private $extraclasses;
+ /**
+ * @var moodle_url full external url pointing to icon image for activity
+ */
+ private $iconurl;
+
/**
* @var string
*/
/**
* Note: Will collect view data, if not already obtained.
- * @return string Extra HTML code to display after link
+ * @return string Extra HTML code to display after link
*/
public function get_after_link() {
$this->obtain_view_data();
if (!$output) {
$output = $OUTPUT;
}
- if (!empty($this->icon)) {
+ // Support modules setting their own, external, icon image
+ if (!empty($this->iconurl)) {
+ $icon = $this->iconurl;
+
+ // Fallback to normal local icon + component procesing
+ } else if (!empty($this->icon)) {
if (substr($this->icon, 0, 4) === 'mod/') {
list($modname, $iconname) = explode('/', substr($this->icon, 4), 2);
$icon = $output->pix_url($iconname, $modname);
$this->extraclasses = $extraclasses;
}
+ /**
+ * Sets the external full url that points to the icon being used
+ * by the activity. Useful for external-tool modules (lti...)
+ * If set, takes precedence over $icon and $iconcomponent
+ *
+ * @param moodle_url $iconurl full external url pointing to icon image for activity
+ * @return void
+ */
+ public function set_icon_url(moodle_url $iconurl) {
+ $this->iconurl = $iconurl;
+ }
+
/**
* Sets value of on-click attribute for JavaScript.
* Note: May not be called from _cm_info_view (only _cm_info_dynamic).
$this->indent = isset($mod->indent) ? $mod->indent : 0;
$this->extra = isset($mod->extra) ? $mod->extra : '';
$this->extraclasses = isset($mod->extraclasses) ? $mod->extraclasses : '';
+ $this->iconurl = isset($mod->iconurl) ? $mod->iconurl : '';
$this->onclick = isset($mod->onclick) ? $mod->onclick : '';
$this->content = isset($mod->content) ? $mod->content : '';
$this->icon = isset($mod->icon) ? $mod->icon : '';
*/
public $extraclasses;
+ /**
+ * External URL image to be used by activity as icon, useful for some external-tool modules
+ * like lti. If set, takes precedence over $icon and $iconcomponent
+ * @var $moodle_url
+ */
+ public $iconurl;
+
/**
* Content of onclick JavaScript; escaped HTML to be inserted as attribute value
* @var string
*/
public $onclick;
-}
\ No newline at end of file
+}
if (strcmp($response['status']['status-code'],'207') == 0 ) {
// ok so far
// next there should be a Content-Type: text/xml; charset="utf-8" header line
- if (preg_match('#text/xml;\s?charset=[\'\"]?utf-8[\'\"]?#i', $response['header']['Content-Type'])) {
+ if (preg_match('#(application|text)/xml;\s?charset=[\'\"]?utf-8[\'\"]?#i', $response['header']['Content-Type'])) {
// ok let's get the content of the xml stuff
$this->_parser = xml_parser_create_ns('UTF-8');
// forget old data...
// check for a specified content-length
case preg_match('/Content\\-Length:\\s+([0-9]*)\\r\\n/',$header,$matches):
$this->_error_log('Getting data using Content-Length '. $matches[1]);
+
// check if we the content data size is small enough to get it as one block
if ($matches[1] <= $max_chunk_size ) {
// only read something if Content-Length is bigger than 0
if ($matches[1] > 0 ) {
$buffer = fread($this->sock, $matches[1]);
+ $loadsize = strlen($buffer);
+ //did we realy get the full length?
+ if ($loadsize < $matches[1]) {
+ $max_chunk_size = $loadsize;
+ do {
+ $mod = $max_chunk_size % ($matches[1] - strlen($buffer));
+ $chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($buffer));
+ $buffer .= fread($this->sock, $chunk_size);
+ $this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($buffer));
+ } while ($mod == $max_chunk_size);
+ break;
+ } else {
+ break;
+ }
} else {
$buffer = '';
+ break;
}
- } else {
- // data is to big to handle it as one. Get it chunk per chunk...
- do {
- $mod = $max_chunk_size % ($matches[1] - strlen($buffer));
- $chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($buffer));
- $buffer .= fread($this->sock, $chunk_size);
- $this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($buffer));
- } while ($mod == $max_chunk_size);
+ }
+
+ // data is to big to handle it as one. Get it chunk per chunk...
+ //trying to get the full length of max_chunk_size
+ $buffer = fread($this->sock, $max_chunk_size);
+ $loadsize = strlen($buffer);
+ if ($loadsize < $max_chunk_size) {
+ $max_chunk_size = $loadsize;
+ }
+ do {
+ $mod = $max_chunk_size % ($matches[1] - strlen($buffer));
+ $chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($buffer));
+ $buffer .= fread($this->sock, $chunk_size);
+ $this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($buffer));
+ } while ($mod == $max_chunk_size);
+ $loadsize = strlen($buffer);
+ if ($loadsize < $matches[1]) {
+ $buffer .= fread($this->sock, $matches[1] - $loadsize);
}
break;
$info->username = fullname($user, true);
$info->assignment = format_string($this->assignment->name,true);
$info->url = $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id;
- $info->timeupdated = strftime('%c',$submission->timemodified);
+ $info->timeupdated = userdate($submission->timemodified, '%c', $teacher->timezone);
$postsubject = $strsubmitted.': '.$info->username.' -> '.$this->assignment->name;
$posttext = $this->email_teachers_text($info);
}
function can_unfinalize($submission) {
+ if(is_bool($submission)) {
+ return false;
+ }
+
if (!$this->drafts_tracked()) {
return false;
}
+
if (has_capability('mod/assignment:grade', $this->context)
and $this->isopen()
and $this->is_finalized($submission)) {
function can_finalize($submission) {
global $USER;
+
+ if(is_bool($submission)) {
+ return false;
+ }
+
if (!$this->drafts_tracked()) {
return false;
}
$importer = new data_preset_existing_importer($course, $cm, $data, $formdata->fullname);
echo $renderer->import_setting_mappings($data, $importer);
echo $OUTPUT->footer();
+ exit(0);
} else if ($formdata = $form_importzip->get_data()) {
$file = new stdClass;
$file->name = $form_importzip->get_new_filename('importfile');
}
$result->newpageid = $answer->jumpto;
$result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
- $result->studentanswer = $result->userresponse = $result->response;
+ $result->studentanswer = $result->userresponse = $answer->answer;
return $result;
}
WHERE
ABS(newgrades.newgrade - qg.grade) > 0.000005 OR
- (newgrades.newgrade IS NULL) <> (qg.grade IS NULL)",
+ ((newgrades.newgrade IS NULL OR qg.grade IS NULL) AND NOT
+ (newgrades.newgrade IS NULL AND qg.grade IS NULL))",
+ // The mess on the previous line is detecting where the value is
+ // NULL in one column, and NOT NULL in the other, but SQL does
+ // not have an XOR operator, and MS SQL server can't cope with
+ // (newgrades.newgrade IS NULL) <> (qg.grade IS NULL).
$param);
$timenow = time();
$sessionid = required_param('session_id', PARAM_ALPHANUM);
$aiccdata = optional_param('aicc_data', '', PARAM_RAW);
+$cfg_scorm = get_config('scorm');
+
$url = new moodle_url('/mod/scorm/aicc.php', array('command'=>$command, 'session_id'=>$sessionid));
if ($aiccdata !== 0) {
$url->param('aicc_data', $aiccdata);
}
$PAGE->set_url($url);
-require_login();
+if (empty($cfg_scorm->allowaicchacp)) {
+ require_login();
+ if (!confirm_sesskey($sessionid)) {
+ print_error('invalidsesskey');
+ }
+ $aiccuser = $USER;
+ $scormsession = $SESSION->scorm;
+} else {
+ $scormsession = scorm_aicc_confirm_hacp_session($sessionid);
+ if (empty($scormsession)) {
+ print_error('invalidhacpsession', 'scorm');
+ }
+ $aiccuser = $DB->get_record('user', array('id'=>$scormsession->userid), 'id,username,lastname,firstname', MUST_EXIST);
+}
-if (!empty($command) && confirm_sesskey($sessionid)) {
+if (!empty($command)) {
$command = strtolower($command);
- if (isset($SESSION->scorm_scoid)) {
- $scoid = $SESSION->scorm_scoid;
+ if (isset($scormsession->scoid)) {
+ $scoid = $scormsession->scoid;
} else {
print_error('cannotcallscript');
}
$mode = 'normal';
- if (isset($SESSION->scorm_mode)) {
- $mode = $SESSION->scorm_mode;
+ if (isset($scormsession->scormmode)) {
+ $mode = $scormsession->scormmode;
}
$status = 'Not Initialized';
- if (isset($SESSION->scorm_status)) {
- $status = $SESSION->scorm_status;
+ if (isset($scormsession->scormstatus)) {
+ $status = $scormsession->scormstatus;
}
- if (isset($SESSION->scorm_attempt)) {
- $attempt = $SESSION->scorm_attempt;
+ if (isset($scormsession->attempt)) {
+ $attempt = $scormsession->attempt;
} else {
$attempt = 1;
}
switch ($command) {
case 'getparam':
if ($status == 'Not Initialized') {
- $SESSION->scorm_status = 'Running';
+ $scormsession->scormstatus = 'Running';
$status = 'Running';
}
if ($status != 'Running') {
echo "error=101\r\nerror_text=Terminated\r\n";
} else {
- if ($usertrack=scorm_get_tracks($scoid, $USER->id, $attempt)) {
+ if ($usertrack=scorm_get_tracks($scoid, $aiccuser->id, $attempt)) {
$userdata = $usertrack;
} else {
$userdata->status = '';
$userdata->score_raw = '';
}
- $userdata->student_id = $USER->username;
- $userdata->student_name = $USER->lastname .', '. $USER->firstname;
+ $userdata->student_id = $aiccuser->username;
+ $userdata->student_name = $aiccuser->lastname .', '. $aiccuser->firstname;
$userdata->mode = $mode;
if ($userdata->mode == 'normal') {
$userdata->credit = 'credit';
}
if (isset($userdata->{'cmi.core.lesson_status'})) {
echo 'Lesson_Status='.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\r\n";
- $SESSION->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'};
+ $scormsession->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'};
} else {
echo 'Lesson_Status=not attempted'.$userdata->entry."\r\n";
- $SESSION->scorm_lessonstatus = 'not attempted';
+ $scormsession->scorm_lessonstatus = 'not attempted';
}
if (isset($userdata->{'cmi.core.score.raw'})) {
$max = '';
if (!empty($aiccdata) && has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE, $cm->id))) {
$initlessonstatus = 'not attempted';
$lessonstatus = 'not attempted';
- if (isset($SESSION->scorm_lessonstatus)) {
- $initlessonstatus = $SESSION->scorm_lessonstatus;
+ if (isset($scormsession->scorm_lessonstatus)) {
+ $initlessonstatus = $scormsession->scorm_lessonstatus;
}
$score = '';
$datamodel['lesson_location'] = 'cmi.core.lesson_location';
$element = $datamodel[$element];
switch ($element) {
case 'cmi.core.lesson_location':
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
break;
case 'cmi.core.lesson_status':
$statuses = array(
}
if (empty($value) || isset($exites[$value])) {
$subelement = 'cmi.core.exit';
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
}
$value = trim(strtolower($values[0]));
$value = $value[0];
if (isset($statuses[$value]) && ($mode == 'normal')) {
$value = $statuses[$value];
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
$lessonstatus = $value;
break;
if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) {
$subelement = 'cmi.core.score.max';
$value = trim($values[1]);
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) {
$subelement = 'cmi.core.score.min';
$value = trim($values[2]);
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
}
}
$value = '';
if (is_numeric($values[0])) {
$value = trim($values[0]);
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
$score = $value;
break;
case 'cmi.core.session_time':
- $SESSION->scorm_session_time = $value;
+ $scormsession->sessiontime = $value;
break;
}
}
next($datarows);
}
$value = rawurlencode($value);
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
}
}
if (($mode == 'browse') && ($initlessonstatus == 'not attempted')) {
$lessonstatus = 'browsed';
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed');
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed');
}
if ($mode == 'normal') {
if ($sco = scorm_get_sco($scoid)) {
}
}
}
- $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);
+ $id = scorm_insert_track($aiccuser->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);
}
}
}
break;
case 'exitau':
if ($status == 'Running') {
- if (isset($SESSION->scorm_session_time) && ($SESSION->scorm_session_time != '')) {
- if ($track = $DB->get_record('scorm_scoes_track', array("userid"=>$USER->id,
+ if (isset($scormsession->sessiontime) && ($scormsession->sessiontime != '')) {
+ if ($track = $DB->get_record('scorm_scoes_track', array("userid"=>$aiccuser->id,
"scormid"=>$scorm->id,
"scoid"=>$sco->id,
"attempt"=>$attempt,
"element"=>'cmi.core.total_time'))) {
// Add session_time to total_time
- $value = scorm_add_time($track->value, $SESSION->scorm_session_time);
+ $value = scorm_add_time($track->value, $scormsession->sessiontime);
$track->value = $value;
$track->timemodified = time();
$DB->update_record('scorm_scoes_track', $track);
} else {
$track = new stdClass();
- $track->userid = $USER->id;
+ $track->userid = $aiccuser->id;
$track->scormid = $scorm->id;
$track->scoid = $sco->id;
$track->element = 'cmi.core.total_time';
- $track->value = $SESSION->scorm_session_time;
+ $track->value = $scormsession->sessiontime;
$track->attempt = $attempt;
$track->timemodified = time();
$id = $DB->insert_record('scorm_scoes_track', $track);
}
- scorm_update_grades($scorm, $USER->id);
+ scorm_update_grades($scorm, $aiccuser->id);
}
- $SESSION->scorm_status = 'Terminated';
- $SESSION->scorm_session_time = '';
+ $scormsession->scormstatus = 'Terminated';
+ $scormsession->session_time = '';
echo "error=0\r\nerror_text=Successful\r\n";
} else if ($status == 'Terminated') {
echo "error=1\r\nerror_text=Terminated\r\n";
echo "error=3\r\nerror_text=Invalid Session ID\r\n";
}
}
+if (empty($cfg_scorm->allowaicchacp)) {
+ $SESSION->scorm = $scormsession;
+} else {
+ $scormsession->timemodified = time();
+ $DB->update_record('scorm_aicc_session', $scormsession);
+}
+
$aiccresponse = ob_get_contents();
scorm_debug_log_write("aicc", "HACP Response:\r\n$aiccresponse", $scoid);
ob_end_flush();
\ No newline at end of file
function scorm_parse_aicc($scorm) {
global $DB;
+ if ($scorm->scormtype == SCORM_TYPE_AICCURL) {
+ return scorm_aicc_generate_simple_sco($scorm);
+ }
if (!isset($scorm->cmid)) {
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
$scorm->cmid = $cm->id;
return true;
}
+
+/**
+ * Given a scormid creates an AICC Session record to allow HACP
+ *
+ * @param int $scormid - id from scorm table
+ * @return string hacpsession
+ */
+function scorm_aicc_get_hacp_session($scormid) {
+ global $USER, $DB, $SESSION;
+ $cfg_scorm = get_config('scorm');
+ if (empty($cfg_scorm->allowaicchacp)) {
+ return false;
+ }
+ $now = time();
+
+ $hacpsession = $SESSION->scorm;
+ $hacpsession->scormid = $scormid;
+ $hacpsession->hacpsession = random_string(20);
+ $hacpsession->userid = $USER->id;
+ $hacpsession->timecreated = $now;
+ $hacpsession->timemodified = $now;
+ $DB->insert_record('scorm_aicc_session', $hacpsession);
+
+ return $hacpsession->hacpsession;
+}
+
+/**
+ * Check the hacp_session for whether it is valid.
+ *
+ * @param string $hacpsession The hacpsession value to check (optional). Normally leave this blank
+ * and this function will do required_param('sesskey', ...).
+ * @return mixed - false if invalid, otherwise returns record from scorm_aicc_session table.
+ */
+function scorm_aicc_confirm_hacp_session($hacpsession) {
+ global $DB;
+ $cfg_scorm = get_config('scorm');
+ if (empty($cfg_scorm->allowaicchacp)) {
+ return false;
+ }
+ $time = time()-($cfg_scorm->aicchacptimeout * 60);
+ $sql = "hacpsession = ? AND timemodified > ?";
+ $hacpsession = $DB->get_record_select('scorm_aicc_session', $sql, array($hacpsession, $time));
+ if (!empty($hacpsession)) { //update timemodified as this is still an active session - resets the timeout.
+ $hacpsession->timemodified = time();
+ $DB->update_record('scorm_aicc_session', $hacpsession);
+ }
+ return $hacpsession;
+}
+
+/**
+ * generate a simple single activity AICC object
+ * structure to wrap around and externally linked
+ * AICC package URL
+ *
+ * @param object $scorm package record
+ */
+function scorm_aicc_generate_simple_sco($scorm) {
+ global $DB;
+ // find the old one
+ $scos = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id));
+ if (!empty($scos)) {
+ $sco = array_shift($scos);
+ } else {
+ $sco = new object();
+ }
+ // get rid of old ones
+ foreach($scos as $oldsco) {
+ $DB->delete_records('scorm_scoes', array('id'=>$oldsco->id));
+ $DB->delete_records('scorm_scoes_track', array('scoid'=>$oldsco->id));
+ }
+
+ $sco->identifier = 'A1';
+ $sco->scorm = $scorm->id;
+ $sco->organization = '';
+ $sco->title = $scorm->name;
+ $sco->parent = '/';
+ // add the HACP signal to the activity launcher
+ if (preg_match('/\?/', $scorm->reference)) {
+ $sco->launch = $scorm->reference.'&CMI=HACP';
+ }
+ else {
+ $sco->launch = $scorm->reference.'?CMI=HACP';
+ }
+ $sco->scormtype = 'sco';
+ if (isset($sco->id)) {
+ $DB->update_record('scorm_scoes', $sco);
+ $id = $sco->id;
+ } else {
+ $id = $DB->insert_record('scorm_scoes', $sco);
+ }
+ return $id;
+}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/scorm/db" VERSION="20110731" COMMENT="XMLDB file for Moodle mod/scorm"
+<XMLDB PATH="mod/scorm/db" VERSION="20111105" COMMENT="XMLDB file for Moodle mod/scorm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<KEY NAME="scorm_rolluprule_scoid" TYPE="foreign" FIELDS="scoid" REFTABLE="scorm_scoes" REFFIELDS="id" COMMENT="The relative sco" PREVIOUS="scorm_rolluprule_uniq"/>
</KEYS>
</TABLE>
- <TABLE NAME="scorm_seq_rolluprulecond" COMMENT="SCORM2004 sequencing rule" PREVIOUS="scorm_seq_rolluprule">
+ <TABLE NAME="scorm_seq_rolluprulecond" COMMENT="SCORM2004 sequencing rule" PREVIOUS="scorm_seq_rolluprule" NEXT="scorm_aicc_session">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="scoid"/>
<FIELD NAME="scoid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="rollupruleid"/>
<KEY NAME="scorm_rolluprulecond_rolluprule" TYPE="foreign" FIELDS="rollupruleid" REFTABLE="scorm_seq_rolluprule" REFFIELDS="id" COMMENT="The relative rolluprule" PREVIOUS="scorm_rolluprulecond_scoid"/>
</KEYS>
</TABLE>
+ <TABLE NAME="scorm_aicc_session" COMMENT="Used by AICC HACP to store session information" PREVIOUS="scorm_seq_rolluprulecond">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
+ <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from user table" PREVIOUS="id" NEXT="scormid"/>
+ <FIELD NAME="scormid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from scorm table" PREVIOUS="userid" NEXT="hacpsession"/>
+ <FIELD NAME="hacpsession" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="sessionid used to authenticate AICC HACP communication" PREVIOUS="scormid" NEXT="scoid"/>
+ <FIELD NAME="scoid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="id from scorm_scoes table" PREVIOUS="hacpsession" NEXT="scormmode"/>
+ <FIELD NAME="scormmode" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false" PREVIOUS="scoid" NEXT="scormstatus"/>
+ <FIELD NAME="scormstatus" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="scormmode" NEXT="attempt"/>
+ <FIELD NAME="attempt" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="scormstatus" NEXT="lessonstatus"/>
+ <FIELD NAME="lessonstatus" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="attempt" NEXT="sessiontime"/>
+ <FIELD NAME="sessiontime" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="lessonstatus" NEXT="timecreated"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="time this session was created" PREVIOUS="sessiontime" NEXT="timemodified"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="time this session was last used" PREVIOUS="timecreated"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="scormid"/>
+ <KEY NAME="scormid" TYPE="foreign" FIELDS="scormid" REFTABLE="scorm" REFFIELDS="id" PREVIOUS="primary" NEXT="userid"/>
+ <KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="scormid"/>
+ </KEYS>
+ </TABLE>
+
</TABLES>
</XMLDB>
\ No newline at end of file
upgrade_mod_savepoint(true, 2011080100, 'scorm');
}
+ if ($oldversion < 2011110502) {
+
+ // Define table scorm_aicc_session to be created
+ $table = new xmldb_table('scorm_aicc_session');
+
+ // Adding fields to table scorm_aicc_session
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('scormid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('hacpsession', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
+ $table->add_field('scormmode', XMLDB_TYPE_CHAR, '50', null, null, null, null);
+ $table->add_field('scormstatus', XMLDB_TYPE_CHAR, '255', null, null, null, null);
+ $table->add_field('attempt', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
+ $table->add_field('lessonstatus', XMLDB_TYPE_CHAR, '255', null, null, null, null);
+ $table->add_field('sessiontime', XMLDB_TYPE_CHAR, '255', null, null, null, null);
+ $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+
+ // Adding keys to table scorm_aicc_session
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+ $table->add_key('scormid', XMLDB_KEY_FOREIGN, array('scormid'), 'scorm', array('id'));
+ $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
+
+ // Conditionally launch create table for scorm_aicc_session
+ if (!$dbman->table_exists($table)) {
+ $dbman->create_table($table);
+ }
+
+ // scorm savepoint reached
+ upgrade_mod_savepoint(true, 2011110502, 'scorm');
+ }
+
return true;
}
*/
$string['toc'] = 'TOC';
$string['navigation'] = 'Navigation';
-
+$string['aicchacptimeout'] = 'AICC HACP Timeout';
+$string['aicchacptimeout_desc'] = 'Length of time in minutes that an external AICC HACP session can remain open';
+$string['aicchacpkeepsessiondata'] = 'AICC HACP session data';
+$string['aicchacpkeepsessiondata_desc'] = 'Length of time in days to keep the external AICC HACP session data (a high setting will fill up the table with old data but may be useful when debugging)';
$string['activation'] = 'Activation';
$string['activityloading'] = 'You will be automatically redirected to the activity in';
$string['activitypleasewait'] = 'Activity loading, please wait ...';
$string['advanced'] = 'Parameters';
$string['allowapidebug'] = 'Activate API debug and tracing (set the capture mask with apidebugmask)';
$string['allowtypeexternal'] = 'Enable external package type';
+$string['allowtypeexternalaicc'] = 'Enable direct AICC url';
+$string['allowtypeexternalaicc_desc'] = 'If enabled this allows a direct url to a simple AICC package';
$string['allowtypeimsrepository'] = 'Enable IMS package type';
$string['allowtypelocalsync'] = 'Enable downloaded package type';
+$string['allowtypeaicchacp'] = 'Enable external AICC HACP';
+$string['allowtypeaicchacp_desc'] = 'If enabled this allows AICC HACP external communication without requiring user login for post requests from the external AICC package';
$string['apidebugmask'] = 'API debug capture mask - use a simple regex on <username>:<activityname> e.g. admin:.* will debug for admin user only';
$string['areacontent'] = 'Content files';
$string['areapackage'] = 'Package file';
$string['asset'] = 'Asset';
$string['assetlaunched'] = 'Asset - Viewed';
-$string['attempt'] = 'attempt';
+$string['attempt'] = 'Attempt';
$string['attempts'] = 'Attempts';
$string['attemptsx'] = '{$a} attempts';
$string['attempt1'] = '1 attempt';
$string['interactionsweight'] = 'Weight assigned to the element';
$string['interactionslearnerresponse'] = 'Learner\'s Response';
$string['invalidactivity'] = 'Scorm activity is incorrect';
+$string['invalidurl'] = 'Invalid URL specified';
+$string['invalidhacpsession'] = 'Invalid HACP Session';
$string['invalidmanifestresource'] = 'WARNING: The following resources were referenced in your manifest but couldn\'t be found:';
$string['last'] = 'Last accessed on';
$string['lastaccess'] = 'Last access';
* Uploaded package - Enables a SCORM package to be chosen via the file picker
* External SCORM manifest - Enables an imsmanifest.xml URL to be specified. Note: If the URL has a different domain name than your site, then "Downloaded package" is a better option, since otherwise grades are not saved.
* Downloaded package - Enables a package URL to be specified. The package will be unzipped and saved locally, and updated when the external SCORM package is updated.
-* Local IMS content repository - Enables a package to be selected from within an IMS repository';
+* Local IMS content repository - Enables a package to be selected from within an IMS repository
+* External AICC URL - this URL is the launch URL for a single AICC Activity. A psuedo package will be constructed around this.';
$string['scorm:viewreport'] = 'View reports';
$string['scorm:viewscores'] = 'View scores';
$string['scrollbars'] = 'Allow the window to be scrolled';
$string['totaltime'] = 'Time';
$string['trackingloose'] = 'WARNING: The tracking data of this package will be lost!';
$string['type'] = 'Type';
+$string['typeaiccurl'] = 'External AICC URL';
$string['typeexternal'] = 'External SCORM manifest';
$string['typeimsrepository'] = 'Local IMS content repository';
$string['typelocal'] = 'Uploaded package';
define('SCORM_TYPE_EXTERNAL', 'external');
/** SCORM_TYPE_IMSREPOSITORY = imsrepository */
define('SCORM_TYPE_IMSREPOSITORY', 'imsrepository');
+/** SCORM_TYPE_AICCURL = external AICC url */
+define('SCORM_TYPE_AICCURL', 'aiccurl');
define('SCORM_TOC_SIDE', 0);
define('SCORM_TOC_HIDDEN', 1);
} else if ($record->scormtype === SCORM_TYPE_LOCALSYNC) {
$record->reference = $scorm->packageurl;
-
} else if ($record->scormtype === SCORM_TYPE_EXTERNAL) {
$record->reference = $scorm->packageurl;
-
} else if ($record->scormtype === SCORM_TYPE_IMSREPOSITORY) {
$record->reference = $scorm->packageurl;
-
+ } else if ($record->scormtype === SCORM_TYPE_AICCURL) {
+ $record->reference = $scorm->packageurl;
} else {
return false;
}
foreach ($scormsupdate as $scormupdate) {
scorm_parse($scormupdate, true);
}
+
+ //now clear out AICC session table with old session data
+ $cfg_scorm = get_config('scorm');
+ if (!empty($cfg_scorm->allowaicchacp)) {
+ $expiretime = time() - ($cfg_scorm->aicchacpkeepsessiondata*24*60*60);
+ $DB->delete_records_select('scorm_aicc_session', 'WHERE timemodified < ?', array($expiretime));
+ }
}
return true;
}
if ($version == 'AICC') {
+ require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php");
+ $aicc_sid = scorm_aicc_get_hacp_session($scorm->id);
+ if (empty($aicc_sid)) {
+ $aicc_sid = sesskey();
+ }
$sco_params = '';
if (isset($sco->parameters) && (!empty($sco->parameters))) {
$sco_params = '&'. $sco->parameters;
}
- $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco_params;
+ $launcher = $sco->launch.$connector.'aicc_sid='.$aicc_sid.'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco_params;
} else {
if (isset($sco->parameters) && (!empty($sco->parameters))) {
$launcher = $sco->launch.$connector.$sco->parameters;
if (!scorm_parse_aicc($scorm)) {
$scorm->version = 'ERROR';
}
+ $scorm->version = 'AICC';
}
} else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL and $cfg_scorm->allowtypeexternal) {
$scorm->version = 'ERROR';
}
$newhash = sha1($scorm->reference);
-
+ } else if ($scorm->scormtype === SCORM_TYPE_AICCURL and $cfg_scorm->allowtypeexternalaicc) {
+ require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php");
+ // AICC
+ if (!scorm_parse_aicc($scorm)) {
+ $scorm->version = 'ERROR';
+ }
+ $scorm->version = 'AICC';
} else {
// sorry, disabled type
return;
$options[SCORM_TYPE_IMSREPOSITORY] = get_string('typeimsrepository', 'scorm');
}
+ if ($cfg_scorm->allowtypeexternalaicc) {
+ $options[SCORM_TYPE_AICCURL] = get_string('typeaiccurl', 'scorm');
+ }
+
// Reference
if (count($options) > 1) {
$mform->addElement('select', 'scormtype', get_string('scormtype', 'scorm'), $options);
} else if ($type === SCORM_TYPE_EXTERNAL) {
$reference = $data['packageurl'];
if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) {
- $errors['packageurl'] = get_string('required'); // TODO: improve help
+ $errors['packageurl'] = get_string('invalidurl', 'scorm');
}
} else if ($type === 'packageurl') {
$reference = $data['reference'];
if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) {
- $errors['packageurl'] = get_string('required'); // TODO: improve help
+ $errors['packageurl'] = get_string('invalidurl', 'scorm');
}
} else if ($type === SCORM_TYPE_IMSREPOSITORY) {
$reference = $data['packageurl'];
if (stripos($reference, '#') !== 0) {
- $errors['packageurl'] = get_string('required');
+ $errors['packageurl'] = get_string('invalidurl', 'scorm');
+ }
+ } else if ($type === SCORM_TYPE_AICCURL) {
+ $reference = $data['packageurl'];
+ if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) {
+ $errors['packageurl'] = get_string('invalidurl', 'scorm');
}
}
Y.use('yui2-resize', 'yui2-dragdrop', 'yui2-container', 'yui2-button', 'yui2-layout', 'yui2-treeview', 'yui2-json', 'yui2-event', function(Y) {
+ YAHOO.widget.TextNode.prototype.getContentHtml = function() {
+ var sb = [];
+ sb[sb.length] = this.href ? '<a' : '<span';
+ sb[sb.length] = ' id="' + YAHOO.lang.escapeHTML(this.labelElId) + '"';
+ sb[sb.length] = ' class="' + YAHOO.lang.escapeHTML(this.labelStyle) + '"';
+ if (this.href) {
+ sb[sb.length] = ' href="' + YAHOO.lang.escapeHTML(this.href) + '"';
+ sb[sb.length] = ' target="' + YAHOO.lang.escapeHTML(this.target) + '"';
+ }
+ if (this.title) {
+ sb[sb.length] = ' title="' + YAHOO.lang.escapeHTML(this.title) + '"';
+ }
+ sb[sb.length] = ' >';
+ sb[sb.length] = this.label;
+ sb[sb.length] = this.href?'</a>':'</span>';
+ return sb.join("");
+ };
+
var scorm_activate_item = function(node) {
if (!node) {
return;
}
$orgstr = '¤torg='.$currentorg;
-$SESSION->scorm_scoid = $sco->id;
-$SESSION->scorm_status = 'Not Initialized';
-$SESSION->scorm_mode = $mode;
-$SESSION->scorm_attempt = $attempt;
+$SESSION->scorm->scoid = $sco->id;
+$SESSION->scorm->scormstatus = 'Not Initialized';
+$SESSION->scorm->scormmode = $mode;
+$SESSION->scorm->attempt = $attempt;
// Mark module viewed
$completion = new completion_info($course);
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+defined('MOODLE_INTERNAL') || die();
+
$string['pluginname'] = 'Interactions Report';
$string['questionx'] = 'Question {$a}';
$string['responsex'] = 'Response {$a}';
$table->no_sorting('start');
$table->no_sorting('finish');
$table->no_sorting('score');
-
+
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$table->no_sorting('scograde'.$sco->id);
* @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();
require_once("$CFG->libdir/formslib.php");
class mod_scorm_report_interactions_settings extends moodleform {
defined('MOODLE_INTERNAL') || die();
+/* Generates and returns list of available Scorm report sub-plugins
+ *
+ * @param context context level to check caps against
+ * @return array list of valid reports present
+ */
function scorm_report_list($context) {
global $CFG;
static $reportlist;
$settings->add(new admin_setting_configcheckbox('scorm/allowtypeimsrepository', get_string('allowtypeimsrepository', 'scorm'), '', 0));
+ $settings->add(new admin_setting_configcheckbox('scorm/allowtypeexternalaicc', get_string('allowtypeexternalaicc', 'scorm'), get_string('allowtypeexternalaicc_desc', 'scorm'), 0));
+
+ $settings->add(new admin_setting_configcheckbox('scorm/allowaicchacp', get_string('allowtypeaicchacp', 'scorm'), get_string('allowtypeaicchacp_desc', 'scorm'), 0));
+
+ $settings->add(new admin_setting_configtext('scorm/aicchacptimeout',
+ get_string('aicchacptimeout', 'scorm'), get_string('aicchacptimeout_desc', 'scorm'),
+ 30, PARAM_INT));
+
+ $settings->add(new admin_setting_configtext('scorm/aicchacpkeepsessiondata',
+ get_string('aicchacpkeepsessiondata', 'scorm'), get_string('aicchacpkeepsessiondata_desc', 'scorm'),
+ 1, PARAM_INT));
+
$settings->add(new admin_setting_configcheckbox('scorm/forcejavascript', get_string('forcejavascript', 'scorm'), get_string('forcejavascript_desc', 'scorm'), 1));
$settings->add(new admin_setting_configcheckbox('scorm/allowapidebug', get_string('allowapidebug', 'scorm'), '', 0));
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$module->version = 2011080100; // The (date) version of this module
+$module->version = 2011110502; // The (date) version of this module
$module->requires = 2010080300; // The version of Moodle that is required
$module->cron = 300; // How often should cron check this module (seconds)?
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
-if (isset($SESSION->scorm_scoid)) {
- unset($SESSION->scorm_scoid);
+if (isset($SESSION->scorm)) {
+ unset($SESSION->scorm);
}
$strscorms = get_string("modulenameplural", "scorm");
* @param string name format name from xml file
* @return int Moodle format code
*/
- protected function trans_format($name) {
+ public function trans_format($name) {
$name = trim($name);
if ($name == 'moodle_auto_format') {
} else if ($name == 'markdown') {
return FORMAT_MARKDOWN;
} else {
- return 0; // or maybe warning required
+ debugging("Unrecognised text format '{$name}' in the import file. Assuming 'html'.");
+ return FORMAT_HTML;
}
}
$qo->questiontext = $this->getpath($question,
array('#', 'questiontext', 0, '#', 'text', 0, '#'), '', true);
$qo->questiontextformat = $this->trans_format($this->getpath(
- $question, array('#', 'questiontext', 0, '@', 'format'), ''));
+ $question, array('#', 'questiontext', 0, '@', 'format'), 'html'));
$qo->questiontextfiles = $this->import_files($this->getpath($question,
array('#', 'questiontext', 0, '#', 'file'), array(), false));
array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), $qo->generalfeedback, true);
$qo->generalfeedbackfiles = array();
$qo->generalfeedbackformat = $this->trans_format($this->getpath($question,
- array('#', 'generalfeedback', 0, '@', 'format'), 'moodle_auto_format'));
+ array('#', 'generalfeedback', 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
$qo->generalfeedbackfiles = $this->import_files($this->getpath($question,
array('#', 'generalfeedback', 0, '#', 'file'), array(), false));
/**
* Import the common parts of a single answer
* @param array answer xml tree for single answer
+ * @param bool $withanswerfiles if true, the answers are HTML (or $defaultformat)
+ * and so may contain files, otherwise the answers are plain text.
+ * @param array Default text format for the feedback, and the answers if $withanswerfiles
+ * is true.
* @return object answer object
*/
- public function import_answer($answer, $withanswerfiles = false) {
+ public function import_answer($answer, $withanswerfiles = false, $defaultformat = 'html') {
$ans = new stdClass();
$ans->answer = array();
$ans->answer['text'] = $this->getpath($answer, array('#', 'text', 0, '#'), '', true);
$ans->answer['format'] = $this->trans_format($this->getpath($answer,
- array('@', 'format'), 'moodle_auto_format'));
+ array('@', 'format'), $defaultformat));
if ($withanswerfiles) {
$ans->answer['files'] = $this->import_files($this->getpath($answer,
array('#', 'file'), array()));
+ } else {
+ $ans->answer['format'] = FORMAT_PLAIN;
}
$ans->feedback = array();
$ans->feedback['text'] = $this->getpath($answer,
array('#', 'feedback', 0, '#', 'text', 0, '#'), '', true);
$ans->feedback['format'] = $this->trans_format($this->getpath($answer,
- array('#', 'feedback', 0, '@', 'format'), 'moodle_auto_format'));
+ array('#', 'feedback', 0, '@', 'format'), $defaultformat));
$ans->feedback['files'] = $this->import_files($this->getpath($answer,
array('#', 'feedback', 0, '#', 'file'), array()));
$text['text'] = $this->getpath($questionxml,
array('#', $field, 0, '#', 'text', 0, '#'), '', true);
$text['format'] = $this->trans_format($this->getpath($questionxml,
- array('#', $field, 0, '@', 'format'), 'moodle_auto_format'));
+ array('#', $field, 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
$text['files'] = $this->import_files($this->getpath($questionxml,
array('#', $field, 0, '#', 'file'), array(), false));
/**
* Import a question hint
* @param array $hintxml hint xml fragment.
+ * @param string $defaultformat the text format to assume for hints that do not specify.
* @return object hint for storing in the database.
*/
- public function import_hint($hintxml) {
+ public function import_hint($hintxml, $defaultformat) {
if (array_key_exists('hintcontent', $hintxml['#'])) {
// Backwards compatibility:
$hint->hint = array('format' => FORMAT_HTML, 'files' => array());
$hint->hint['text'] = $this->getpath($hintxml,
array('#', 'hintcontent', 0, '#', 'text', 0, '#'), '', true);
+ $hint->hint['format'] = $this->trans_format($defaultformat);
+ $hint->hint['files'] = array();
$hint->shownumcorrect = $this->getpath($hintxml,
array('#', 'statenumberofcorrectresponses', 0, '#'), 0);
$hint->clearwrong = $this->getpath($hintxml,
$hint->hint['text'] = $this->getpath($hintxml,
array('#', 'text', 0, '#'), '', true);
$hint->hint['format'] = $this->trans_format($this->getpath($hintxml,
- array('@', 'format'), 'moodle_auto_format'));
+ array('@', 'format'), $defaultformat));
$hint->hint['files'] = $this->import_files($this->getpath($hintxml,
array('#', 'file'), array(), false));
$hint->shownumcorrect = array_key_exists('shownumcorrect', $hintxml['#']);
* Import all the question hints
*
* @param object $qo the question data that is being constructed.
- * @param array $hintsxml hints xml fragment.
+ * @param array $questionxml The xml representing the question.
+ * @param bool $withparts whether the extra fields relating to parts should be imported.
+ * @param bool $withoptions whether the extra options field should be imported.
+ * @param string $defaultformat the text format to assume for hints that do not specify.
+ * @return array of objects representing the hints in the file.
*/
- public function import_hints($qo, $questionxml, $withparts = false, $withoptions = false) {
+ public function import_hints($qo, $questionxml, $withparts = false,
+ $withoptions = false, $defaultformat = 'html') {
if (!isset($questionxml['#']['hint'])) {
return;
}
foreach ($questionxml['#']['hint'] as $hintxml) {
- $hint = $this->import_hint($hintxml);
+ $hint = $this->import_hint($hintxml, $defaultformat);
$qo->hint[] = $hint->hint;
if ($withparts) {
$answers = $question['#']['answer'];
$acount = 0;
foreach ($answers as $answer) {
- $ans = $this->import_answer($answer, true);
+ $ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat));
$qo->answer[$acount] = $ans->answer;
$qo->fraction[$acount] = $ans->fraction;
$qo->feedback[$acount] = $ans->feedback;
}
$this->import_combined_feedback($qo, $question, true);
- $this->import_hints($qo, $question, true);
+ $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
return $qo;
}
question_bank::get_qtype('multianswer');
$questiontext['text'] = $this->import_text($question['#']['questiontext'][0]['#']['text']);
- $questiontext['format'] = '1';
+ $questiontext['format'] = FORMAT_HTML;
$questiontext['itemid'] = '';
$qo = qtype_multianswer_extract_question($questiontext);
$qo->qtype = 'multianswer';
$qo->course = $this->course;
$qo->generalfeedback = '';
+
+ $qo->name = $this->import_text($question['#']['name'][0]['#']['text']);
+ $qo->questiontextformat = $questiontext['format'];
+ $qo->questiontext = $qo->questiontext['text'];
+ $qo->questiontextfiles = array();
+
// restore files in generalfeedback
$qo->generalfeedback = $this->getpath($question,
array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), $qo->generalfeedback, true);
$qo->generalfeedbackformat = $this->trans_format($this->getpath($question,
- array('#', 'generalfeedback', 0, '@', 'format'), 'moodle_auto_format'));
+ array('#', 'generalfeedback', 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
$qo->generalfeedbackfiles = $this->import_files($this->getpath($question,
array('#', 'generalfeedback', 0, '#', 'file'), array(), false));
- $qo->name = $this->import_text($question['#']['name'][0]['#']['text']);
- $qo->questiontext = $qo->questiontext['text'];
- $qo->questiontextformat = '';
-
$qo->penalty = $this->getpath($question,
array('#', 'penalty', 0, '#'), $this->defaultquestion()->penalty);
// Fix problematic rounding from old files:
$qo->penalty = 0.3333333;
}
- $this->import_hints($qo, $question);
+ $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
return $qo;
}
$feedback = $this->getpath($answer,
array('#', 'feedback', 0, '#', 'text', 0, '#'), '', true);
$feedbackformat = $this->getpath($answer,
- array('#', 'feedback', 0, '@', 'format'), 'moodle_auto_format');
+ array('#', 'feedback', 0, '@', 'format'), $this->get_format($qo->questiontextformat));
$feedbackfiles = $this->getpath($answer,
array('#', 'feedback', 0, '#', 'file'), array());
$files = array();
echo $OUTPUT->notification(get_string('truefalseimporterror', 'qformat_xml', $a));
}
- $this->import_hints($qo, $question);
+ $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
return $qo;
}
$answers = $question['#']['answer'];
$acount = 0;
foreach ($answers as $answer) {
- $ans = $this->import_answer($answer);
+ $ans = $this->import_answer($answer, false, $this->get_format($qo->questiontextformat));
$qo->answer[$acount] = $ans->answer['text'];
$qo->fraction[$acount] = $ans->fraction;
$qo->feedback[$acount] = $ans->feedback;
++$acount;
}
- $this->import_hints($qo, $question);
+ $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
return $qo;
}
$qo->tolerance = array();
foreach ($answers as $answer) {
// answer outside of <text> is deprecated
- $obj = $this->import_answer($answer);
+ $obj = $this->import_answer($answer, false, $this->get_format($qo->questiontextformat));
$qo->answer[] = $obj->answer['text'];
if (empty($qo->answer)) {
$qo->answer = '*';
}
}
$qo->unitgradingtype = $this->getpath($question, array('#', 'unitgradingtype', 0, '#'), 0);
- $qo->unitpenalty = $this->getpath($question, array('#', 'unitpenalty', 0, '#'), 0);
- $qo->showunits = $this->getpath($question, array('#', 'showunits', 0, '#'), 0);
+ $qo->unitpenalty = $this->getpath($question, array('#', 'unitpenalty', 0, '#'), 0.1);
+ $qo->showunits = $this->getpath($question, array('#', 'showunits', 0, '#'), null);
$qo->unitsleft = $this->getpath($question, array('#', 'unitsleft', 0, '#'), 0);
$qo->instructions['text'] = '';
$qo->instructions['format'] = FORMAT_HTML;
$qo->instructions['text'] = $this->getpath($instructions,
array('0', '#', 'text', '0', '#'), '', true);
$qo->instructions['format'] = $this->trans_format($this->getpath($instructions,
- array('0', '@', 'format'), 'moodle_auto_format'));
+ array('0', '@', 'format'), $this->get_format($qo->questiontextformat)));
$qo->instructions['files'] = $this->import_files($this->getpath(
$instructions, array('0', '#', 'file'), array()));
}
- $this->import_hints($qo, $question);
+ if (is_null($qo->showunits)) {
+ // Set a good default, depending on whether there are any units defined.
+ if (empty($qo->unit)) {
+ $qo->showunits = 3; // qtype_numerical::UNITNONE;
+ } else {
+ $qo->showunits = 0; // qtype_numerical::UNITOPTIONAL;
+ }
+ }
+
+ $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
return $qo;
}
$subquestion = array();
$subquestion['text'] = $this->getpath($subqxml, array('#', 'text', 0, '#'), '', true);
$subquestion['format'] = $this->trans_format($this->getpath($subqxml,
- array('@', 'format'), 'moodle_auto_format'));
+ array('@', 'format'), $this->get_format($qo->questiontextformat)));
$subquestion['files'] = $this->import_files($this->getpath($subqxml,
array('#', 'file'), array()));
}
$this->import_combined_feedback($qo, $question, true);
- $this->import_hints($qo, $question, true);
+ $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
return $qo;
}
$qo->graderinfo['text'] = $this->getpath($question,
array('#', 'graderinfo', 0, '#', 'text', 0, '#'), '', true);
$qo->graderinfo['format'] = $this->trans_format($this->getpath($question,
- array('#', 'graderinfo', 0, '@', 'format'), 'moodle_auto_format'));
+ array('#', 'graderinfo', 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
$qo->graderinfo['files'] = $this->import_files($this->getpath($question,
array('#', 'graderinfo', '0', '#', 'file'), array()));
array('#', 'answernumbering', 0, '#'), 'abc');
$qo->shuffleanswers = $this->trans_single($shuffleanswers);
- $qo->correctfeedback = array();
- $qo->correctfeedback['text'] = $this->getpath(
- $question, array('#', 'correctfeedback', 0, '#', 'text', 0, '#'), '', true);
- $qo->correctfeedback['format'] = $this->trans_format($this->getpath(
- $question, array('#', 'correctfeedback', 0, '@', 'format'), 'moodle_auto_format'));
- $qo->correctfeedback['files'] = $this->import_files($this->getpath(
- $question, array('#', 'correctfeedback', '0', '#', 'file'), array()));
-
- $qo->partiallycorrectfeedback = array();
- $qo->partiallycorrectfeedback['text'] = $this->getpath($question,
- array('#', 'partiallycorrectfeedback', 0, '#', 'text', 0, '#'), '', true);
- $qo->partiallycorrectfeedback['format'] = $this->trans_format(
- $this->getpath($question, array('#', 'partiallycorrectfeedback', 0, '@', 'format'),
- 'moodle_auto_format'));
- $qo->partiallycorrectfeedback['files'] = $this->import_files($this->getpath(
- $question, array('#', 'partiallycorrectfeedback', '0', '#', 'file'), array()));
-
- $qo->incorrectfeedback = array();
- $qo->incorrectfeedback['text'] = $this->getpath($question,
- array('#', 'incorrectfeedback', 0, '#', 'text', 0, '#'), '', true);
- $qo->incorrectfeedback['format'] = $this->trans_format($this->getpath($question,
- array('#', 'incorrectfeedback', 0, '@', 'format'), 'moodle_auto_format'));
- $qo->incorrectfeedback['files'] = $this->import_files($this->getpath($question,
- array('#', 'incorrectfeedback', '0', '#', 'file'), array()));
+ $this->import_combined_feedback($qo, $question);
$qo->unitgradingtype = $this->getpath($question,
array('#', 'unitgradingtype', 0, '#'), 0);
- $qo->unitpenalty = $this->getpath($question, array('#', 'unitpenalty', 0, '#'), 0);
+ $qo->unitpenalty = $this->getpath($question, array('#', 'unitpenalty', 0, '#'), null);
$qo->showunits = $this->getpath($question, array('#', 'showunits', 0, '#'), 0);
$qo->unitsleft = $this->getpath($question, array('#', 'unitsleft', 0, '#'), 0);
$qo->instructions = $this->getpath($question,
$qo->instructions['text'] = $this->getpath($instructions,
array('0', '#', 'text', '0', '#'), '', true);
$qo->instructions['format'] = $this->trans_format($this->getpath($instructions,
- array('0', '@', 'format'), 'moodle_auto_format'));
+ array('0', '@', 'format'), $this->get_format($qo->questiontextformat)));
$qo->instructions['files'] = $this->import_files($this->getpath($instructions,
array('0', '#', 'file'), array()));
}
$qo->correctanswerlength = array();
$qo->feedback = array();
foreach ($answers as $answer) {
- $ans = $this->import_answer($answer, true);
+ $ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat));
// answer outside of <text> is deprecated
if (empty($ans->answer['text'])) {
$ans->answer['text'] = '*';
$qo->instructions['text'] = $this->getpath($instructions,
array('0', '#', 'text', '0', '#'), '', true);
$qo->instructions['format'] = $this->trans_format($this->getpath($instructions,
- array('0', '@', 'format'), 'moodle_auto_format'));
+ array('0', '@', 'format'), $this->get_format($qo->questiontextformat)));
$qo->instructions['files'] = $this->import_files($this->getpath($instructions,
array('0', '#', 'file'), array()));
}
+
+ if (is_null($qo->unitpenalty)) {
+ // Set a good default, depending on whether there are any units defined.
+ if (empty($qo->unit)) {
+ $qo->showunits = 3; // qtype_numerical::UNITNONE;
+ } else {
+ $qo->showunits = 0; // qtype_numerical::UNITOPTIONAL;
+ }
+ }
+
$datasets = $question['#']['dataset_definitions'][0]['#']['dataset_definition'];
$qo->dataset = array();
$qo->datasetindex= 0;
}
}
- $this->import_hints($qo, $question);
+ $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
return $qo;
}
* @param int id internal code
* @return string format text
*/
- protected function get_format($id) {
+ public function get_format($id) {
switch($id) {
case FORMAT_MOODLE:
return 'moodle_auto_format';
"</shuffleanswers>\n";
$expout .= " <answernumbering>" . $question->options->answernumbering .
"</answernumbering>\n";
- $expout .= $this->write_combined_feedback($question->options);
+ $expout .= $this->write_combined_feedback($question->options, $question->id, $question->contextid);
$expout .= $this->write_answers($question->options->answers);
break;
$expout .= " <shuffleanswers>" .
$this->get_single($question->options->shuffleanswers) .
"</shuffleanswers>\n";
- $expout .= $this->write_combined_feedback($question->options);
+ $expout .= $this->write_combined_feedback($question->options, $question->id, $question->contextid);
foreach ($question->options->subquestions as $subquestion) {
$files = $fs->get_area_files($contextid, 'qtype_match',
'subquestion', $subquestion->id);
return $output;
}
+ /**
+ * Write out the hints.
+ * @param object $question the question definition data.
+ * @return string XML to output.
+ */
public function write_hints($question) {
if (empty($question->hints)) {
return '';
$output = '';
foreach ($question->hints as $hint) {
- $output .= $this->write_hint($hint);
+ $output .= $this->write_hint($hint, $question->contextid);
}
return $output;
}
return 'format="' . $this->get_format($format) . '"';
}
- public function write_hint($hint) {
+ public function write_hint($hint, $contextid) {
+ $fs = get_file_storage();
+ $files = $fs->get_area_files($contextid, 'question', 'hint', $hint->id);
+
$output = '';
$output .= " <hint {$this->format($hint->hintformat)}>\n";
$output .= ' ' . $this->writetext($hint->hint);
+
if (!empty($hint->shownumcorrect)) {
$output .= " <shownumcorrect/>\n";
}
if (!empty($hint->clearwrong)) {
$output .= " <clearwrong/>\n";
}
+
if (!empty($hint->options)) {
$output .= ' <options>' . $this->xml_escape($hint->options) . "</options>\n";
}
+ $output .= $this->writefiles($files);
$output .= " </hint>\n";
return $output;
}
- public function write_combined_feedback($questionoptions) {
- $output = " <correctfeedback {$this->format($questionoptions->correctfeedbackformat)}>
- {$this->writetext($questionoptions->correctfeedback)} </correctfeedback>
- <partiallycorrectfeedback {$this->format($questionoptions->partiallycorrectfeedbackformat)}>
- {$this->writetext($questionoptions->partiallycorrectfeedback)} </partiallycorrectfeedback>
- <incorrectfeedback {$this->format($questionoptions->incorrectfeedbackformat)}>
- {$this->writetext($questionoptions->incorrectfeedback)} </incorrectfeedback>\n";
+ /**
+ * Output the combined feedback fields.
+ * @param object $questionoptions the question definition data.
+ * @param int $questionid the question id.
+ * @param int $contextid the question context id.
+ * @return string XML to output.
+ */
+ public function write_combined_feedback($questionoptions, $questionid, $contextid) {
+ $fs = get_file_storage();
+ $output = '';
+
+ $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
+ foreach ($fields as $field) {
+ $formatfield = $field . 'format';
+ $files = $fs->get_area_files($contextid, 'question', $field, $questionid);
+
+ $output .= " <{$field} {$this->format($questionoptions->$formatfield)}>\n";
+ $output .= ' ' . $this->writetext($questionoptions->$field);
+ $output .= $this->writefiles($files);
+ $output .= " </{$field}>\n";
+ }
+
if (!empty($questionoptions->shownumcorrect)) {
$output .= " <shownumcorrect/>\n";
}
$qo = new stdClass();
$importer = new qformat_xml();
- $importer->import_hints($qo, $questionxml['question']);
+ $importer->import_hints($qo, $questionxml['question'], false, false, 'html');
$this->assertEqual(array(
array('text' => 'This is the first hint',
- 'format' => FORMAT_MOODLE, 'files' => array()),
+ 'format' => FORMAT_HTML, 'files' => array()),
array('text' => 'This is the second hint',
- 'format' => FORMAT_MOODLE, 'files' => array()),
+ 'format' => FORMAT_HTML, 'files' => array()),
), $qo->hint);
$this->assertFalse(isset($qo->hintclearwrong));
$this->assertFalse(isset($qo->hintshownumcorrect));
$qo = new stdClass();
$importer = new qformat_xml();
- $importer->import_hints($qo, $questionxml['question'], true, true);
+ $importer->import_hints($qo, $questionxml['question'], true, true, 'html');
$this->assertEqual(array(
array('text' => 'This is the first hint',
- 'format' => FORMAT_MOODLE, 'files' => array()),
+ 'format' => FORMAT_HTML, 'files' => array()),
array('text' => 'This is the second hint',
- 'format' => FORMAT_MOODLE, 'files' => array()),
+ 'format' => FORMAT_HTML, 'files' => array()),
), $qo->hint);
$this->assertEqual(array(1, 0), $qo->hintclearwrong);
$this->assertEqual(array(0, 1), $qo->hintshownumcorrect);
$qo = new stdClass();
$importer = new qformat_xml();
- $importer->import_hints($qo, $questionxml['question']);
+ $importer->import_hints($qo, $questionxml['question'], 'html');
$this->assertFalse(isset($qo->hint));
}
$expectedq->questiontext = 'Match the upper and lower case letters.';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array('text' => 'Well done.',
- 'format' => FORMAT_MOODLE, 'files' => array());
+ 'format' => FORMAT_HTML, 'files' => array());
$expectedq->partiallycorrectfeedback = array('text' => 'Not entirely.',
- 'format' => FORMAT_MOODLE, 'files' => array());
+ 'format' => FORMAT_HTML, 'files' => array());
$expectedq->shownumcorrect = false;
$expectedq->incorrectfeedback = array('text' => 'Completely wrong!',
- 'format' => FORMAT_MOODLE, 'files' => array());
+ 'format' => FORMAT_HTML, 'files' => array());
$expectedq->generalfeedback = 'The answer is A -> a, B -> b and C -> c.';
- $expectedq->generalfeedbackformat = FORMAT_MOODLE;
+ $expectedq->generalfeedbackformat = FORMAT_HTML;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = 0;
$expectedq->subquestions = array(
- array('text' => 'A', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => 'B', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => 'C', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()));
+ array('text' => 'A', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => 'B', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => 'C', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '', 'format' => FORMAT_HTML, 'files' => array()));
$expectedq->subanswers = array('a', 'b', 'c', 'd');
$expectedq->hint = array(
- array('text' => 'Hint 1', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
+ array('text' => 'Hint 1', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
);
$expectedq->hintshownumcorrect = array(true, true);
$expectedq->hintclearwrong = array(false, true);
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array(
'text' => '<p>Your answer is correct.</p>',
- 'format' => FORMAT_MOODLE,
+ 'format' => FORMAT_HTML,
'files' => array());
$expectedq->shownumcorrect = false;
$expectedq->partiallycorrectfeedback = array(
'text' => '<p>Your answer is partially correct.</p>',
- 'format' => FORMAT_MOODLE,
+ 'format' => FORMAT_HTML,
'files' => array());
$expectedq->shownumcorrect = true;
$expectedq->incorrectfeedback = array(
'text' => '<p>Your answer is incorrect.</p>',
- 'format' => FORMAT_MOODLE,
+ 'format' => FORMAT_HTML,
'files' => array());
$expectedq->generalfeedback = 'The even numbers are 2 and 4.';
$expectedq->defaultmark = 2;
$expectedq->single = false;
$expectedq->answer = array(
- array('text' => '1', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '2', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '3', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '4', 'format' => FORMAT_MOODLE, 'files' => array()));
+ array('text' => '1', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '2', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '3', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '4', 'format' => FORMAT_HTML, 'files' => array()));
$expectedq->fraction = array(0, 1, 0, 1);
$expectedq->feedback = array(
- array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()));
+ array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => '', 'format' => FORMAT_HTML, 'files' => array()));
$expectedq->hint = array(
- array('text' => 'Hint 1.', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => 'Hint 2.', 'format' => FORMAT_MOODLE, 'files' => array()),
+ array('text' => 'Hint 1.', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => 'Hint 2.', 'format' => FORMAT_HTML, 'files' => array()),
);
$expectedq->hintshownumcorrect = array(false, false);
$expectedq->hintclearwrong = array(false, false);
$expectedq->questiontext = 'What is the answer?';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->generalfeedback = 'General feedback: Think Hitch-hikers guide to the Galaxy.';
- $expectedq->generalfeedbackformat = FORMAT_MOODLE;
+ $expectedq->generalfeedbackformat = FORMAT_HTML;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.1;
$expectedq->fraction = array(1, 0, 0);
$expectedq->feedback = array(
array('text' => 'Well done!',
- 'format' => FORMAT_MOODLE, 'files' => array()),
+ 'format' => FORMAT_HTML, 'files' => array()),
array('text' => 'What were you thinking?!',
- 'format' => FORMAT_MOODLE, 'files' => array()),
+ 'format' => FORMAT_HTML, 'files' => array()),
array('text' => 'Completely wrong.',
- 'format' => FORMAT_MOODLE, 'files' => array()));
+ 'format' => FORMAT_HTML, 'files' => array()));
$expectedq->tolerance = array(0.001, 1, 0);
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
$expectedq->answer = array('Beta', '*');
$expectedq->fraction = array(1, 0);
$expectedq->feedback = array(
- array('text' => 'Well done!', 'format' => FORMAT_MOODLE, 'files' => array()),
- array('text' => 'Doh!', 'format' => FORMAT_MOODLE, 'files' => array()));
+ array('text' => 'Well done!', 'format' => FORMAT_HTML, 'files' => array()),
+ array('text' => 'Doh!', 'format' => FORMAT_HTML, 'files' => array()));
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
}
$expectedq->penalty = 1;
$expectedq->feedbacktrue = array('text' => 'Well done!',
- 'format' => FORMAT_MOODLE, 'files' => array());
+ 'format' => FORMAT_HTML, 'files' => array());
$expectedq->feedbackfalse = array('text' => 'Doh!',
- 'format' => FORMAT_MOODLE, 'files' => array());
+ 'format' => FORMAT_HTML, 'files' => array());
$expectedq->correctanswer = true;
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
} else if (optional_param('fill', null, PARAM_BOOL)) {
$correctresponse = $quba->get_correct_response($slot);
- $quba->process_action($slot, $correctresponse);
-
- $transaction = $DB->start_delegated_transaction();
- question_engine::save_questions_usage_by_activity($quba);
- $transaction->allow_commit();
+ if (!is_null($correctresponse)) {
+ $quba->process_action($slot, $correctresponse);
+ $transaction = $DB->start_delegated_transaction();
+ question_engine::save_questions_usage_by_activity($quba);
+ $transaction->allow_commit();
+ }
redirect($actionurl);
} else if (optional_param('finish', null, PARAM_BOOL)) {
if ($quba->get_question_state($slot)->is_finished()) {
$finishdisabled = ' disabled="disabled"';
$filldisabled = ' disabled="disabled"';
+} else if (is_null($quba->get_correct_response($slot))) {
+ $filldisabled = ' disabled="disabled"';
}
if (!$previewid) {
$restartdisabled = ' disabled="disabled"';
// convert and write the numerical units and numerical options
if (isset($data['calculated'][0]['numerical_units'])) {
- $numericalunits = $data['calculated'][0]['numerical_units'];
- $numericaloptions = $this->get_default_numerical_options($data['oldquestiontextformat']);
+ $numericalunits = $data['calculated'][0]['numerical_units'];
} else {
- $numericalunits = array();
- $numericaloptions = array();
+ $numericalunits = array();
}
+ $numericaloptions = $this->get_default_numerical_options(
+ $data['oldquestiontextformat'], $numericalunits);
+
$this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions);
// convert and write the numerical units and numerical options
if (isset($data['numerical'][0]['numerical_units'])) {
- $numericalunits = $data['numerical'][0]['numerical_units'];
- $numericaloptions = $this->get_default_numerical_options($data['oldquestiontextformat']);
+ $numericalunits = $data['numerical'][0]['numerical_units'];
} else {
- $numericalunits = array();
- $numericaloptions = array();
+ $numericalunits = array();
}
+ $numericaloptions = $this->get_default_numerical_options(
+ $data['oldquestiontextformat'], $numericalunits);
+
$this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions);
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
<FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="showunits"/>
- <FIELD NAME="showunits" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="display units as multichoice" PREVIOUS="question" NEXT="unitsleft"/>
+ <FIELD NAME="showunits" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="How units are handled: 3) Not used at all, 0) Optional, or 1) must be right or penalty applied." PREVIOUS="question" NEXT="unitsleft"/>
<FIELD NAME="unitsleft" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="display the unit at left as in $1.00" PREVIOUS="showunits" NEXT="unitgradingtype"/>
- <FIELD NAME="unitgradingtype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="0 no penalty, 1 response grade, 2 total grade" PREVIOUS="unitsleft" NEXT="unitpenalty"/>
- <FIELD NAME="unitpenalty" TYPE="number" LENGTH="12" NOTNULL="true" UNSIGNED="true" DEFAULT="0.1" SEQUENCE="false" DECIMALS="7" PREVIOUS="unitgradingtype"/>
+ <FIELD NAME="unitgradingtype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="0 no penalty, 1 fraction response grade, 2 fraction total grade" PREVIOUS="unitsleft" NEXT="unitpenalty"/>
+ <FIELD NAME="unitpenalty" TYPE="number" LENGTH="12" NOTNULL="true" UNSIGNED="true" DEFAULT="0.1" SEQUENCE="false" DECIMALS="7" COMMENT="Penalty for getting the unit wrong, when they are being graded." PREVIOUS="unitgradingtype"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
// Adding keys to table question_numerical_options
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
+
// Conditionally launch create table for question_calculated_options
if (!$dbman->table_exists($table)) {
// $dbman->create_table doesnt return a result, we just have to trust it
$dbman->create_table($table);
}
+
+ // Set a better default for questions without units.
+ $DB->execute('
+ UPDATE {question_numerical_options} qno
+ SET showunits = 3
+ WHERE NOT EXISTS (
+ SELECT 1
+ FROM {question_numerical_units} qnu
+ WHERE qnu.question = qno.question)');
+
upgrade_plugin_savepoint(true, 2009100100, 'qtype', 'numerical');
}
$dbman->add_field($table, $field);
}
- // In the past, question_match_sub.questiontext assumed to contain
+ // In the past, question_numerical_options.instructions assumed to contain
// content of the same form as question.questiontextformat. If we are
// using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML.
$rs = $DB->get_recordset_sql('
--- /dev/null
+This files describes API changes for question type plugins.
+
+=== 2.2 ===
+
+* The XML import/export base class has had some minor API changes. The
+ - write_combined_feedback method now requires that you pass the questionid and
+ contextid. (MDL-29058)
+ - calls to the import_hints and import_answer methods now should pass the question
+ text format as the last argument, to be used as a default if necessary. (MDL-29739)
+ If you do not upgrade your code, it will not break, but there will be PHP
+ warnings, and it the export will not work 100% correctly.
+
+* Question type plugins should start using a string called 'pluginname' for the
+ question type name, as with other plugins. Using a string with the same name
+ as the question type (e.g. get_string('essay', 'qtype_essay') will be supported
+ for one more release, but will generate a debugging warning.
\ No newline at end of file
}
if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') {
// a folder
- if ($path != $v['href']) {
+ if (ltrim($path, '/') != ltrim($v['href'], '/')) {
$matches = array();
preg_match('#(\w+)$#i', $v['href'], $matches);
if (!empty($matches[1])) {
}
}else{
// a file
+ $path = rtrim($path,'/');
$title = urldecode(substr($v['href'], strpos($v['href'], $path)+strlen($path)));
$title = basename($title);
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';