[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 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 /////////////////////////////////////////////////////////////////////////// 24 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. 28 29 class data_field_date extends data_field_base { 30 31 var $type = 'date'; 32 33 var $day = 0; 34 var $month = 0; 35 var $year = 0; 36 37 function display_add_field($recordid = 0, $formdata = null) { 38 global $DB, $OUTPUT; 39 40 if ($formdata) { 41 $fieldname = 'field_' . $this->field->id . '_day'; 42 $day = $formdata->$fieldname; 43 $fieldname = 'field_' . $this->field->id . '_month'; 44 $month = $formdata->$fieldname; 45 $fieldname = 'field_' . $this->field->id . '_year'; 46 $year = $formdata->$fieldname; 47 48 $calendartype = \core_calendar\type_factory::get_calendar_instance(); 49 $gregoriandate = $calendartype->convert_to_gregorian($year, $month, $day); 50 $content = make_timestamp( 51 $gregoriandate['year'], 52 $gregoriandate['month'], 53 $gregoriandate['day'], 54 $gregoriandate['hour'], 55 $gregoriandate['minute'], 56 0, 57 0, 58 false); 59 } else if ($recordid) { 60 $content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); 61 } else { 62 $content = time(); 63 } 64 65 $str = '<div title="'.s($this->field->description).'" class="mod-data-input">'; 66 $dayselector = html_writer::select_time('days', 'field_'.$this->field->id.'_day', $content); 67 $monthselector = html_writer::select_time('months', 'field_'.$this->field->id.'_month', $content); 68 $yearselector = html_writer::select_time('years', 'field_'.$this->field->id.'_year', $content); 69 $str .= $dayselector . $monthselector . $yearselector; 70 $str .= '</div>'; 71 72 return $str; 73 } 74 75 //Enable the following three functions once core API issues have been addressed. 76 function display_search_field($value=0) { 77 $selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value['timestamp']) 78 . html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value['timestamp']) 79 . html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value['timestamp']); 80 $datecheck = html_writer::checkbox('f_'.$this->field->id.'_z', 1, $value['usedate']); 81 $str = $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data'); 82 83 return $str; 84 } 85 86 function generate_sql($tablealias, $value) { 87 global $DB; 88 89 static $i=0; 90 $i++; 91 $name = "df_date_$i"; 92 $varcharcontent = $DB->sql_compare_text("{$tablealias}.content"); 93 return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name => $value['timestamp'])); 94 } 95 96 function parse_search_field() { 97 $day = optional_param('f_'.$this->field->id.'_d', 0, PARAM_INT); 98 $month = optional_param('f_'.$this->field->id.'_m', 0, PARAM_INT); 99 $year = optional_param('f_'.$this->field->id.'_y', 0, PARAM_INT); 100 $usedate = optional_param('f_'.$this->field->id.'_z', 0, PARAM_INT); 101 $data = array(); 102 if (!empty($day) && !empty($month) && !empty($year) && $usedate == 1) { 103 $calendartype = \core_calendar\type_factory::get_calendar_instance(); 104 $gregoriandate = $calendartype->convert_to_gregorian($year, $month, $day); 105 106 $data['timestamp'] = make_timestamp( 107 $gregoriandate['year'], 108 $gregoriandate['month'], 109 $gregoriandate['day'], 110 $gregoriandate['hour'], 111 $gregoriandate['minute'], 112 0, 113 0, 114 false); 115 $data['usedate'] = 1; 116 return $data; 117 } else { 118 return 0; 119 } 120 } 121 122 function update_content($recordid, $value, $name='') { 123 global $DB; 124 125 $names = explode('_',$name); 126 $name = $names[2]; // day month or year 127 128 $this->$name = $value; 129 130 if ($this->day and $this->month and $this->year) { // All of them have been collected now 131 132 $content = new stdClass(); 133 $content->fieldid = $this->field->id; 134 $content->recordid = $recordid; 135 136 $calendartype = \core_calendar\type_factory::get_calendar_instance(); 137 $gregoriandate = $calendartype->convert_to_gregorian($this->year, $this->month, $this->day); 138 $content->content = make_timestamp( 139 $gregoriandate['year'], 140 $gregoriandate['month'], 141 $gregoriandate['day'], 142 $gregoriandate['hour'], 143 $gregoriandate['minute'], 144 0, 145 0, 146 false); 147 148 if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 149 $content->id = $oldcontent->id; 150 return $DB->update_record('data_content', $content); 151 } else { 152 return $DB->insert_record('data_content', $content); 153 } 154 } 155 } 156 157 function display_browse_field($recordid, $template) { 158 global $CFG, $DB; 159 160 if ($content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 161 return userdate($content, get_string('strftimedate'), 0); 162 } 163 } 164 165 function get_sort_sql($fieldname) { 166 global $DB; 167 return $DB->sql_cast_char2int($fieldname, true); 168 } 169 170 171 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |