9bab24cb9e753aa657cb33aa3e99740aac72b98e
[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             'timezone'  => 99,
30             'applydst'  => true,
31             'optional'  => $optional
32         );
34         // Check if they wanted to include time as well
35         if (!empty($this->field->param3)) {
36             $mform->addElement('date_time_selector', $this->inputname, format_string($this->field->name), $attributes);
37         } else {
38             $mform->addElement('date_selector', $this->inputname, format_string($this->field->name), $attributes);
39         }
41         $mform->setType($this->inputname, PARAM_INT);
42         $mform->setDefault($this->inputname, time());
43     }
45     /**
46      * Display the data for this field
47      */
48     function display_data() {
49         // Check if time was specified
50         if (!empty($this->field->param3)) {
51             $format = get_string('strftimedaydatetime', 'langconfig');
52         } else {
53             $format = get_string('strftimedate', 'langconfig');
54         }
56         // Check if a date has been specified
57         if (empty($this->data)) {
58             return get_string('notset', 'profilefield_datetime');
59         } else {
60             return userdate($this->data, $format);
61         }
62     }
63 }