49
49
/** a flag indicating whether outcomes are being used*/
50
50
protected $_outcomesused;
53
* @var bool A flag used to indicate that this module should lock settings
54
* based on admin settings flags in definition_after_data.
56
protected $applyadminlockedflags = false;
58
/** @var object The course format of the current course. */
59
protected $courseformat;
52
61
function moodleform_mod($current, $section, $cm, $course) {
53
64
$this->current = $current;
54
65
$this->_instance = $current->instance;
55
66
$this->_section = $section;
209
224
// is changed, maybe someone has completed it now)
210
225
$mform->getElement('completionunlocked')->setValue(1);
212
// Has the element been unlocked?
213
if ($mform->exportValue('unlockcompletion')) {
227
// Has the element been unlocked, either by the button being pressed
228
// in this request, or the field already being set from a previous one?
229
if ($mform->exportValue('unlockcompletion') ||
230
$mform->exportValue('completionunlocked')) {
214
231
// Yes, add in warning text and set the hidden variable
215
232
$mform->insertElementBefore(
216
233
$mform->createElement('static', 'completedunlocked',
486
506
if ($this->_features->groupings or $this->_features->groupmembersonly) {
487
507
//groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
488
508
$options = array();
489
$options[0] = get_string('none');
490
509
if ($groupings = $DB->get_records('groupings', array('courseid'=>$COURSE->id))) {
491
510
foreach ($groupings as $grouping) {
492
511
$options[$grouping->id] = format_string($grouping->name);
514
core_collator::asort($options);
515
$options = array(0 => get_string('none')) + $options;
495
516
$mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
496
517
$mform->addHelpButton('groupingid', 'grouping', 'group');
641
662
$mform->addElement('hidden', 'completionunlocked', 0);
642
663
$mform->setType('completionunlocked', PARAM_INT);
665
$trackingdefault = COMPLETION_TRACKING_NONE;
666
// If system and activity default is on, set it.
667
if ($CFG->completiondefault && $this->_features->defaultcompletion) {
668
$trackingdefault = COMPLETION_TRACKING_MANUAL;
644
671
$mform->addElement('select', 'completion', get_string('completion', 'completion'),
645
672
array(COMPLETION_TRACKING_NONE=>get_string('completion_none', 'completion'),
646
673
COMPLETION_TRACKING_MANUAL=>get_string('completion_manual', 'completion')));
647
$mform->setDefault('completion', $this->_features->defaultcompletion
648
? COMPLETION_TRACKING_MANUAL
649
: COMPLETION_TRACKING_NONE);
674
$mform->setDefault('completion', $trackingdefault);
650
675
$mform->addHelpButton('completion', 'completion', 'completion');
652
677
// Automatic completion once you view it
665
690
$mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
666
691
$mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
667
692
$gotcompletionoptions = true;
694
// If using the rating system, there is no grade unless ratings are enabled.
695
if ($this->_features->rating) {
696
$mform->disabledIf('completionusegrade', 'assessed', 'eq', 0);
670
700
// Automatic completion according to module-specific rules
812
842
$label = is_null($customlabel) ? get_string('moduleintro') : $customlabel;
814
844
$mform->addElement('editor', 'introeditor', $label, array('rows' => 10), array('maxfiles' => EDITOR_UNLIMITED_FILES,
815
'noclean' => true, 'context' => $this->context, 'collapsed' => true));
845
'noclean' => true, 'context' => $this->context, 'subdirs' => true));
816
846
$mform->setType('introeditor', PARAM_RAW); // no XSS prevention here, users must be trusted
818
848
$mform->addRule('introeditor', get_string('required'), 'required', null, 'client');
821
// If the 'show description' feature is enabled, this checkbox appears
823
if ($this->_features->showdescription) {
851
// If the 'show description' feature is enabled, this checkbox appears below the intro.
852
// We want to hide that when using the singleactivity course format because it is confusing.
853
if ($this->_features->showdescription && $this->courseformat->has_view_page()) {
824
854
$mform->addElement('checkbox', 'showdescription', get_string('showdescription'));
825
855
$mform->addHelpButton('showdescription', 'showdescription');
864
896
$mform->setType('buttonar', PARAM_RAW);
865
897
$mform->closeHeaderBefore('buttonar');
901
* Get the list of admin settings for this module and apply any locked settings.
902
* This cannot happen in apply_admin_defaults because we do not the current values of the settings
903
* in that function because set_data has not been called yet.
907
protected function apply_admin_locked_flags() {
910
if (!$this->applyadminlockedflags) {
914
$settings = get_config($this->_modname);
915
$mform = $this->_form;
916
$lockedicon = html_writer::tag('span',
917
$OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')),
918
array('class' => 'action-icon'));
919
$isupdate = !empty($this->_cm);
921
foreach ($settings as $name => $value) {
922
if (strpos('_', $name) !== false) {
925
if ($mform->elementExists($name)) {
926
$element = $mform->getElement($name);
927
$lockedsetting = $name . '_locked';
928
if (!empty($settings->$lockedsetting)) {
929
// Always lock locked settings for new modules,
930
// for updates, only lock them if the current value is the same as the default (or there is no current value).
931
$value = $settings->$name;
932
if ($isupdate && isset($this->current->$name)) {
933
$value = $this->current->$name;
935
if ($value == $settings->$name) {
936
$mform->setConstant($name, $settings->$name);
937
$element->setLabel($element->getLabel() . $lockedicon);
938
// Do not use hardfreeze because we need the hidden input to check dependencies.
947
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
949
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
950
* default date/time value should be relative to. If not passed, all
951
* date/time fields are set relative to the users current midnight.
954
public function apply_admin_defaults($datetimeoffsets = array()) {
955
// This flag triggers the settings to be locked in apply_admin_locked_flags().
956
$this->applyadminlockedflags = true;
958
$settings = get_config($this->_modname);
959
$mform = $this->_form;
960
$usermidnight = usergetmidnight(time());
961
$isupdate = !empty($this->_cm);
963
foreach ($settings as $name => $value) {
964
if (strpos('_', $name) !== false) {
967
if ($mform->elementExists($name)) {
968
$element = $mform->getElement($name);
970
if ($element->getType() == 'date_time_selector') {
971
$enabledsetting = $name . '_enabled';
972
if (empty($settings->$enabledsetting)) {
973
$mform->setDefault($name, 0);
975
$relativetime = $usermidnight;
976
if (isset($datetimeoffsets[$name])) {
977
$relativetime = $datetimeoffsets[$name];
979
$mform->setDefault($name, $relativetime + $settings->$name);
982
$mform->setDefault($name, $settings->$name);
985
$advancedsetting = $name . '_adv';
986
if (!empty($settings->$advancedsetting)) {
987
$mform->setAdvanced($name);