diff --git a/user/profile/field/checkbox/define.class.php b/user/profile/field/checkbox/define.class.php new file mode 100644 index 0000000000000..24b469d05b407 --- /dev/null +++ b/user/profile/field/checkbox/define.class.php @@ -0,0 +1,13 @@ +addElement('selectyesno', 'defaultdata', get_string('profiledefaultchecked', 'profilefield_checkbox')); + $form->setDefault('defaultdata', 0); // defaults to 'no' + $form->setType('defaultdata', PARAM_BOOL); + } +} + +?> diff --git a/user/profile/field/checkbox/field.class.php b/user/profile/field/checkbox/field.class.php new file mode 100644 index 0000000000000..21e9ca9596f8d --- /dev/null +++ b/user/profile/field/checkbox/field.class.php @@ -0,0 +1,47 @@ +profile_field_base($fieldid, $userid); + + if (!empty($this->field)) { + $datafield = get_field('user_info_data', 'data', 'userid', $this->userid, 'fieldid', $this->fieldid); + if ($datafield !== false) { + $this->data = $datafield; + } else { + $this->data = $this->field->defaultdata; + } + } + } + + function edit_field_add(&$mform) { + /// Create the form field + $checkbox = &$mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name)); + if ($this->data == '1') { + $checkbox->setChecked(true); + } + $mform->setType($this->inputname, PARAM_BOOL); + if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { + $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client'); + } + } + + /** + * Display the data for this field + */ + function display_data() { + $options->para = false; + $checked = intval($this->data) === 1 ? 'checked="checked"' : ''; + return ''; + } + +} + +?>