mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-78528 mod: Add suffix support to module completion fields
This commit is contained in:
parent
274db7f747
commit
8f57f0fdac
@ -319,10 +319,13 @@ class mod_assign_mod_form extends moodleform_mod {
|
||||
public function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('advcheckbox', 'completionsubmit', '', get_string('completionsubmit', 'assign'));
|
||||
$suffix = $this->get_suffix();
|
||||
$completionsubmitel = 'completionsubmit' . $suffix;
|
||||
$mform->addElement('advcheckbox', $completionsubmitel, '', get_string('completionsubmit', 'assign'));
|
||||
// Enable this completion rule by default.
|
||||
$mform->setDefault('completionsubmit', 1);
|
||||
return array('completionsubmit');
|
||||
$mform->setDefault($completionsubmitel, 1);
|
||||
|
||||
return [$completionsubmitel];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -332,7 +335,8 @@ class mod_assign_mod_form extends moodleform_mod {
|
||||
* @return bool
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return !empty($data['completionsubmit']);
|
||||
$suffix = $this->get_suffix();
|
||||
return !empty($data['completionsubmit' . $suffix]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -143,10 +143,14 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
public function data_preprocessing(&$defaultvalues) {
|
||||
parent::data_preprocessing($defaultvalues);
|
||||
|
||||
$suffix = $this->get_suffix();
|
||||
$completionattendanceenabledel = 'completionattendanceenabled' . $suffix;
|
||||
$completionattendanceel = 'completionattendance' . $suffix;
|
||||
|
||||
// Completion: tick by default if completion attendance settings is set to 1 or more.
|
||||
$defaultvalues['completionattendanceenabled'] = 0;
|
||||
if (!empty($defaultvalues['completionattendance'])) {
|
||||
$defaultvalues['completionattendanceenabled'] = 1;
|
||||
$defaultvalues[$completionattendanceenabledel] = 0;
|
||||
if (!empty($defaultvalues[$completionattendanceel])) {
|
||||
$defaultvalues[$completionattendanceenabledel] = 1;
|
||||
}
|
||||
// Check if we are Editing an existing instance.
|
||||
if ($this->current->instance) {
|
||||
@ -162,9 +166,9 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
return;
|
||||
}
|
||||
// Completion: tick if completion attendance settings is set to 1 or more.
|
||||
$defaultvalues['completionattendanceenabled'] = 0;
|
||||
if (!empty($this->current->completionattendance)) {
|
||||
$defaultvalues['completionattendanceenabled'] = 1;
|
||||
$defaultvalues[$completionattendanceenabledel] = 0;
|
||||
if (!empty($this->current->{$completionattendanceel})) {
|
||||
$defaultvalues[$completionattendanceenabledel] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -204,19 +208,26 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
return [];
|
||||
}
|
||||
|
||||
$suffix = $this->get_suffix();
|
||||
|
||||
// Elements for completion by Attendance.
|
||||
$attendance['grouplabel'] = get_string('completionattendancegroup', 'bigbluebuttonbn');
|
||||
$attendance['rulelabel'] = get_string('completionattendance', 'bigbluebuttonbn');
|
||||
$completionattendanceenabledel = 'completionattendanceenabled' . $suffix;
|
||||
$completionattendanceel = 'completionattendance' . $suffix;
|
||||
$completionattendanceunitel = 'completionattendanceunit' . $suffix;
|
||||
$attendance['group'] = [
|
||||
$mform->createElement('advcheckbox', 'completionattendanceenabled', '', $attendance['rulelabel'] . ' '),
|
||||
$mform->createElement('text', 'completionattendance', '', ['size' => 3]),
|
||||
$mform->createElement('static', 'completionattendanceunit', ' ', get_string('minutes', 'bigbluebuttonbn'))
|
||||
$mform->createElement('advcheckbox', $completionattendanceenabledel, '', $attendance['rulelabel'] . ' '),
|
||||
$mform->createElement('text', $completionattendanceel, '', ['size' => 3]),
|
||||
$mform->createElement('static', $completionattendanceunitel, ' ', get_string('minutes', 'bigbluebuttonbn'))
|
||||
];
|
||||
$mform->setType('completionattendance', PARAM_INT);
|
||||
$mform->addGroup($attendance['group'], 'completionattendancegroup', $attendance['grouplabel'], [' '], false);
|
||||
$mform->addHelpButton('completionattendancegroup', 'completionattendancegroup', 'bigbluebuttonbn');
|
||||
$mform->disabledIf('completionattendancegroup', 'completion', 'neq', COMPLETION_AGGREGATION_ANY);
|
||||
$mform->disabledIf('completionattendance', 'completionattendanceenabled', 'notchecked');
|
||||
$mform->setType($completionattendanceel, PARAM_INT);
|
||||
$completionattendancegroupel = 'completionattendancegroup' . $suffix;
|
||||
$mform->addGroup($attendance['group'], $completionattendancegroupel, $attendance['grouplabel'], ' ', false);
|
||||
$mform->addHelpButton($completionattendancegroupel, 'completionattendancegroup', 'bigbluebuttonbn');
|
||||
$completionel = 'completion' . $suffix;
|
||||
$mform->disabledIf($completionattendancegroupel, $completionel, 'neq', COMPLETION_AGGREGATION_ANY);
|
||||
$mform->disabledIf($completionattendanceel, $completionattendanceenabledel, 'notchecked');
|
||||
|
||||
// Elements for completion by Engagement.
|
||||
$engagement['grouplabel'] = get_string('completionengagementgroup', 'bigbluebuttonbn');
|
||||
@ -225,23 +236,30 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
$engagement['raisehand'] = get_string('completionengagementraisehand', 'bigbluebuttonbn');
|
||||
$engagement['pollvotes'] = get_string('completionengagementpollvotes', 'bigbluebuttonbn');
|
||||
$engagement['emojis'] = get_string('completionengagementemojis', 'bigbluebuttonbn');
|
||||
|
||||
$completionengagementchatsel = 'completionengagementchats' . $suffix;
|
||||
$completionengagementtalksel = 'completionengagementtalks' . $suffix;
|
||||
$completionengagementraisehandel = 'completionengagementraisehand' . $suffix;
|
||||
$completionengagementpollvotesel = 'completionengagementpollvotes' . $suffix;
|
||||
$completionengagementemojisel = 'completionengagementemojis' . $suffix;
|
||||
$engagement['group'] = [
|
||||
$mform->createElement('advcheckbox', 'completionengagementchats', '', $engagement['chatlabel'] . ' '),
|
||||
$mform->createElement('advcheckbox', 'completionengagementtalks', '', $engagement['talklabel'] . ' '),
|
||||
$mform->createElement('advcheckbox', 'completionengagementraisehand', '', $engagement['raisehand'] . ' '),
|
||||
$mform->createElement('advcheckbox', 'completionengagementpollvotes', '', $engagement['pollvotes'] . ' '),
|
||||
$mform->createElement('advcheckbox', 'completionengagementemojis', '', $engagement['emojis'] . ' '),
|
||||
$mform->createElement('advcheckbox', $completionengagementchatsel, '', $engagement['chatlabel'] . ' '),
|
||||
$mform->createElement('advcheckbox', $completionengagementtalksel, '', $engagement['talklabel'] . ' '),
|
||||
$mform->createElement('advcheckbox', $completionengagementraisehandel, '', $engagement['raisehand'] . ' '),
|
||||
$mform->createElement('advcheckbox', $completionengagementpollvotesel, '', $engagement['pollvotes'] . ' '),
|
||||
$mform->createElement('advcheckbox', $completionengagementemojisel, '', $engagement['emojis'] . ' '),
|
||||
];
|
||||
$mform->addGroup($engagement['group'], 'completionengagementgroup', $engagement['grouplabel'], [' '], false);
|
||||
$mform->addGroupRule('completionattendancegroup', [
|
||||
'completionattendance' => [
|
||||
$completionengagementgroupel = 'completionengagementgroup' . $suffix;
|
||||
$mform->addGroup($engagement['group'], $completionengagementgroupel, $engagement['grouplabel'], ' ', false);
|
||||
$mform->addGroupRule($completionattendancegroupel, [
|
||||
$completionattendanceel => [
|
||||
[null, 'numeric', null, 'client']
|
||||
]
|
||||
]);
|
||||
$mform->addHelpButton('completionengagementgroup', 'completionengagementgroup', 'bigbluebuttonbn');
|
||||
$mform->disabledIf('completionengagementgroup', 'completion', 'neq', COMPLETION_AGGREGATION_ANY);
|
||||
$mform->addHelpButton($completionengagementgroupel, 'completionengagementgroup', 'bigbluebuttonbn');
|
||||
$mform->disabledIf($completionengagementgroupel, $completionel, 'neq', COMPLETION_AGGREGATION_ANY);
|
||||
|
||||
return ['completionattendancegroup', 'completionengagementgroup'];
|
||||
return [$completionattendancegroupel, $completionengagementgroupel];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,12 +269,13 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
* @return bool True if one or more rules is enabled, false if none are.
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return (!empty($data['completionattendanceenabled']) && $data['completionattendance'] != 0)
|
||||
|| !empty($data['completionengagementchats'])
|
||||
|| !empty($data['completionengagementtalks'])
|
||||
|| !empty($data['completionengagementraisehand'])
|
||||
|| !empty($data['completionengagementpollvotes'])
|
||||
|| !empty($data['completionengagementemojis']);
|
||||
$suffix = $this->get_suffix();
|
||||
return (!empty($data['completionattendanceenabled' . $suffix]) && $data['completionattendance' . $suffix] != 0)
|
||||
|| !empty($data['completionengagementchats' . $suffix])
|
||||
|| !empty($data['completionengagementtalks' . $suffix])
|
||||
|| !empty($data['completionengagementraisehand' . $suffix])
|
||||
|| !empty($data['completionengagementpollvotes' . $suffix])
|
||||
|| !empty($data['completionengagementemojis' . $suffix]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,9 +290,11 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
parent::data_postprocessing($data);
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
if (!empty($data->completionunlocked)) {
|
||||
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completionattendanceenabled) || !$autocompletion) {
|
||||
$data->completionattendance = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->{'completionattendanceenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionattendance' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -703,7 +724,10 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
|
||||
$completion = new completion_info($COURSE);
|
||||
if ($completion->is_enabled()) {
|
||||
$mform = $this->_form;
|
||||
foreach (['completionattendancegroup', 'completionengagementgroup'] as $groupname) {
|
||||
$suffix = $this->get_suffix();
|
||||
$completionattendancegroupel = 'completionattendancegroup' . $suffix;
|
||||
$completionengagementgroupel = 'completionengagementgroup' . $suffix;
|
||||
foreach ([$completionattendancegroupel, $completionengagementgroupel] as $groupname) {
|
||||
if ($mform->elementExists($groupname)) {
|
||||
$element = $mform->getElement($groupname);
|
||||
if ($element->isFrozen()) {
|
||||
|
@ -138,10 +138,11 @@ class mod_choice_mod_form extends moodleform_mod {
|
||||
*/
|
||||
public function data_postprocessing($data) {
|
||||
parent::data_postprocessing($data);
|
||||
// Set up completion section even if checkbox is not ticked
|
||||
// Set up completion section even if checkbox is not ticked.
|
||||
if (!empty($data->completionunlocked)) {
|
||||
if (empty($data->completionsubmit)) {
|
||||
$data->completionsubmit = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
if (empty($data->{'completionsubmit' . $suffix})) {
|
||||
$data->{'completionsubmit' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,17 +166,19 @@ class mod_choice_mod_form extends moodleform_mod {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function add_completion_rules() {
|
||||
public function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'choice'));
|
||||
$suffix = $this->get_suffix();
|
||||
$completionsubmitel = 'completionsubmit' . $suffix;
|
||||
$mform->addElement('checkbox', $completionsubmitel, '', get_string('completionsubmit', 'choice'));
|
||||
// Enable this completion rule by default.
|
||||
$mform->setDefault('completionsubmit', 1);
|
||||
return array('completionsubmit');
|
||||
$mform->setDefault($completionsubmitel, 1);
|
||||
return [$completionsubmitel];
|
||||
}
|
||||
|
||||
function completion_rule_enabled($data) {
|
||||
return !empty($data['completionsubmit']);
|
||||
public function completion_rule_enabled($data) {
|
||||
$suffix = $this->get_suffix();
|
||||
return !empty($data['completionsubmit' . $suffix]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,19 +123,37 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
*/
|
||||
public function add_completion_rules() {
|
||||
$mform = & $this->_form;
|
||||
$group = array();
|
||||
$group[] = $mform->createElement('checkbox', 'completionentriesenabled', '',
|
||||
get_string('completionentriescount', 'data'));
|
||||
$group[] = $mform->createElement('text', 'completionentries',
|
||||
get_string('completionentriescount', 'data'), array('size' => '1'));
|
||||
$group = [];
|
||||
|
||||
$mform->addGroup($group, 'completionentriesgroup', get_string('completionentries', 'data'),
|
||||
array(' '), false);
|
||||
$mform->disabledIf('completionentries', 'completionentriesenabled', 'notchecked');
|
||||
$mform->setDefault('completionentries', 1);
|
||||
$mform->setType('completionentries', PARAM_INT);
|
||||
$suffix = $this->get_suffix();
|
||||
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
||||
$group[] = $mform->createElement(
|
||||
'checkbox',
|
||||
$completionentriesenabledel,
|
||||
'',
|
||||
get_string('completionentriescount', 'data')
|
||||
);
|
||||
$completionentriesel = 'completionentries' . $suffix;
|
||||
$group[] = $mform->createElement(
|
||||
'text',
|
||||
$completionentriesel,
|
||||
get_string('completionentriescount', 'data'),
|
||||
['size' => '1']
|
||||
);
|
||||
|
||||
$completionentriesgroupel = 'completionentriesgroup' . $suffix;
|
||||
$mform->addGroup(
|
||||
$group,
|
||||
$completionentriesgroupel,
|
||||
get_string('completionentries', 'data'),
|
||||
[' '],
|
||||
false
|
||||
);
|
||||
$mform->disabledIf($completionentriesel, $completionentriesenabledel, 'notchecked');
|
||||
$mform->setDefault($completionentriesel, 1);
|
||||
$mform->setType($completionentriesel, PARAM_INT);
|
||||
/* This ensures the elements are disabled unless completion rules are enabled */
|
||||
return array('completionentriesgroup');
|
||||
return [$completionentriesgroupel];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +163,8 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
* @return bool True if one or more rules is enabled, false if none are.
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return (!empty($data['completionentriesenabled']) && $data['completionentries'] != 0);
|
||||
$suffix = $this->get_suffix();
|
||||
return (!empty($data['completionentriesenabled' . $suffix]) && $data['completionentries' . $suffix] != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,9 +175,13 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
*/
|
||||
public function data_preprocessing(&$defaultvalues) {
|
||||
parent::data_preprocessing($defaultvalues);
|
||||
$defaultvalues['completionentriesenabled'] = !empty($defaultvalues['completionentries']) ? 1 : 0;
|
||||
if (empty($defaultvalues['completionentries'])) {
|
||||
$defaultvalues['completionentries'] = 1;
|
||||
|
||||
$suffix = $this->get_suffix();
|
||||
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
||||
$completionentriesel = 'completionentries' . $suffix;
|
||||
$defaultvalues[$completionentriesenabledel] = !empty($defaultvalues[$completionentriesel]) ? 1 : 0;
|
||||
if (empty($defaultvalues[$completionentriesel])) {
|
||||
$defaultvalues[$completionentriesel] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,9 +196,13 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
public function data_postprocessing($data) {
|
||||
parent::data_postprocessing($data);
|
||||
if (!empty($data->completionunlocked)) {
|
||||
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completionentriesenabled) || !$autocompletion) {
|
||||
$data->completionentries = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completionel = 'completion' . $suffix;
|
||||
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
||||
$autocompletion = !empty($data->{$completionel}) && $data->{$completionel} == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->{$completionentriesenabledel}) || !$autocompletion) {
|
||||
$completionentriesel = 'completionentries' . $suffix;
|
||||
$data->{$completionentriesel} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,11 +175,12 @@ class mod_feedback_mod_form extends moodleform_mod {
|
||||
$data->page_after_submit = $data->page_after_submit_editor['text'];
|
||||
|
||||
if (!empty($data->completionunlocked)) {
|
||||
// Turn off completion settings if the checkboxes aren't ticked
|
||||
$autocompletion = !empty($data->completion) &&
|
||||
$data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (!$autocompletion || empty($data->completionsubmit)) {
|
||||
$data->completionsubmit=0;
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (!$autocompletion || empty($data->{'completionsubmit' . $suffix})) {
|
||||
$data->{'completionsubmit' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,16 +207,20 @@ class mod_feedback_mod_form extends moodleform_mod {
|
||||
public function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
$suffix = $this->get_suffix();
|
||||
$completionsubmitel = 'completionsubmit' . $suffix;
|
||||
$mform->addElement('checkbox',
|
||||
'completionsubmit',
|
||||
'',
|
||||
get_string('completionsubmit', 'feedback'));
|
||||
$completionsubmitel,
|
||||
'',
|
||||
get_string('completionsubmit', 'feedback')
|
||||
);
|
||||
// Enable this completion rule by default.
|
||||
$mform->setDefault('completionsubmit', 1);
|
||||
return array('completionsubmit');
|
||||
$mform->setDefault($completionsubmitel, 1);
|
||||
return [$completionsubmitel];
|
||||
}
|
||||
|
||||
public function completion_rule_enabled($data) {
|
||||
return !empty($data['completionsubmit']);
|
||||
$suffix = $this->get_suffix();
|
||||
return !empty($data['completionsubmit' . $suffix]);
|
||||
}
|
||||
}
|
||||
|
@ -405,30 +405,36 @@ class mod_forum_mod_form extends moodleform_mod {
|
||||
}
|
||||
}
|
||||
|
||||
function data_preprocessing(&$default_values) {
|
||||
parent::data_preprocessing($default_values);
|
||||
public function data_preprocessing(&$defaultvalues) {
|
||||
parent::data_preprocessing($defaultvalues);
|
||||
|
||||
$suffix = $this->get_suffix();
|
||||
$completiondiscussionsenabledel = 'completiondiscussionsenabled' . $suffix;
|
||||
$completiondiscussionsel = 'completiondiscussions' . $suffix;
|
||||
$completionrepliesenabledel = 'completionrepliesenabled' . $suffix;
|
||||
$completionrepliesel = 'completionreplies' . $suffix;
|
||||
$completionpostsel = 'completionposts' . $suffix;
|
||||
$completionpostsenabledel = 'completionpostsenabled' . $suffix;
|
||||
|
||||
// Set up the completion checkboxes which aren't part of standard data.
|
||||
// We also make the default value (if you turn on the checkbox) for those
|
||||
// numbers to be 1, this will not apply unless checkbox is ticked.
|
||||
$default_values['completiondiscussionsenabled']=
|
||||
!empty($default_values['completiondiscussions']) ? 1 : 0;
|
||||
if (empty($default_values['completiondiscussions'])) {
|
||||
$default_values['completiondiscussions']=1;
|
||||
$defaultvalues[$completiondiscussionsenabledel] = !empty($defaultvalues[$completiondiscussionsel]) ? 1 : 0;
|
||||
if (empty($defaultvalues[$completiondiscussionsel])) {
|
||||
$defaultvalues[$completiondiscussionsel] = 1;
|
||||
}
|
||||
$default_values['completionrepliesenabled']=
|
||||
!empty($default_values['completionreplies']) ? 1 : 0;
|
||||
if (empty($default_values['completionreplies'])) {
|
||||
$default_values['completionreplies']=1;
|
||||
$defaultvalues[$completionrepliesenabledel] = !empty($defaultvalues[$completionrepliesel]) ? 1 : 0;
|
||||
if (empty($defaultvalues[$completionrepliesel])) {
|
||||
$defaultvalues[$completionrepliesel] = 1;
|
||||
}
|
||||
// Tick by default if Add mode or if completion posts settings is set to 1 or more.
|
||||
if (empty($this->_instance) || !empty($default_values['completionposts'])) {
|
||||
$default_values['completionpostsenabled'] = 1;
|
||||
if (empty($this->_instance) || !empty($defaultvalues[$completionpostsel])) {
|
||||
$defaultvalues[$completionpostsenabledel] = 1;
|
||||
} else {
|
||||
$default_values['completionpostsenabled'] = 0;
|
||||
$defaultvalues[$completionpostsenabledel] = 0;
|
||||
}
|
||||
if (empty($default_values['completionposts'])) {
|
||||
$default_values['completionposts']=1;
|
||||
if (empty($defaultvalues[$completionpostsel])) {
|
||||
$defaultvalues[$completionpostsel] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,36 +444,54 @@ class mod_forum_mod_form extends moodleform_mod {
|
||||
* @return array Array of string IDs of added items, empty array if none
|
||||
*/
|
||||
public function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
|
||||
$group=array();
|
||||
$group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum'));
|
||||
$group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3));
|
||||
$mform->setType('completionposts',PARAM_INT);
|
||||
$mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false);
|
||||
$mform->disabledIf('completionposts','completionpostsenabled','notchecked');
|
||||
$suffix = $this->get_suffix();
|
||||
|
||||
$group=array();
|
||||
$group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum'));
|
||||
$group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3));
|
||||
$mform->setType('completiondiscussions',PARAM_INT);
|
||||
$mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false);
|
||||
$mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked');
|
||||
$group = [];
|
||||
$completionpostsenabledel = 'completionpostsenabled' . $suffix;
|
||||
$group[] =& $mform->createElement('checkbox', $completionpostsenabledel, '', get_string('completionposts', 'forum'));
|
||||
$completionpostsel = 'completionposts' . $suffix;
|
||||
$group[] =& $mform->createElement('text', $completionpostsel, '', ['size' => 3]);
|
||||
$mform->setType($completionpostsel, PARAM_INT);
|
||||
$completionpostsgroupel = 'completionpostsgroup' . $suffix;
|
||||
$mform->addGroup($group, $completionpostsgroupel, get_string('completionpostsgroup', 'forum'), ' ', false);
|
||||
$mform->disabledIf($completionpostsel, $completionpostsenabledel, 'notchecked');
|
||||
|
||||
$group=array();
|
||||
$group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum'));
|
||||
$group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3));
|
||||
$mform->setType('completionreplies',PARAM_INT);
|
||||
$mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false);
|
||||
$mform->disabledIf('completionreplies','completionrepliesenabled','notchecked');
|
||||
$group = [];
|
||||
$completiondiscussionsenabledel = 'completiondiscussionsenabled' . $suffix;
|
||||
$group[] =& $mform->createElement(
|
||||
'checkbox',
|
||||
$completiondiscussionsenabledel,
|
||||
'',
|
||||
get_string('completiondiscussions',
|
||||
'forum')
|
||||
);
|
||||
$completiondiscussionsel = 'completiondiscussions' . $suffix;
|
||||
$group[] =& $mform->createElement('text', $completiondiscussionsel, '', ['size' => 3]);
|
||||
$mform->setType($completiondiscussionsel, PARAM_INT);
|
||||
$completiondiscussionsgroupel = 'completiondiscussionsgroup' . $suffix;
|
||||
$mform->addGroup($group, $completiondiscussionsgroupel, get_string('completiondiscussionsgroup', 'forum'), ' ', false);
|
||||
$mform->disabledIf($completiondiscussionsel, $completiondiscussionsenabledel, 'notchecked');
|
||||
|
||||
return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup');
|
||||
$group = [];
|
||||
$completionrepliesenabledel = 'completionrepliesenabled' . $suffix;
|
||||
$group[] =& $mform->createElement('checkbox', $completionrepliesenabledel, '', get_string('completionreplies', 'forum'));
|
||||
$completionrepliesel = 'completionreplies' . $suffix;
|
||||
$group[] =& $mform->createElement('text', $completionrepliesel, '', ['size' => 3]);
|
||||
$mform->setType($completionrepliesel, PARAM_INT);
|
||||
$completionrepliesgroupel = 'completionrepliesgroup' . $suffix;
|
||||
$mform->addGroup($group, $completionrepliesgroupel, get_string('completionrepliesgroup', 'forum'), ' ', false);
|
||||
$mform->disabledIf($completionrepliesel, $completionrepliesenabledel, 'notchecked');
|
||||
|
||||
return [$completiondiscussionsgroupel, $completionrepliesgroupel, $completionpostsgroupel];
|
||||
}
|
||||
|
||||
function completion_rule_enabled($data) {
|
||||
return (!empty($data['completiondiscussionsenabled']) && $data['completiondiscussions']!=0) ||
|
||||
(!empty($data['completionrepliesenabled']) && $data['completionreplies']!=0) ||
|
||||
(!empty($data['completionpostsenabled']) && $data['completionposts']!=0);
|
||||
public function completion_rule_enabled($data) {
|
||||
$suffix = $this->get_suffix();
|
||||
return (!empty($data['completiondiscussionsenabled' . $suffix]) && $data['completiondiscussions' . $suffix] != 0) ||
|
||||
(!empty($data['completionrepliesenabled' . $suffix]) && $data['completionreplies' . $suffix] != 0) ||
|
||||
(!empty($data['completionpostsenabled' . $suffix]) && $data['completionposts' . $suffix] != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -506,17 +530,19 @@ class mod_forum_mod_form extends moodleform_mod {
|
||||
*/
|
||||
public function data_postprocessing($data) {
|
||||
parent::data_postprocessing($data);
|
||||
// Turn off completion settings if the checkboxes aren't ticked
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
if (!empty($data->completionunlocked)) {
|
||||
$autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completiondiscussionsenabled) || !$autocompletion) {
|
||||
$data->completiondiscussions = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->{'completiondiscussionsenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completiondiscussions' . $suffix} = 0;
|
||||
}
|
||||
if (empty($data->completionrepliesenabled) || !$autocompletion) {
|
||||
$data->completionreplies = 0;
|
||||
if (empty($data->{'completionrepliesenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionreplies' . $suffix} = 0;
|
||||
}
|
||||
if (empty($data->completionpostsenabled) || !$autocompletion) {
|
||||
$data->completionposts = 0;
|
||||
if (empty($data->{'completionpostsenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionposts' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,43 +163,57 @@ class mod_glossary_mod_form extends moodleform_mod {
|
||||
}
|
||||
}
|
||||
|
||||
function data_preprocessing(&$default_values){
|
||||
parent::data_preprocessing($default_values);
|
||||
public function data_preprocessing(&$defaultvalues) {
|
||||
parent::data_preprocessing($defaultvalues);
|
||||
|
||||
// Fallsback on the default setting if 'Entries shown per page' has been left blank.
|
||||
// This prevents the field from being required and expand its section which should not
|
||||
// be the case if there is a default value defined.
|
||||
if (empty($default_values['entbypage']) || $default_values['entbypage'] < 0) {
|
||||
$default_values['entbypage'] = $this->get_default_entbypage();
|
||||
if (empty($defaultvalues['entbypage']) || $defaultvalues['entbypage'] < 0) {
|
||||
$defaultvalues['entbypage'] = $this->get_default_entbypage();
|
||||
}
|
||||
|
||||
$suffix = $this->get_suffix();
|
||||
$completionentriesel = 'completionentries' . $suffix;
|
||||
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
||||
|
||||
// Set up the completion checkboxes which aren't part of standard data.
|
||||
// Tick by default if Add mode or if completion entries settings is set to 1 or more.
|
||||
if (empty($this->_instance) || !empty($default_values['completionentries'])) {
|
||||
$default_values['completionentriesenabled'] = 1;
|
||||
if (empty($this->_instance) || !empty($defaultvalues[$completionentriesel])) {
|
||||
$defaultvalues[$completionentriesenabledel] = 1;
|
||||
} else {
|
||||
$default_values['completionentriesenabled'] = 0;
|
||||
$defaultvalues[$completionentriesenabledel] = 0;
|
||||
}
|
||||
if (empty($default_values['completionentries'])) {
|
||||
$default_values['completionentries']=1;
|
||||
if (empty($defaultvalues[$completionentriesel])) {
|
||||
$defaultvalues[$completionentriesel] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
public function add_completion_rules() {
|
||||
$mform = $this->_form;
|
||||
$suffix = $this->get_suffix();
|
||||
|
||||
$group=array();
|
||||
$group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
|
||||
$group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
|
||||
$mform->setType('completionentries', PARAM_INT);
|
||||
$mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
|
||||
$mform->disabledIf('completionentries','completionentriesenabled','notchecked');
|
||||
$group = [];
|
||||
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
||||
$group[] =& $mform->createElement(
|
||||
'checkbox',
|
||||
$completionentriesenabledel,
|
||||
'',
|
||||
get_string('completionentries', 'glossary')
|
||||
);
|
||||
$completionentriesel = 'completionentries' . $suffix;
|
||||
$group[] =& $mform->createElement('text', $completionentriesel, '', ['size' => 3]);
|
||||
$mform->setType($completionentriesel, PARAM_INT);
|
||||
$completionentriesgroupel = 'completionentriesgroup' . $suffix;
|
||||
$mform->addGroup($group, $completionentriesgroupel, get_string('completionentriesgroup', 'glossary'), ' ', false);
|
||||
$mform->disabledIf($completionentriesel, $completionentriesenabledel, 'notchecked');
|
||||
|
||||
return array('completionentriesgroup');
|
||||
return [$completionentriesgroupel];
|
||||
}
|
||||
|
||||
function completion_rule_enabled($data) {
|
||||
return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
|
||||
public function completion_rule_enabled($data) {
|
||||
$suffix = $this->get_suffix();
|
||||
return (!empty($data['completionentriesenabled' . $suffix]) && $data['completionentries' . $suffix] != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,10 +227,12 @@ class mod_glossary_mod_form extends moodleform_mod {
|
||||
public function data_postprocessing($data) {
|
||||
parent::data_postprocessing($data);
|
||||
if (!empty($data->completionunlocked)) {
|
||||
// Turn off completion settings if the checkboxes aren't ticked
|
||||
$autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completionentriesenabled) || !$autocompletion) {
|
||||
$data->completionentries = 0;
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->{'completionentriesenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionentries' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,4 +248,3 @@ class mod_glossary_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -365,8 +365,10 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
// Set up the completion checkbox which is not part of standard data.
|
||||
$defaultvalues['completiontimespentenabled'] =
|
||||
!empty($defaultvalues['completiontimespent']) ? 1 : 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completiontimespentenabledel = 'completiontimespentenabled' . $suffix;
|
||||
$completiontimespentel = 'completiontimespent' . $suffix;
|
||||
$defaultvalues[$completiontimespentenabledel] = !empty($defaultvalues[$completiontimespentel]) ? 1 : 0;
|
||||
|
||||
if ($this->current->instance) {
|
||||
// Editing existing instance - copy existing files into draft area.
|
||||
@ -406,20 +408,32 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
public function add_completion_rules() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('checkbox', 'completionendreached', get_string('completionendreached', 'lesson'),
|
||||
get_string('completionendreached_desc', 'lesson'));
|
||||
$suffix = $this->get_suffix();
|
||||
$completionendreachedel = 'completionendreached' . $suffix;
|
||||
$mform->addElement(
|
||||
'checkbox', $completionendreachedel,
|
||||
get_string('completionendreached', 'lesson'),
|
||||
get_string('completionendreached_desc', 'lesson')
|
||||
);
|
||||
// Enable this completion rule by default.
|
||||
$mform->setDefault('completionendreached', 1);
|
||||
$mform->setDefault($completionendreachedel, 1);
|
||||
|
||||
$group = array();
|
||||
$group[] =& $mform->createElement('checkbox', 'completiontimespentenabled', '',
|
||||
get_string('completiontimespent', 'lesson'));
|
||||
$group[] =& $mform->createElement('duration', 'completiontimespent', '', array('optional' => false));
|
||||
$mform->addGroup($group, 'completiontimespentgroup', get_string('completiontimespentgroup', 'lesson'), array(' '), false);
|
||||
$mform->disabledIf('completiontimespent[number]', 'completiontimespentenabled', 'notchecked');
|
||||
$mform->disabledIf('completiontimespent[timeunit]', 'completiontimespentenabled', 'notchecked');
|
||||
$group = [];
|
||||
$completiontimespentenabledel = 'completiontimespentenabled' . $suffix;
|
||||
$group[] =& $mform->createElement(
|
||||
'checkbox',
|
||||
$completiontimespentenabledel,
|
||||
'',
|
||||
get_string('completiontimespent', 'lesson')
|
||||
);
|
||||
$completiontimespentel = 'completiontimespent' . $suffix;
|
||||
$group[] =& $mform->createElement('duration', $completiontimespentel, '', ['optional' => false]);
|
||||
$completiontimespentgroupel = 'completiontimespentgroup' . $suffix;
|
||||
$mform->addGroup($group, $completiontimespentgroupel, get_string('completiontimespentgroup', 'lesson'), ' ', false);
|
||||
$mform->disabledIf($completiontimespentel . '[number]', $completiontimespentenabledel, 'notchecked');
|
||||
$mform->disabledIf($completiontimespentel . '[timeunit]', $completiontimespentenabledel, 'notchecked');
|
||||
|
||||
return array('completionendreached', 'completiontimespentgroup');
|
||||
return [$completionendreachedel, $completiontimespentgroupel];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,7 +443,8 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
* @return bool True if one or more rules is enabled, false if none are.
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return !empty($data['completionendreached']) || $data['completiontimespent'] > 0;
|
||||
$suffix = $this->get_suffix();
|
||||
return !empty($data['completionendreached' . $suffix]) || $data['completiontimespent' . $suffix] > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,14 +459,15 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
parent::data_postprocessing($data);
|
||||
// Turn off completion setting if the checkbox is not ticked.
|
||||
if (!empty($data->completionunlocked)) {
|
||||
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completiontimespentenabled) || !$autocompletion) {
|
||||
$data->completiontimespent = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->{'completiontimespentenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completiontimespent' . $suffix} = 0;
|
||||
}
|
||||
if (empty($data->completionendreached) || !$autocompletion) {
|
||||
$data->completionendreached = 0;
|
||||
if (empty($data->{'completionendreached' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionendreached' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,10 +491,13 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($toform['completionminattempts'])) {
|
||||
$toform['completionminattempts'] = 1;
|
||||
$suffix = $this->get_suffix();
|
||||
$completionminattemptsel = 'completionminattempts' . $suffix;
|
||||
if (empty($toform[$completionminattemptsel])) {
|
||||
$toform[$completionminattemptsel] = 1;
|
||||
} else {
|
||||
$toform['completionminattemptsenabled'] = $toform['completionminattempts'] > 0;
|
||||
$completionminattemptsenabledel = 'completionminattemptsenabled' . $suffix;
|
||||
$toform[$completionminattemptsenabledel] = $toform[$completionminattemptsel] > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -510,9 +513,11 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
parent::data_postprocessing($data);
|
||||
if (!empty($data->completionunlocked)) {
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completionminattemptsenabled) || !$autocompletion) {
|
||||
$data->completionminattempts = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->{'completionminattemptsenabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionminattempts' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -534,9 +539,12 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['completionminattempts'])) {
|
||||
if ($data['attempts'] > 0 && $data['completionminattempts'] > $data['attempts']) {
|
||||
$errors['completionminattemptsgroup'] = get_string('completionminattemptserror', 'quiz');
|
||||
$suffix = $this->get_suffix();
|
||||
$completionminattemptsel = 'completionminattempts' . $suffix;
|
||||
if (!empty($data[$completionminattemptsel])) {
|
||||
if ($data['attempts'] > 0 && $data[$completionminattemptsel] > $data['attempts']) {
|
||||
$completionminattemptsgroupel = 'completionminattemptsgroup' . $suffix;
|
||||
$errors[$completionminattemptsgroupel] = get_string('completionminattemptserror', 'quiz');
|
||||
}
|
||||
}
|
||||
|
||||
@ -607,23 +615,36 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
*/
|
||||
public function add_completion_rules() {
|
||||
$mform = $this->_form;
|
||||
$suffix = $this->get_suffix();
|
||||
$items = [];
|
||||
|
||||
$mform->addElement('advcheckbox', 'completionattemptsexhausted', null,
|
||||
$completionattemptsexhaustedel = 'completionattemptsexhausted' . $suffix;
|
||||
$mform->addElement(
|
||||
'advcheckbox',
|
||||
$completionattemptsexhaustedel,
|
||||
null,
|
||||
get_string('completionattemptsexhausted', 'quiz'),
|
||||
['group' => 'cattempts']);
|
||||
$mform->disabledIf('completionattemptsexhausted', 'completionpassgrade', 'notchecked');
|
||||
$items[] = 'completionattemptsexhausted';
|
||||
['group' => 'cattempts']
|
||||
);
|
||||
$completionpassgradeel = 'completionpassgrade' . $suffix;
|
||||
$mform->disabledIf($completionattemptsexhaustedel, $completionpassgradeel, 'notchecked');
|
||||
$items[] = $completionattemptsexhaustedel;
|
||||
|
||||
$group = [];
|
||||
$group[] = $mform->createElement('checkbox', 'completionminattemptsenabled', '',
|
||||
get_string('completionminattempts', 'quiz'));
|
||||
$group[] = $mform->createElement('text', 'completionminattempts', '', ['size' => 3]);
|
||||
$mform->setType('completionminattempts', PARAM_INT);
|
||||
$mform->addGroup($group, 'completionminattemptsgroup', get_string('completionminattemptsgroup', 'quiz'), [' '], false);
|
||||
$mform->disabledIf('completionminattempts', 'completionminattemptsenabled', 'notchecked');
|
||||
|
||||
$items[] = 'completionminattemptsgroup';
|
||||
$completionminattemptsenabledel = 'completionminattemptsenabled' . $suffix;
|
||||
$group[] = $mform->createElement(
|
||||
'checkbox',
|
||||
$completionminattemptsenabledel,
|
||||
'',
|
||||
get_string('completionminattempts', 'quiz')
|
||||
);
|
||||
$completionminattemptsel = 'completionminattempts' . $suffix;
|
||||
$group[] = $mform->createElement('text', $completionminattemptsel, '', ['size' => 3]);
|
||||
$mform->setType($completionminattemptsel, PARAM_INT);
|
||||
$completionminattemptsgroupel = 'completionminattemptsgroup' . $suffix;
|
||||
$mform->addGroup($group, $completionminattemptsgroupel, get_string('completionminattemptsgroup', 'quiz'), ' ', false);
|
||||
$mform->disabledIf($completionminattemptsel, $completionminattemptsenabledel, 'notchecked');
|
||||
$items[] = $completionminattemptsgroupel;
|
||||
|
||||
return $items;
|
||||
}
|
||||
@ -635,8 +656,9 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
* @return bool True if one or more rules is enabled, false if none are.
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return !empty($data['completionattemptsexhausted']) ||
|
||||
!empty($data['completionminattemptsenabled']);
|
||||
$suffix = $this->get_suffix();
|
||||
return !empty($data['completionattemptsexhausted' . $suffix]) ||
|
||||
!empty($data['completionminattemptsenabled' . $suffix]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -271,8 +271,10 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
$this->standard_coursemodule_elements();
|
||||
|
||||
// A SCORM module should define this within itself and is not needed here.
|
||||
if ($mform->elementExists('completionpassgrade')) {
|
||||
$mform->removeElement('completionpassgrade');
|
||||
$suffix = $this->get_suffix();
|
||||
$completionpassgradeel = 'completionpassgrade' . $suffix;
|
||||
if ($mform->elementExists($completionpassgradeel)) {
|
||||
$mform->removeElement($completionpassgradeel);
|
||||
}
|
||||
|
||||
// Buttons.
|
||||
@ -332,24 +334,29 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
// Set some completion default data.
|
||||
$suffix = $this->get_suffix();
|
||||
$completionstatusrequiredel = 'completionstatusrequired' . $suffix;
|
||||
$cvalues = array();
|
||||
if (empty($this->_instance)) {
|
||||
// When in add mode, set a default completion rule that requires the SCORM's status be set to "Completed".
|
||||
$cvalues[4] = 1;
|
||||
} else if (!empty($defaultvalues['completionstatusrequired']) && !is_array($defaultvalues['completionstatusrequired'])) {
|
||||
if (!empty($defaultvalues[$completionstatusrequiredel]) && !is_array($defaultvalues[$completionstatusrequiredel])) {
|
||||
// Unpack values.
|
||||
foreach (scorm_status_options() as $key => $value) {
|
||||
if (($defaultvalues['completionstatusrequired'] & $key) == $key) {
|
||||
if (($defaultvalues[$completionstatusrequiredel] & $key) == $key) {
|
||||
$cvalues[$key] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($cvalues)) {
|
||||
$defaultvalues['completionstatusrequired'] = $cvalues;
|
||||
} else if (empty($this->_instance)) {
|
||||
// When in add mode, set a default completion rule that requires the SCORM's status be set to "Completed".
|
||||
$cvalues[4] = 1;
|
||||
}
|
||||
|
||||
if (!isset($defaultvalues['completionscorerequired']) || !strlen($defaultvalues['completionscorerequired'])) {
|
||||
$defaultvalues['completionscoredisabled'] = 1;
|
||||
if (!empty($cvalues)) {
|
||||
$defaultvalues[$completionstatusrequiredel] = $cvalues;
|
||||
}
|
||||
|
||||
$completionscorerequiredel = 'completionscorerequired' . $suffix;
|
||||
if (!isset($defaultvalues[$completionscorerequiredel]) || !strlen($defaultvalues[$completionscorerequiredel])) {
|
||||
$completionscoredisabledel = 'completionscoredisabled' . $suffix;
|
||||
$defaultvalues[$completionscoredisabledel] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -447,15 +454,18 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
$errors['timeclose'] = get_string('closebeforeopen', 'scorm');
|
||||
}
|
||||
}
|
||||
if (!empty($data['completionstatusallscos'])) {
|
||||
$suffix = $this->get_suffix();
|
||||
$completionstatusallscosel = 'completionstatusallscos' . $suffix;
|
||||
if (!empty($data[$completionstatusallscosel])) {
|
||||
$completionstatusrequiredel = 'completionstatusrequired' . $suffix;
|
||||
$requirestatus = false;
|
||||
foreach (scorm_status_options(true) as $key => $value) {
|
||||
if (!empty($data['completionstatusrequired'][$key])) {
|
||||
if (!empty($data[$completionstatusrequiredel][$key])) {
|
||||
$requirestatus = true;
|
||||
}
|
||||
}
|
||||
if (!$requirestatus) {
|
||||
$errors['completionstatusallscos'] = get_string('youmustselectastatus', 'scorm');
|
||||
$errors[$completionstatusallscosel] = get_string('youmustselectastatus', 'scorm');
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,27 +500,31 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
public function add_completion_rules() {
|
||||
$suffix = $this->get_suffix();
|
||||
$mform =& $this->_form;
|
||||
$items = array();
|
||||
|
||||
// Require score.
|
||||
$group = array();
|
||||
$group[] =& $mform->createElement('text', 'completionscorerequired', '', array('size' => 5));
|
||||
$group = [];
|
||||
$completionscorerequiredel = 'completionscorerequired' . $suffix;
|
||||
$group[] =& $mform->createElement('text', $completionscorerequiredel, '', ['size' => 5]);
|
||||
$group[] =& $mform->createElement('checkbox', 'completionscoredisabled', null, get_string('disable'));
|
||||
$mform->setType('completionscorerequired', PARAM_INT);
|
||||
$mform->addGroup($group, 'completionscoregroup', get_string('completionscorerequired', 'scorm'), '', false);
|
||||
$mform->addHelpButton('completionscoregroup', 'completionscorerequired', 'scorm');
|
||||
$mform->disabledIf('completionscorerequired', 'completionscoredisabled', 'checked');
|
||||
$mform->setDefault('completionscorerequired', 0);
|
||||
$mform->setType($completionscorerequiredel, PARAM_INT);
|
||||
$completionscoregroupel = 'completionscoregroup' . $suffix;
|
||||
$mform->addGroup($group, $completionscoregroupel, get_string('completionscorerequired', 'scorm'), '', false);
|
||||
$mform->addHelpButton($completionscoregroupel, 'completionscorerequired', 'scorm');
|
||||
$mform->disabledIf($completionscorerequiredel, 'completionscoredisabled', 'checked');
|
||||
$mform->setDefault($completionscorerequiredel, 0);
|
||||
|
||||
$items[] = 'completionscoregroup';
|
||||
$items[] = $completionscoregroupel;
|
||||
|
||||
// Require status.
|
||||
$first = true;
|
||||
$firstkey = null;
|
||||
$completionstatusrequiredel = 'completionstatusrequired' . $suffix;
|
||||
foreach (scorm_status_options(true) as $key => $value) {
|
||||
$name = null;
|
||||
$key = 'completionstatusrequired['.$key.']';
|
||||
$key = $completionstatusrequiredel . '['.$key.']';
|
||||
if ($first) {
|
||||
$name = get_string('completionstatusrequired', 'scorm');
|
||||
$first = false;
|
||||
@ -522,18 +536,20 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
}
|
||||
$mform->addHelpButton($firstkey, 'completionstatusrequired', 'scorm');
|
||||
|
||||
$mform->addElement('checkbox', 'completionstatusallscos', get_string('completionstatusallscos', 'scorm'));
|
||||
$mform->setType('completionstatusallscos', PARAM_BOOL);
|
||||
$mform->addHelpButton('completionstatusallscos', 'completionstatusallscos', 'scorm');
|
||||
$mform->setDefault('completionstatusallscos', 0);
|
||||
$items[] = 'completionstatusallscos';
|
||||
$completionstatusallscosel = 'completionstatusallscos' . $suffix;
|
||||
$mform->addElement('checkbox', $completionstatusallscosel, get_string('completionstatusallscos', 'scorm'));
|
||||
$mform->setType($completionstatusallscosel, PARAM_BOOL);
|
||||
$mform->addHelpButton($completionstatusallscosel, 'completionstatusallscos', 'scorm');
|
||||
$mform->setDefault($completionstatusallscosel, 0);
|
||||
$items[] = $completionstatusallscosel;
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function completion_rule_enabled($data) {
|
||||
$status = !empty($data['completionstatusrequired']);
|
||||
$score = empty($data['completionscoredisabled']) && strlen($data['completionscorerequired']);
|
||||
$suffix = $this->get_suffix();
|
||||
$status = !empty($data['completionstatusrequired' . $suffix]);
|
||||
$score = empty($data['completionscoredisabled' . $suffix]) && strlen($data['completionscorerequired' . $suffix]);
|
||||
|
||||
return $status || $score;
|
||||
}
|
||||
@ -550,8 +566,9 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
parent::data_postprocessing($data);
|
||||
// Convert completionstatusrequired to a proper integer, if any.
|
||||
$total = 0;
|
||||
if (isset($data->completionstatusrequired) && is_array($data->completionstatusrequired)) {
|
||||
foreach ($data->completionstatusrequired as $state => $value) {
|
||||
$suffix = $this->get_suffix();
|
||||
if (isset($data->{'completionstatusrequired' . $suffix}) && is_array($data->{'completionstatusrequired' . $suffix})) {
|
||||
foreach ($data->{'completionstatusrequired' . $suffix} as $state => $value) {
|
||||
if ($value) {
|
||||
$total |= $state;
|
||||
}
|
||||
@ -559,21 +576,21 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
if (!$total) {
|
||||
$total = null;
|
||||
}
|
||||
$data->completionstatusrequired = $total;
|
||||
$data->{'completionstatusrequired' . $suffix} = $total;
|
||||
}
|
||||
|
||||
if (!empty($data->completionunlocked)) {
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
$autocompletion = isset($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = isset($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
|
||||
if (!(isset($data->completionstatusrequired) && $autocompletion)) {
|
||||
$data->completionstatusrequired = null;
|
||||
if (!(isset($data->{'completionstatusrequired' . $suffix}) && $autocompletion)) {
|
||||
$data->{'completionstatusrequired' . $suffix} = null;
|
||||
}
|
||||
// Else do nothing: completionstatusrequired has been already converted
|
||||
// into a correct integer representation.
|
||||
// Else do nothing: completionstatusrequired has been already converted into a correct integer representation.
|
||||
|
||||
if (!empty($data->completionscoredisabled) || !$autocompletion) {
|
||||
$data->completionscorerequired = null;
|
||||
if (!empty($data->{'completionscoredisabled' . $suffix}) || !$autocompletion) {
|
||||
$data->{'completionscorerequired' . $suffix} = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,10 +58,11 @@ class mod_survey_mod_form extends moodleform_mod {
|
||||
parent::data_postprocessing($data);
|
||||
if (!empty($data->completionunlocked)) {
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
$autocompletion = !empty($data->completion) &&
|
||||
$data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (!$autocompletion || empty($data->completionsubmit)) {
|
||||
$data->completionsubmit = 0;
|
||||
$suffix = $this->get_suffix();
|
||||
$completion = $data->{'completion' . $suffix};
|
||||
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (!$autocompletion || empty($data->{'completionsubmit' . $suffix})) {
|
||||
$data->{'completionsubmit' . $suffix} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,19 +73,21 @@ class mod_survey_mod_form extends moodleform_mod {
|
||||
*/
|
||||
public function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
$mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'survey'));
|
||||
$suffix = $this->get_suffix();
|
||||
$completionsubmitel = 'completionsubmit' . $suffix;
|
||||
$mform->addElement('checkbox', $completionsubmitel, '', get_string('completionsubmit', 'survey'));
|
||||
// Enable this completion rule by default.
|
||||
$mform->setDefault('completionsubmit', 1);
|
||||
return array('completionsubmit');
|
||||
$mform->setDefault($completionsubmitel, 1);
|
||||
return [$completionsubmitel];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable completion rules
|
||||
* @param stdclass $data
|
||||
* @return array
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return !empty($data['completionsubmit']);
|
||||
$suffix = $this->get_suffix();
|
||||
return !empty($data['completionsubmit' . $suffix]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user