|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00003 // // 00004 // NOTICE OF COPYRIGHT // 00005 // // 00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 00007 // http://moodle.org // 00008 // // 00009 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com // 00010 // // 00011 // This program is free software; you can redistribute it and/or modify // 00012 // it under the terms of the GNU General Public License as published by // 00013 // the Free Software Foundation; either version 2 of the License, or // 00014 // (at your option) any later version. // 00015 // // 00016 // This program is distributed in the hope that it will be useful, // 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00019 // GNU General Public License for more details: // 00020 // // 00021 // http://www.gnu.org/copyleft/gpl.html // 00022 // // 00024 00025 //2/19/07: Advanced search of the date field is currently disabled because it does not track 00026 // pre 1970 dates and does not handle blank entrys. Advanced search functionality for this field 00027 // type can be enabled once these issues are addressed in the core API. 00028 00029 class data_field_date extends data_field_base { 00030 00031 var $type = 'date'; 00032 00033 var $day = 0; 00034 var $month = 0; 00035 var $year = 0; 00036 00037 function display_add_field($recordid=0) { 00038 global $DB, $OUTPUT; 00039 00040 if ($recordid) { 00041 $content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); 00042 } else { 00043 $content = time(); 00044 } 00045 00046 $str = '<div title="'.s($this->field->description).'">'; 00047 $dayselector = html_writer::select_time('days', 'field_'.$this->field->id.'_day', $content); 00048 $monthselector = html_writer::select_time('months', 'field_'.$this->field->id.'_month', $content); 00049 $yearselector = html_writer::select_time('years', 'field_'.$this->field->id.'_year', $content); 00050 $str .= $dayselector . $monthselector . $yearselector; 00051 $str .= '</div>'; 00052 00053 return $str; 00054 } 00055 00056 //Enable the following three functions once core API issues have been addressed. 00057 function display_search_field($value=0) { 00058 $selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value) 00059 . html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value) 00060 . html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value); 00061 return $selectors; 00062 00063 //return print_date_selector('f_'.$this->field->id.'_d', 'f_'.$this->field->id.'_m', 'f_'.$this->field->id.'_y', $value, true); 00064 } 00065 00066 function generate_sql($tablealias, $value) { 00067 global $DB; 00068 00069 static $i=0; 00070 $i++; 00071 $name = "df_date_$i"; 00072 $varcharcontent = $DB->sql_compare_text("{$tablealias}.content"); 00073 return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value)); 00074 } 00075 00076 function parse_search_field() { 00077 00078 $day = optional_param('f_'.$this->field->id.'_d', 0, PARAM_INT); 00079 $month = optional_param('f_'.$this->field->id.'_m', 0, PARAM_INT); 00080 $year = optional_param('f_'.$this->field->id.'_y', 0, PARAM_INT); 00081 if (!empty($day) && !empty($month) && !empty($year)) { 00082 return make_timestamp($year, $month, $day, 12, 0, 0, 0, false); 00083 } 00084 else { 00085 return 0; 00086 } 00087 00088 } 00089 00090 function update_content($recordid, $value, $name='') { 00091 global $DB; 00092 00093 $names = explode('_',$name); 00094 $name = $names[2]; // day month or year 00095 00096 $this->$name = $value; 00097 00098 if ($this->day and $this->month and $this->year) { // All of them have been collected now 00099 00100 $content = new stdClass(); 00101 $content->fieldid = $this->field->id; 00102 $content->recordid = $recordid; 00103 $content->content = make_timestamp($this->year, $this->month, $this->day, 12, 0, 0, 0, false); 00104 00105 if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 00106 $content->id = $oldcontent->id; 00107 return $DB->update_record('data_content', $content); 00108 } else { 00109 return $DB->insert_record('data_content', $content); 00110 } 00111 } 00112 } 00113 00114 function display_browse_field($recordid, $template) { 00115 global $CFG, $DB; 00116 00117 if ($content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 00118 return userdate($content, get_string('strftimedate'), 0); 00119 } 00120 } 00121 00122 function get_sort_sql($fieldname) { 00123 global $DB; 00124 return $DB->sql_cast_char2int($fieldname, true); 00125 } 00126 00127 00128 } 00129 00130