[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 if (!defined('MOODLE_INTERNAL')) { 18 die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 19 } 20 21 require_once($CFG->dirroot.'/course/moodleform_mod.php'); 22 require_once($CFG->dirroot.'/mod/scorm/locallib.php'); 23 24 class mod_scorm_mod_form extends moodleform_mod { 25 26 public function definition() { 27 global $CFG, $COURSE, $OUTPUT; 28 $cfgscorm = get_config('scorm'); 29 30 $mform = $this->_form; 31 32 if (!$CFG->slasharguments) { 33 $mform->addElement('static', '', '', $OUTPUT->notification(get_string('slashargs', 'scorm'), 'notifyproblem')); 34 } 35 36 $mform->addElement('header', 'general', get_string('general', 'form')); 37 38 // Name. 39 $mform->addElement('text', 'name', get_string('name')); 40 if (!empty($CFG->formatstringstriptags)) { 41 $mform->setType('name', PARAM_TEXT); 42 } else { 43 $mform->setType('name', PARAM_CLEANHTML); 44 } 45 $mform->addRule('name', null, 'required', null, 'client'); 46 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 47 48 // Summary. 49 $this->standard_intro_elements(); 50 51 // Package. 52 $mform->addElement('header', 'packagehdr', get_string('packagehdr', 'scorm')); 53 $mform->setExpanded('packagehdr', true); 54 55 // Scorm types. 56 $scormtypes = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm')); 57 58 if ($cfgscorm->allowtypeexternal) { 59 $scormtypes[SCORM_TYPE_EXTERNAL] = get_string('typeexternal', 'scorm'); 60 } 61 62 if ($cfgscorm->allowtypelocalsync) { 63 $scormtypes[SCORM_TYPE_LOCALSYNC] = get_string('typelocalsync', 'scorm'); 64 } 65 66 if ($cfgscorm->allowtypeexternalaicc) { 67 $scormtypes[SCORM_TYPE_AICCURL] = get_string('typeaiccurl', 'scorm'); 68 } 69 70 // Reference. 71 if (count($scormtypes) > 1) { 72 $mform->addElement('select', 'scormtype', get_string('scormtype', 'scorm'), $scormtypes); 73 $mform->setType('scormtype', PARAM_ALPHA); 74 $mform->addHelpButton('scormtype', 'scormtype', 'scorm'); 75 $mform->addElement('text', 'packageurl', get_string('packageurl', 'scorm'), array('size' => 60)); 76 $mform->setType('packageurl', PARAM_RAW); 77 $mform->addHelpButton('packageurl', 'packageurl', 'scorm'); 78 $mform->disabledIf('packageurl', 'scormtype', 'eq', SCORM_TYPE_LOCAL); 79 } else { 80 $mform->addElement('hidden', 'scormtype', SCORM_TYPE_LOCAL); 81 $mform->setType('scormtype', PARAM_ALPHA); 82 } 83 84 // New local package upload. 85 $filemanageroptions = array(); 86 $filemanageroptions['accepted_types'] = array('.zip', '.xml'); 87 $filemanageroptions['maxbytes'] = 0; 88 $filemanageroptions['maxfiles'] = 1; 89 $filemanageroptions['subdirs'] = 0; 90 91 $mform->addElement('filemanager', 'packagefile', get_string('package', 'scorm'), null, $filemanageroptions); 92 $mform->addHelpButton('packagefile', 'package', 'scorm'); 93 $mform->disabledIf('packagefile', 'scormtype', 'noteq', SCORM_TYPE_LOCAL); 94 95 // Update packages timing. 96 $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array()); 97 $mform->setType('updatefreq', PARAM_INT); 98 $mform->setDefault('updatefreq', $cfgscorm->updatefreq); 99 $mform->addHelpButton('updatefreq', 'updatefreq', 'scorm'); 100 101 // Display Settings. 102 $mform->addElement('header', 'displaysettings', get_string('appearance')); 103 104 // Framed / Popup Window. 105 $mform->addElement('select', 'popup', get_string('display', 'scorm'), scorm_get_popup_display_array()); 106 $mform->setDefault('popup', $cfgscorm->popup); 107 $mform->setAdvanced('popup', $cfgscorm->popup_adv); 108 109 // Width. 110 $mform->addElement('text', 'width', get_string('width', 'scorm'), 'maxlength="5" size="5"'); 111 $mform->setDefault('width', $cfgscorm->framewidth); 112 $mform->setType('width', PARAM_INT); 113 $mform->setAdvanced('width', $cfgscorm->framewidth_adv); 114 $mform->disabledIf('width', 'popup', 'eq', 0); 115 116 // Height. 117 $mform->addElement('text', 'height', get_string('height', 'scorm'), 'maxlength="5" size="5"'); 118 $mform->setDefault('height', $cfgscorm->frameheight); 119 $mform->setType('height', PARAM_INT); 120 $mform->setAdvanced('height', $cfgscorm->frameheight_adv); 121 $mform->disabledIf('height', 'popup', 'eq', 0); 122 123 // Window Options. 124 $winoptgrp = array(); 125 foreach (scorm_get_popup_options_array() as $key => $value) { 126 $winoptgrp[] = &$mform->createElement('checkbox', $key, '', get_string($key, 'scorm')); 127 $mform->setDefault($key, $value); 128 } 129 $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options', 'scorm'), '<br />', false); 130 $mform->disabledIf('winoptgrp', 'popup', 'eq', 0); 131 $mform->setAdvanced('winoptgrp', $cfgscorm->winoptgrp_adv); 132 133 // Display activity name. 134 $mform->addElement('advcheckbox', 'displayactivityname', get_string('displayactivityname', 'scorm')); 135 $mform->addHelpButton('displayactivityname', 'displayactivityname', 'scorm'); 136 $mform->setDefault('displayactivityname', $cfgscorm->displayactivityname); 137 138 // Skip view page. 139 $skipviewoptions = scorm_get_skip_view_array(); 140 if ($COURSE->format == 'singleactivity') { // Remove option that would cause a constant redirect. 141 unset($skipviewoptions[SCORM_SKIPVIEW_ALWAYS]); 142 if ($cfgscorm->skipview == SCORM_SKIPVIEW_ALWAYS) { 143 $cfgscorm->skipview = SCORM_SKIPVIEW_FIRST; 144 } 145 } 146 $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), $skipviewoptions); 147 $mform->addHelpButton('skipview', 'skipview', 'scorm'); 148 $mform->setDefault('skipview', $cfgscorm->skipview); 149 $mform->setAdvanced('skipview', $cfgscorm->skipview_adv); 150 151 // Hide Browse. 152 $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm')); 153 $mform->addHelpButton('hidebrowse', 'hidebrowse', 'scorm'); 154 $mform->setDefault('hidebrowse', $cfgscorm->hidebrowse); 155 $mform->setAdvanced('hidebrowse', $cfgscorm->hidebrowse_adv); 156 157 // Display course structure. 158 $mform->addElement('selectyesno', 'displaycoursestructure', get_string('displaycoursestructure', 'scorm')); 159 $mform->addHelpButton('displaycoursestructure', 'displaycoursestructure', 'scorm'); 160 $mform->setDefault('displaycoursestructure', $cfgscorm->displaycoursestructure); 161 $mform->setAdvanced('displaycoursestructure', $cfgscorm->displaycoursestructure_adv); 162 163 // Toc display. 164 $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), scorm_get_hidetoc_array()); 165 $mform->addHelpButton('hidetoc', 'hidetoc', 'scorm'); 166 $mform->setDefault('hidetoc', $cfgscorm->hidetoc); 167 $mform->setAdvanced('hidetoc', $cfgscorm->hidetoc_adv); 168 $mform->disabledIf('hidetoc', 'scormtype', 'eq', SCORM_TYPE_AICCURL); 169 170 // Navigation panel display. 171 $mform->addElement('select', 'nav', get_string('nav', 'scorm'), scorm_get_navigation_display_array()); 172 $mform->addHelpButton('nav', 'nav', 'scorm'); 173 $mform->setDefault('nav', $cfgscorm->nav); 174 $mform->setAdvanced('nav', $cfgscorm->nav_adv); 175 $mform->disabledIf('nav', 'hidetoc', 'noteq', SCORM_TOC_SIDE); 176 177 // Navigation panel position from left. 178 $mform->addElement('text', 'navpositionleft', get_string('fromleft', 'scorm'), 'maxlength="5" size="5"'); 179 $mform->setDefault('navpositionleft', $cfgscorm->navpositionleft); 180 $mform->setType('navpositionleft', PARAM_INT); 181 $mform->setAdvanced('navpositionleft', $cfgscorm->navpositionleft_adv); 182 $mform->disabledIf('navpositionleft', 'hidetoc', 'noteq', SCORM_TOC_SIDE); 183 $mform->disabledIf('navpositionleft', 'nav', 'noteq', SCORM_NAV_FLOATING); 184 185 // Navigation panel position from top. 186 $mform->addElement('text', 'navpositiontop', get_string('fromtop', 'scorm'), 'maxlength="5" size="5"'); 187 $mform->setDefault('navpositiontop', $cfgscorm->navpositiontop); 188 $mform->setType('navpositiontop', PARAM_INT); 189 $mform->setAdvanced('navpositiontop', $cfgscorm->navpositiontop_adv); 190 $mform->disabledIf('navpositiontop', 'hidetoc', 'noteq', SCORM_TOC_SIDE); 191 $mform->disabledIf('navpositiontop', 'nav', 'noteq', SCORM_NAV_FLOATING); 192 193 // Display attempt status. 194 $mform->addElement('select', 'displayattemptstatus', get_string('displayattemptstatus', 'scorm'), 195 scorm_get_attemptstatus_array()); 196 $mform->addHelpButton('displayattemptstatus', 'displayattemptstatus', 'scorm'); 197 $mform->setDefault('displayattemptstatus', $cfgscorm->displayattemptstatus); 198 $mform->setAdvanced('displayattemptstatus', $cfgscorm->displayattemptstatus_adv); 199 200 // Availability. 201 $mform->addElement('header', 'availability', get_string('availability')); 202 203 $mform->addElement('date_time_selector', 'timeopen', get_string("scormopen", "scorm"), array('optional' => true)); 204 $mform->addElement('date_time_selector', 'timeclose', get_string("scormclose", "scorm"), array('optional' => true)); 205 206 // Grade Settings. 207 $mform->addElement('header', 'gradesettings', get_string('grade')); 208 209 // Grade Method. 210 $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), scorm_get_grade_method_array()); 211 $mform->addHelpButton('grademethod', 'grademethod', 'scorm'); 212 $mform->setDefault('grademethod', $cfgscorm->grademethod); 213 214 // Maximum Grade. 215 for ($i = 0; $i <= 100; $i++) { 216 $grades[$i] = "$i"; 217 } 218 $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades); 219 $mform->setDefault('maxgrade', $cfgscorm->maxgrade); 220 $mform->disabledIf('maxgrade', 'grademethod', 'eq', GRADESCOES); 221 222 // Attempts management. 223 $mform->addElement('header', 'attemptsmanagementhdr', get_string('attemptsmanagement', 'scorm')); 224 225 // Max Attempts. 226 $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), scorm_get_attempts_array()); 227 $mform->addHelpButton('maxattempt', 'maximumattempts', 'scorm'); 228 $mform->setDefault('maxattempt', $cfgscorm->maxattempt); 229 230 // What Grade. 231 $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), scorm_get_what_grade_array()); 232 $mform->disabledIf('whatgrade', 'maxattempt', 'eq', 1); 233 $mform->addHelpButton('whatgrade', 'whatgrade', 'scorm'); 234 $mform->setDefault('whatgrade', $cfgscorm->whatgrade); 235 236 // Force new attempt. 237 $mform->addElement('selectyesno', 'forcenewattempt', get_string('forcenewattempt', 'scorm')); 238 $mform->addHelpButton('forcenewattempt', 'forcenewattempt', 'scorm'); 239 $mform->setDefault('forcenewattempt', $cfgscorm->forcenewattempt); 240 241 // Last attempt lock - lock the enter button after the last available attempt has been made. 242 $mform->addElement('selectyesno', 'lastattemptlock', get_string('lastattemptlock', 'scorm')); 243 $mform->addHelpButton('lastattemptlock', 'lastattemptlock', 'scorm'); 244 $mform->setDefault('lastattemptlock', $cfgscorm->lastattemptlock); 245 246 // Compatibility settings. 247 $mform->addElement('header', 'compatibilitysettingshdr', get_string('compatibilitysettings', 'scorm')); 248 249 // Force completed. 250 $mform->addElement('selectyesno', 'forcecompleted', get_string('forcecompleted', 'scorm')); 251 $mform->addHelpButton('forcecompleted', 'forcecompleted', 'scorm'); 252 $mform->setDefault('forcecompleted', $cfgscorm->forcecompleted); 253 254 // Autocontinue. 255 $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm')); 256 $mform->addHelpButton('auto', 'autocontinue', 'scorm'); 257 $mform->setDefault('auto', $cfgscorm->auto); 258 259 // Autocommit. 260 $mform->addElement('selectyesno', 'autocommit', get_string('autocommit', 'scorm')); 261 $mform->addHelpButton('autocommit', 'autocommit', 'scorm'); 262 $mform->setDefault('autocommit', $cfgscorm->autocommit); 263 264 // Mastery score overrides status. 265 $mform->addElement('selectyesno', 'masteryoverride', get_string('masteryoverride', 'scorm')); 266 $mform->addHelpButton('masteryoverride', 'masteryoverride', 'scorm'); 267 $mform->setDefault('masteryoverride', $cfgscorm->masteryoverride); 268 269 // Hidden Settings. 270 $mform->addElement('hidden', 'datadir', null); 271 $mform->setType('datadir', PARAM_RAW); 272 $mform->addElement('hidden', 'pkgtype', null); 273 $mform->setType('pkgtype', PARAM_RAW); 274 $mform->addElement('hidden', 'launch', null); 275 $mform->setType('launch', PARAM_RAW); 276 $mform->addElement('hidden', 'redirect', null); 277 $mform->setType('redirect', PARAM_RAW); 278 $mform->addElement('hidden', 'redirecturl', null); 279 $mform->setType('redirecturl', PARAM_RAW); 280 281 $this->standard_coursemodule_elements(); 282 283 // Buttons. 284 $this->add_action_buttons(); 285 } 286 287 public function data_preprocessing(&$defaultvalues) { 288 global $COURSE; 289 290 if (isset($defaultvalues['popup']) && ($defaultvalues['popup'] == 1) && isset($defaultvalues['options'])) { 291 if (!empty($defaultvalues['options'])) { 292 $options = explode(',', $defaultvalues['options']); 293 foreach ($options as $option) { 294 list($element, $value) = explode('=', $option); 295 $element = trim($element); 296 $defaultvalues[$element] = trim($value); 297 } 298 } 299 } 300 if (isset($defaultvalues['grademethod'])) { 301 $defaultvalues['grademethod'] = intval($defaultvalues['grademethod']); 302 } 303 if (isset($defaultvalues['width']) && (strpos($defaultvalues['width'], '%') === false) 304 && ($defaultvalues['width'] <= 100)) { 305 $defaultvalues['width'] .= '%'; 306 } 307 if (isset($defaultvalues['width']) && (strpos($defaultvalues['height'], '%') === false) 308 && ($defaultvalues['height'] <= 100)) { 309 $defaultvalues['height'] .= '%'; 310 } 311 $scorms = get_all_instances_in_course('scorm', $COURSE); 312 $coursescorm = current($scorms); 313 314 $draftitemid = file_get_submitted_draft_itemid('packagefile'); 315 file_prepare_draft_area($draftitemid, $this->context->id, 'mod_scorm', 'package', 0, 316 array('subdirs' => 0, 'maxfiles' => 1)); 317 $defaultvalues['packagefile'] = $draftitemid; 318 319 if (($COURSE->format == 'singleactivity') && ((count($scorms) == 0) || ($defaultvalues['instance'] == $coursescorm->id))) { 320 $defaultvalues['redirect'] = 'yes'; 321 $defaultvalues['redirecturl'] = '../course/view.php?id='.$defaultvalues['course']; 322 } else { 323 $defaultvalues['redirect'] = 'no'; 324 $defaultvalues['redirecturl'] = '../mod/scorm/view.php?id='.$defaultvalues['coursemodule']; 325 } 326 if (isset($defaultvalues['version'])) { 327 $defaultvalues['pkgtype'] = (substr($defaultvalues['version'], 0, 5) == 'SCORM') ? 'scorm' : 'aicc'; 328 } 329 if (isset($defaultvalues['instance'])) { 330 $defaultvalues['datadir'] = $defaultvalues['instance']; 331 } 332 if (empty($defaultvalues['timeopen'])) { 333 $defaultvalues['timeopen'] = 0; 334 } 335 if (empty($defaultvalues['timeclose'])) { 336 $defaultvalues['timeclose'] = 0; 337 } 338 339 // Set some completion default data. 340 if (!empty($defaultvalues['completionstatusrequired']) && !is_array($defaultvalues['completionstatusrequired'])) { 341 // Unpack values. 342 $cvalues = array(); 343 foreach (scorm_status_options() as $key => $value) { 344 if (($defaultvalues['completionstatusrequired'] & $key) == $key) { 345 $cvalues[$key] = 1; 346 } 347 } 348 349 $defaultvalues['completionstatusrequired'] = $cvalues; 350 } 351 352 if (!isset($defaultvalues['completionscorerequired']) || !strlen($defaultvalues['completionscorerequired'])) { 353 $defaultvalues['completionscoredisabled'] = 1; 354 } 355 } 356 357 public function validation($data, $files) { 358 global $CFG, $USER; 359 $errors = parent::validation($data, $files); 360 361 $type = $data['scormtype']; 362 363 if ($type === SCORM_TYPE_LOCAL) { 364 if (empty($data['packagefile'])) { 365 $errors['packagefile'] = get_string('required'); 366 367 } else { 368 $draftitemid = file_get_submitted_draft_itemid('packagefile'); 369 370 file_prepare_draft_area($draftitemid, $this->context->id, 'mod_scorm', 'packagefilecheck', null, 371 array('subdirs' => 0, 'maxfiles' => 1)); 372 373 // Get file from users draft area. 374 $usercontext = context_user::instance($USER->id); 375 $fs = get_file_storage(); 376 $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', false); 377 378 if (count($files) < 1) { 379 $errors['packagefile'] = get_string('required'); 380 return $errors; 381 } 382 $file = reset($files); 383 if (!$file->is_external_file() && !empty($data['updatefreq'])) { 384 // Make sure updatefreq is not set if using normal local file. 385 $errors['updatefreq'] = get_string('updatefreq_error', 'mod_scorm'); 386 } 387 if (strtolower($file->get_filename()) == 'imsmanifest.xml') { 388 if (!$file->is_external_file()) { 389 $errors['packagefile'] = get_string('aliasonly', 'mod_scorm'); 390 } else { 391 $repository = repository::get_repository_by_id($file->get_repository_id(), context_system::instance()); 392 if (!$repository->supports_relative_file()) { 393 $errors['packagefile'] = get_string('repositorynotsupported', 'mod_scorm'); 394 } 395 } 396 } else if (strtolower(substr($file->get_filename(), -3)) == 'xml') { 397 $errors['packagefile'] = get_string('invalidmanifestname', 'mod_scorm'); 398 } else { 399 // Validate this SCORM package. 400 $errors = array_merge($errors, scorm_validate_package($file)); 401 } 402 } 403 404 } else if ($type === SCORM_TYPE_EXTERNAL) { 405 $reference = $data['packageurl']; 406 // Syntax check. 407 if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) { 408 $errors['packageurl'] = get_string('invalidurl', 'scorm'); 409 } else { 410 // Availability check. 411 $result = scorm_check_url($reference); 412 if (is_string($result)) { 413 $errors['packageurl'] = $result; 414 } 415 } 416 417 } else if ($type === 'packageurl') { 418 $reference = $data['reference']; 419 // Syntax check. 420 if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) { 421 $errors['packageurl'] = get_string('invalidurl', 'scorm'); 422 } else { 423 // Availability check. 424 $result = scorm_check_url($reference); 425 if (is_string($result)) { 426 $errors['packageurl'] = $result; 427 } 428 } 429 430 } else if ($type === SCORM_TYPE_AICCURL) { 431 $reference = $data['packageurl']; 432 // Syntax check. 433 if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) { 434 $errors['packageurl'] = get_string('invalidurl', 'scorm'); 435 } else { 436 // Availability check. 437 $result = scorm_check_url($reference); 438 if (is_string($result)) { 439 $errors['packageurl'] = $result; 440 } 441 } 442 443 } 444 445 // Validate availability dates. 446 if ($data['timeopen'] && $data['timeclose']) { 447 if ($data['timeopen'] > $data['timeclose']) { 448 $errors['timeclose'] = get_string('closebeforeopen', 'scorm'); 449 } 450 } 451 452 return $errors; 453 } 454 455 // Need to translate the "options" and "reference" field. 456 public function set_data($defaultvalues) { 457 $defaultvalues = (array)$defaultvalues; 458 459 if (isset($defaultvalues['scormtype']) and isset($defaultvalues['reference'])) { 460 switch ($defaultvalues['scormtype']) { 461 case SCORM_TYPE_LOCALSYNC : 462 case SCORM_TYPE_EXTERNAL: 463 case SCORM_TYPE_AICCURL: 464 $defaultvalues['packageurl'] = $defaultvalues['reference']; 465 } 466 } 467 unset($defaultvalues['reference']); 468 469 if (!empty($defaultvalues['options'])) { 470 $options = explode(',', $defaultvalues['options']); 471 foreach ($options as $option) { 472 $opt = explode('=', $option); 473 if (isset($opt[1])) { 474 $defaultvalues[$opt[0]] = $opt[1]; 475 } 476 } 477 } 478 479 $this->data_preprocessing($defaultvalues); 480 parent::set_data($defaultvalues); 481 } 482 483 public function add_completion_rules() { 484 $mform =& $this->_form; 485 $items = array(); 486 487 // Require score. 488 $group = array(); 489 $group[] =& $mform->createElement('text', 'completionscorerequired', '', array('size' => 5)); 490 $group[] =& $mform->createElement('checkbox', 'completionscoredisabled', null, get_string('disable')); 491 $mform->setType('completionscorerequired', PARAM_INT); 492 $mform->addGroup($group, 'completionscoregroup', get_string('completionscorerequired', 'scorm'), '', false); 493 $mform->addHelpButton('completionscoregroup', 'completionscorerequired', 'scorm'); 494 $mform->disabledIf('completionscorerequired', 'completionscoredisabled', 'checked'); 495 $mform->setDefault('completionscorerequired', 0); 496 497 $items[] = 'completionscoregroup'; 498 499 // Require status. 500 $first = true; 501 $firstkey = null; 502 foreach (scorm_status_options(true) as $key => $value) { 503 $name = null; 504 $key = 'completionstatusrequired['.$key.']'; 505 if ($first) { 506 $name = get_string('completionstatusrequired', 'scorm'); 507 $first = false; 508 $firstkey = $key; 509 } 510 $mform->addElement('checkbox', $key, $name, $value); 511 $mform->setType($key, PARAM_BOOL); 512 $items[] = $key; 513 } 514 $mform->addHelpButton($firstkey, 'completionstatusrequired', 'scorm'); 515 516 return $items; 517 } 518 519 public function completion_rule_enabled($data) { 520 $status = !empty($data['completionstatusrequired']); 521 $score = empty($data['completionscoredisabled']) && strlen($data['completionscorerequired']); 522 523 return $status || $score; 524 } 525 526 public function get_data($slashed = true) { 527 $data = parent::get_data($slashed); 528 529 if (!$data) { 530 return false; 531 } 532 533 // Convert completionstatusrequired to a proper integer, if any. 534 $total = 0; 535 if (isset($data->completionstatusrequired) && is_array($data->completionstatusrequired)) { 536 foreach (array_keys($data->completionstatusrequired) as $state) { 537 $total |= $state; 538 } 539 $data->completionstatusrequired = $total; 540 } 541 542 if (!empty($data->completionunlocked)) { 543 // Turn off completion settings if the checkboxes aren't ticked. 544 $autocompletion = isset($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC; 545 546 if (!(isset($data->completionstatusrequired) && $autocompletion)) { 547 $data->completionstatusrequired = null; 548 } 549 // Else do nothing: completionstatusrequired has been already converted 550 // into a correct integer representation. 551 552 if (!empty($data->completionscoredisabled) || !$autocompletion) { 553 $data->completionscorerequired = null; 554 } 555 } 556 557 return $data; 558 } 559 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |