Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/profile/field/menu/field.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class profile_field_menu extends profile_field_base {
00004     var $options;
00005     var $datakey;
00006 
00012     function profile_field_menu($fieldid=0, $userid=0) {
00013         //first call parent constructor
00014         $this->profile_field_base($fieldid, $userid);
00015 
00017         $options = explode("\n", $this->field->param1);
00018         $this->options = array();
00019         if ($this->field->required){
00020             $this->options[''] = get_string('choose').'...';
00021         }
00022         foreach($options as $key => $option) {
00023             $this->options[$key] = format_string($option);//multilang formatting
00024         }
00025 
00027         if ($this->data !== NULL) {
00028             $this->datakey = (int)array_search($this->data, $this->options);
00029         }
00030     }
00031 
00037     function edit_field_add(&$mform) {
00038         $mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options);
00039     }
00040 
00045     function edit_field_set_default(&$mform) {
00046         if (FALSE !==array_search($this->field->defaultdata, $this->options)){
00047             $defaultkey = (int)array_search($this->field->defaultdata, $this->options);
00048         } else {
00049             $defaultkey = '';
00050         }
00051         $mform->setDefault($this->inputname, $defaultkey);
00052     }
00053 
00060     function edit_save_data_preprocess($key) {
00061         return isset($this->options[$key]) ? $this->options[$key] : NULL;
00062     }
00063 
00070     function edit_load_user_data(&$user) {
00071         $user->{$this->inputname} = $this->datakey;
00072     }
00073 
00078     function edit_field_set_locked(&$mform) {
00079         if (!$mform->elementExists($this->inputname)) {
00080             return;
00081         }
00082         if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
00083             $mform->hardFreeze($this->inputname);
00084             $mform->setConstant($this->inputname, $this->datakey);
00085         }
00086     }
00087 }
00088 
00089 
 All Data Structures Namespaces Files Functions Variables Enumerations