Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / data / field / date / field.class.php
blobbc35d4aea25491b9db734a42d18819853dcbfa42
1 <?php // $Id$
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
8 // //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 //2/19/07: Advanced search of the date field is currently disabled because it does not track
26 // pre 1970 dates and does not handle blank entrys. Advanced search functionality for this field
27 // type can be enabled once these issues are addressed in the core API.
29 class data_field_date extends data_field_base {
31 var $type = 'date';
33 var $day = 0;
34 var $month = 0;
35 var $year = 0;
37 function data_field_date($field=0, $data=0) {
38 parent::data_field_base($field, $data);
41 function display_add_field($recordid=0) {
43 if ($recordid) {
44 $content = (int) get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
45 } else {
46 $content = time();
49 $str = '<div title="'.s($this->field->description).'">';
50 $str .= print_date_selector('field_'.$this->field->id.'_day', 'field_'.$this->field->id.'_month',
51 'field_'.$this->field->id.'_year', $content, true);
52 $str .= '</div>';
54 return $str;
57 //Enable the following three functions once core API issues have been addressed.
58 function display_search_field($value=0) {
59 return false;
60 //return print_date_selector('f_'.$this->field->id.'_d', 'f_'.$this->field->id.'_m', 'f_'.$this->field->id.'_y', $value, true);
63 function generate_sql($tablealias, $value) {
64 return ' 1=1 ';
65 //return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') ";
68 function parse_search_field() {
69 return '';
70 /*
71 $day = optional_param('f_'.$this->field->id.'_d', 0, PARAM_INT);
72 $month = optional_param('f_'.$this->field->id.'_m', 0, PARAM_INT);
73 $year = optional_param('f_'.$this->field->id.'_y', 0, PARAM_INT);
74 if (!empty($day) && !empty($month) && !empty($year)) {
75 return make_timestamp($year, $month, $day, 12, 0, 0, 0, false);
77 else {
78 return 0;
83 function update_content($recordid, $value, $name='') {
85 $names = explode('_',$name);
86 $name = $names[2]; // day month or year
88 $this->$name = $value;
90 if ($this->day and $this->month and $this->year) { // All of them have been collected now
92 $content = new object;
93 $content->fieldid = $this->field->id;
94 $content->recordid = $recordid;
95 $content->content = make_timestamp($this->year, $this->month, $this->day, 12, 0, 0, 0, false);
97 if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
98 $content->id = $oldcontent->id;
99 return update_record('data_content', $content);
100 } else {
101 return insert_record('data_content', $content);
106 function display_browse_field($recordid, $template) {
108 global $CFG;
110 if ($content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid)){
111 return userdate($content, get_string('strftimedate'), 0);
115 function get_sort_sql($fieldname) {
116 return 'CAST('.$fieldname.' AS unsigned)';