Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / user / profile / field / checkbox / field.class.php
blob09989a40fdcea63ff9440b276813c19eea1a6d6c
1 <?php // $Id$
3 class profile_field_checkbox extends profile_field_base {
5 /**
6 * Constructor method.
7 * Pulls out the options for the checkbox from the database and sets the
8 * the corresponding key for the data if it exists
9 */
10 function profile_field_checkbox($fieldid=0, $userid=0) {
11 //first call parent constructor
12 $this->profile_field_base($fieldid, $userid);
14 if (!empty($this->field)) {
15 $datafield = get_field('user_info_data', 'data', 'userid', $this->userid, 'fieldid', $this->fieldid);
16 if ($datafield !== false) {
17 $this->data = $datafield;
18 } else {
19 $this->data = $this->field->defaultdata;
24 function edit_field_add(&$mform) {
25 /// Create the form field
26 $checkbox = &$mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
27 if ($this->data == '1') {
28 $checkbox->setChecked(true);
30 $mform->setType($this->inputname, PARAM_BOOL);
31 if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
32 $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client');
36 /**
37 * Display the data for this field
39 function display_data() {
40 $options->para = false;
41 $checked = intval($this->data) === 1 ? 'checked="checked"' : '';
42 return '<input disabled="disabled" type="checkbox" name="'.$this->inputname.'" '.$checked.' />';