[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/data/field/date/ -> field.class.php (source)

   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) {
  38          global $DB, $OUTPUT;
  39  
  40          if ($recordid) {
  41              $content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
  42          } else {
  43              $content = time();
  44          }
  45  
  46          $str = '<div title="'.s($this->field->description).'">';
  47          $dayselector = html_writer::select_time('days', 'field_'.$this->field->id.'_day', $content);
  48          $monthselector = html_writer::select_time('months', 'field_'.$this->field->id.'_month', $content);
  49          $yearselector = html_writer::select_time('years', 'field_'.$this->field->id.'_year', $content);
  50          $str .= $dayselector . $monthselector . $yearselector;
  51          $str .= '</div>';
  52  
  53          return $str;
  54      }
  55  
  56      //Enable the following three functions once core API issues have been addressed.
  57      function display_search_field($value=0) {
  58          $selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value['timestamp'])
  59             . html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value['timestamp'])
  60             . html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value['timestamp']);
  61          $datecheck = html_writer::checkbox('f_'.$this->field->id.'_z', 1, $value['usedate']);
  62          $str = $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data');
  63  
  64          return $str;
  65      }
  66  
  67      function generate_sql($tablealias, $value) {
  68          global $DB;
  69  
  70          static $i=0;
  71          $i++;
  72          $name = "df_date_$i";
  73          $varcharcontent = $DB->sql_compare_text("{$tablealias}.content");
  74          return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name => $value['timestamp']));
  75      }
  76  
  77      function parse_search_field() {
  78          $day   = optional_param('f_'.$this->field->id.'_d', 0, PARAM_INT);
  79          $month = optional_param('f_'.$this->field->id.'_m', 0, PARAM_INT);
  80          $year  = optional_param('f_'.$this->field->id.'_y', 0, PARAM_INT);
  81          $usedate = optional_param('f_'.$this->field->id.'_z', 0, PARAM_INT);
  82          $data = array();
  83          if (!empty($day) && !empty($month) && !empty($year) && $usedate == 1) {
  84              $data['timestamp'] = make_timestamp($year, $month, $day, 12, 0, 0, 0, false);
  85              $data['usedate'] = 1;
  86              return $data;
  87          } else {
  88              return 0;
  89          }
  90      }
  91  
  92      function update_content($recordid, $value, $name='') {
  93          global $DB;
  94  
  95          $names = explode('_',$name);
  96          $name = $names[2];          // day month or year
  97  
  98          $this->$name = $value;
  99  
 100          if ($this->day and $this->month and $this->year) {  // All of them have been collected now
 101  
 102              $content = new stdClass();
 103              $content->fieldid = $this->field->id;
 104              $content->recordid = $recordid;
 105              $content->content = make_timestamp($this->year, $this->month, $this->day, 12, 0, 0, 0, false);
 106  
 107              if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
 108                  $content->id = $oldcontent->id;
 109                  return $DB->update_record('data_content', $content);
 110              } else {
 111                  return $DB->insert_record('data_content', $content);
 112              }
 113          }
 114      }
 115  
 116      function display_browse_field($recordid, $template) {
 117          global $CFG, $DB;
 118  
 119          if ($content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
 120              return userdate($content, get_string('strftimedate'), 0);
 121          }
 122      }
 123  
 124      function get_sort_sql($fieldname) {
 125          global $DB;
 126          return $DB->sql_cast_char2int($fieldname, true);
 127      }
 128  
 129  
 130  }
 131  
 132  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1