[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/data/field/menu/ -> 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  class data_field_menu extends data_field_base {
  26  
  27      var $type = 'menu';
  28  
  29      function display_add_field($recordid=0) {
  30          global $DB, $OUTPUT;
  31  
  32          if ($recordid){
  33              $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
  34              $content = trim($content);
  35          } else {
  36              $content = '';
  37          }
  38  
  39          $str = '<div title="'.s($this->field->description).'">';
  40  
  41          $options = array();
  42          $rawoptions = explode("\n",$this->field->param1);
  43          foreach ($rawoptions as $option) {
  44              $option = trim($option);
  45              if ($option) {
  46                  $options[$option] = $option;
  47              }
  48          }
  49  
  50          $str .= html_writer::label(get_string('menuchoose', 'data'), 'field_'.$this->field->id, false, array('class' => 'accesshide'));
  51          $str .= html_writer::select($options, 'field_'.$this->field->id, $content, array(''=>get_string('menuchoose', 'data')), array('id'=>'field_'.$this->field->id));
  52  
  53          $str .= '</div>';
  54  
  55          return $str;
  56      }
  57  
  58      function display_search_field($content = '') {
  59          global $CFG, $DB;
  60  
  61          $varcharcontent =  $DB->sql_compare_text('content', 255);
  62          $sql = "SELECT DISTINCT $varcharcontent AS content
  63                    FROM {data_content}
  64                   WHERE fieldid=? AND content IS NOT NULL";
  65  
  66          $usedoptions = array();
  67          if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
  68              foreach ($used as $data) {
  69                  $value = $data->content;
  70                  if ($value === '') {
  71                      continue;
  72                  }
  73                  $usedoptions[$value] = $value;
  74              }
  75          }
  76  
  77          $options = array();
  78          foreach (explode("\n",$this->field->param1) as $option) {
  79              $option = trim($option);
  80              if (!isset($usedoptions[$option])) {
  81                  continue;
  82              }
  83              $options[$option] = $option;
  84          }
  85          if (!$options) {
  86              // oh, nothing to search for
  87              return '';
  88          }
  89  
  90          $return = html_writer::label(get_string('namemenu', 'data'), 'menuf_'. $this->field->id, false, array('class' => 'accesshide'));
  91          $return .= html_writer::select($options, 'f_'.$this->field->id, $content);
  92          return $return;
  93      }
  94  
  95       function parse_search_field() {
  96              return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
  97       }
  98  
  99      function generate_sql($tablealias, $value) {
 100          global $DB;
 101  
 102          static $i=0;
 103          $i++;
 104          $name = "df_menu_$i";
 105          $varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
 106  
 107          return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
 108      }
 109  
 110  }
 111  
 112  


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