|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00011 class profile_field_datetime extends profile_field_base { 00012 00018 function edit_field_add($mform) { 00019 // Check if the field is required 00020 if ($this->field->required) { 00021 $optional = false; 00022 } else { 00023 $optional = true; 00024 } 00025 00026 $attributes = array( 00027 'startyear' => $this->field->param1, 00028 'stopyear' => $this->field->param2, 00029 'timezone' => 99, 00030 'applydst' => true, 00031 'optional' => $optional 00032 ); 00033 00034 // Check if they wanted to include time as well 00035 if (!empty($this->field->param3)) { 00036 $mform->addElement('date_time_selector', $this->inputname, format_string($this->field->name), $attributes); 00037 } else { 00038 $mform->addElement('date_selector', $this->inputname, format_string($this->field->name), $attributes); 00039 } 00040 00041 $mform->setType($this->inputname, PARAM_INT); 00042 $mform->setDefault($this->inputname, time()); 00043 } 00044 00048 function display_data() { 00049 // Check if time was specified 00050 if (!empty($this->field->param3)) { 00051 $format = get_string('strftimedaydatetime', 'langconfig'); 00052 } else { 00053 $format = get_string('strftimedate', 'langconfig'); 00054 } 00055 00056 // Check if a date has been specified 00057 if (empty($this->data)) { 00058 return get_string('notset', 'profilefield_datetime'); 00059 } else { 00060 return userdate($this->data, $format); 00061 } 00062 } 00063 }