From 8aba9cda72e8c1911cd95840bbf714e1b152c097 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 16 Feb 2012 12:16:02 +1300 Subject: [PATCH] MDL-31652 SCORM - hide updatefreq setting and remove it if not required. --- mod/scorm/lang/en/scorm.php | 2 +- mod/scorm/lib.php | 2 +- mod/scorm/locallib.php | 18 ++++++++---------- mod/scorm/mod_form.php | 29 +++++++++++++++++------------ 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index 00f9205d934..b5ad5d57bac 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -210,7 +210,6 @@ $string['notattempted'] = 'Not attempted'; $string['not_corr_type'] = 'Type mismatch for tag {$a->tag}'; $string['notopenyet'] = 'Sorry, this activity is not available until {$a}'; $string['objectives'] = 'Objectives'; -$string['onchanges'] = 'Whenever it changes'; $string['optallstudents'] = 'all users'; $string['optattemptsonly'] = 'users with attempts only'; $string['optnoattemptsonly'] = 'users with no attempts only'; @@ -310,6 +309,7 @@ $string['typelocal'] = 'Uploaded package'; $string['typelocalsync'] = 'Downloaded package'; $string['unziperror'] = 'An error occurs during package unzip'; $string['updatefreq'] = 'Auto-update frequency'; +$string['updatefreq_help'] = 'This allows the external package to be automatically downloaded and updated'; $string['updatefreqdesc'] = 'This preference sets the default auto-update frequency of an activity'; $string['validateascorm'] = 'Validate a package'; $string['validation'] = 'Validation result'; diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 6074888b869..e239096375e 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -502,7 +502,7 @@ function scorm_cron () { mtrace('Updating scorm packages which require daily update');//We are updating - $scormsupdate = $DB->get_records('scorm', array('updatefreq'=>UPDATE_EVERYDAY)); + $scormsupdate = $DB->get_records_select('scorm', 'updatefreq = ? AND scormtype <> ?', array(SCORM_UPDATE_EVERYDAY, SCORM_TYPE_LOCAL)); foreach ($scormsupdate as $scormupdate) { scorm_parse($scormupdate, true); } diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 613266de5a3..c7be4bec2d7 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -18,10 +18,9 @@ require_once("$CFG->dirroot/mod/scorm/lib.php"); require_once("$CFG->libdir/filelib.php"); /// Constants and settings for module scorm -define('UPDATE_NEVER', '0'); -define('UPDATE_ONCHANGE', '1'); -define('UPDATE_EVERYDAY', '2'); -define('UPDATE_EVERYTIME', '3'); +define('SCORM_UPDATE_NEVER', '0'); +define('SCORM_UPDATE_EVERYDAY', '2'); +define('SCORM_UPDATE_EVERYTIME', '3'); define('SCO_ALL', 0); define('SCO_DATA', 1); @@ -133,10 +132,9 @@ function scorm_get_hidetoc_array() { * @return array an array of update frequency options */ function scorm_get_updatefreq_array() { - return array(0 => get_string('never'), - 1 => get_string('onchanges', 'scorm'), - 2 => get_string('everyday', 'scorm'), - 3 => get_string('everytime', 'scorm')); + return array(SCORM_UPDATE_NEVER => get_string('never'), + SCORM_UPDATE_EVERYDAY => get_string('everyday', 'scorm'), + SCORM_UPDATE_EVERYTIME => get_string('everytime', 'scorm')); } /** @@ -729,7 +727,7 @@ function scorm_course_format_display($user, $course) { function scorm_view_display ($user, $scorm, $action, $cm) { global $CFG, $DB, $PAGE, $OUTPUT; - if ($scorm->updatefreq == UPDATE_EVERYTIME) { + if ($scorm->scormtype != SCORM_TYPE_LOCAL && $scorm->updatefreq == SCORM_UPDATE_EVERYTIME) { scorm_parse($scorm, false); } @@ -823,7 +821,7 @@ function scorm_simple_play($scorm, $user, $context, $cmid) { $result = false; - if ($scorm->updatefreq == UPDATE_EVERYTIME) { + if ($scorm->scormtype != SCORM_TYPE_LOCAL && $scorm->updatefreq == SCORM_UPDATE_EVERYTIME) { scorm_parse($scorm, false); } if (has_capability('mod/scorm:viewreport', $context)) { //if this user can view reports, don't skipview so they can see links to reports. diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index 088634c3aab..247b3212110 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -48,27 +48,27 @@ class mod_scorm_mod_form extends moodleform_mod { $this->add_intro_editor(true); // Scorm types - $options = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm')); + $scormtypes = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm')); if ($cfg_scorm->allowtypeexternal) { - $options[SCORM_TYPE_EXTERNAL] = get_string('typeexternal', 'scorm'); + $scormtypes[SCORM_TYPE_EXTERNAL] = get_string('typeexternal', 'scorm'); } if ($cfg_scorm->allowtypelocalsync) { - $options[SCORM_TYPE_LOCALSYNC] = get_string('typelocalsync', 'scorm'); + $scormtypes[SCORM_TYPE_LOCALSYNC] = get_string('typelocalsync', 'scorm'); } if (!empty($CFG->repositoryactivate) and $cfg_scorm->allowtypeimsrepository) { - $options[SCORM_TYPE_IMSREPOSITORY] = get_string('typeimsrepository', 'scorm'); + $scormtypes[SCORM_TYPE_IMSREPOSITORY] = get_string('typeimsrepository', 'scorm'); } if ($cfg_scorm->allowtypeexternalaicc) { - $options[SCORM_TYPE_AICCURL] = get_string('typeaiccurl', 'scorm'); + $scormtypes[SCORM_TYPE_AICCURL] = get_string('typeaiccurl', 'scorm'); } // Reference - if (count($options) > 1) { - $mform->addElement('select', 'scormtype', get_string('scormtype', 'scorm'), $options); + if (count($scormtypes) > 1) { + $mform->addElement('select', 'scormtype', get_string('scormtype', 'scorm'), $scormtypes); $mform->addHelpButton('scormtype', 'scormtype', 'scorm'); $mform->addElement('text', 'packageurl', get_string('packageurl', 'scorm'), array('size'=>60)); $mform->setType('packageurl', PARAM_RAW); @@ -237,11 +237,16 @@ class mod_scorm_mod_form extends moodleform_mod { $mform->setDefault('auto', $cfg_scorm->auto); $mform->setAdvanced('auto', $cfg_scorm->auto_adv); - // Update packages timing - $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array()); - $mform->setDefault('updatefreq', $cfg_scorm->updatefreq); - $mform->setAdvanced('updatefreq', $cfg_scorm->updatefreq_adv); - + if (count($scormtypes) > 1) { + // Update packages timing + $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array()); + $mform->setDefault('updatefreq', $cfg_scorm->updatefreq); + $mform->setAdvanced('updatefreq', $cfg_scorm->updatefreq_adv); + $mform->addHelpButton('updatefreq', 'updatefreq', 'scorm'); + $mform->disabledIf('updatefreq', 'scormtype', 'eq', SCORM_TYPE_LOCAL); + } else { + $mform->addElement('hidden', 'updatefreq', 0); + } //------------------------------------------------------------------------------- // Hidden Settings $mform->addElement('hidden', 'datadir', null);