mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-14299 New checkbox profile field type.
Credit to Brian King.
- Loading branch information
ikawhero
committed
Jul 15, 2008
1 parent
c68c552
commit 60d922d
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php //$Id: | ||
|
||
class profile_define_checkbox extends profile_define_base { | ||
|
||
function define_form_specific(&$form) { | ||
/// select whether or not this should be checked by default | ||
$form->addElement('selectyesno', 'defaultdata', get_string('profiledefaultchecked', 'profilefield_checkbox')); | ||
$form->setDefault('defaultdata', 0); // defaults to 'no' | ||
$form->setType('defaultdata', PARAM_BOOL); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php //$Id: | ||
|
||
class profile_field_checkbox extends profile_field_base { | ||
|
||
/** | ||
* Constructor method. | ||
* Pulls out the options for the checkbox from the database and sets the | ||
* the corresponding key for the data if it exists | ||
*/ | ||
function profile_field_checkbox($fieldid=0, $userid=0) { | ||
//first call parent constructor | ||
$this->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 '<input disabled="disabled" type="checkbox" name="'.$this->inputname.'" '.$checked.' />'; | ||
} | ||
|
||
} | ||
|
||
?> |