MDL-27562 formslib: applydst should be always true, hence option removed from datesel...
[moodle.git] / user / profile / field / datetime / field.class.php
1 <?php
3 /**
4  * Handles displaying and editing the datetime field
5  *
6  * @author Mark Nelson <mark@moodle.com.au>
7  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8  * @version 20101022
9  */
11 class profile_field_datetime extends profile_field_base {
13     /**
14      * Handles editing datetime fields
15      *
16      * @param object moodleform instance
17      */
18     function edit_field_add($mform) {
19         // Check if the field is required
20         if ($this->field->required) {
21             $optional = false;
22         } else {
23             $optional = true;
24         }
26         $attributes = array(
27             'startyear' => $this->field->param1,
28             'stopyear'  => $this->field->param2,
29             'optional'  => $optional
30         );
32         // Check if they wanted to include time as well
33         if (!empty($this->field->param3)) {
34             $mform->addElement('date_time_selector', $this->inputname, format_string($this->field->name), $attributes);
35         } else {
36             $mform->addElement('date_selector', $this->inputname, format_string($this->field->name), $attributes);
37         }
39         $mform->setType($this->inputname, PARAM_INT);
40         $mform->setDefault($this->inputname, time());
41     }
43     /**
44      * Display the data for this field
45      */
46     function display_data() {
47         // Check if time was specified
48         if (!empty($this->field->param3)) {
49             $format = get_string('strftimedaydatetime', 'langconfig');
50         } else {
51             $format = get_string('strftimedate', 'langconfig');
52         }
54         // Check if a date has been specified
55         if (empty($this->data)) {
56             return get_string('notset', 'profilefield_datetime');
57         } else {
58             return userdate($this->data, $format);
59         }
60     }
61 }