|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 class profile_field_checkbox extends profile_field_base { 00004 00010 function profile_field_checkbox($fieldid=0, $userid=0) { 00011 global $DB; 00012 //first call parent constructor 00013 $this->profile_field_base($fieldid, $userid); 00014 00015 if (!empty($this->field)) { 00016 $datafield = $DB->get_field('user_info_data', 'data', array('userid' => $this->userid, 'fieldid' => $this->fieldid)); 00017 if ($datafield !== false) { 00018 $this->data = $datafield; 00019 } else { 00020 $this->data = $this->field->defaultdata; 00021 } 00022 } 00023 } 00024 00025 function edit_field_add(&$mform) { 00027 $checkbox = &$mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name)); 00028 if ($this->data == '1') { 00029 $checkbox->setChecked(true); 00030 } 00031 $mform->setType($this->inputname, PARAM_BOOL); 00032 if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { 00033 $mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client'); 00034 } 00035 } 00036 00040 function display_data() { 00041 $options = new stdClass(); 00042 $options->para = false; 00043 $checked = intval($this->data) === 1 ? 'checked="checked"' : ''; 00044 return '<input disabled="disabled" type="checkbox" name="'.$this->inputname.'" '.$checked.' />'; 00045 } 00046 00047 } 00048 00049