[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/data/field/radiobutton/ -> 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_radiobutton extends data_field_base {
  26  
  27      var $type = 'radiobutton';
  28  
  29      function display_add_field($recordid=0) {
  30          global $CFG, $DB;
  31  
  32          if ($recordid){
  33              $content = trim($DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)));
  34          } else {
  35              $content = '';
  36          }
  37  
  38          $str = '<div title="'.s($this->field->description).'">';
  39          $str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
  40  
  41          $i = 0;
  42          foreach (explode("\n",$this->field->param1) as $radio) {
  43              $radio = trim($radio);
  44              if ($radio === '') {
  45                  continue; // skip empty lines
  46              }
  47              $str .= '<input type="radio" id="field_'.$this->field->id.'_'.$i.'" name="field_' . $this->field->id . '" ';
  48              $str .= 'value="' . s($radio) . '" ';
  49  
  50              if ($content == $radio) {
  51                  // Selected by user.
  52                  $str .= 'checked />';
  53              } else {
  54                  $str .= '/>';
  55              }
  56  
  57              $str .= '<label for="field_'.$this->field->id.'_'.$i.'">'.$radio.'</label><br />';
  58              $i++;
  59          }
  60          $str .= '</fieldset>';
  61          $str .= '</div>';
  62          return $str;
  63      }
  64  
  65       function display_search_field($value = '') {
  66          global $CFG, $DB;
  67  
  68          $varcharcontent = $DB->sql_compare_text('content', 255);
  69          $used = $DB->get_records_sql(
  70              "SELECT DISTINCT $varcharcontent AS content
  71                 FROM {data_content}
  72                WHERE fieldid=?
  73               ORDER BY $varcharcontent", array($this->field->id));
  74  
  75          $options = array();
  76          if(!empty($used)) {
  77              foreach ($used as $rec) {
  78                  $options[$rec->content] = $rec->content;  //Build following indicies from the sql.
  79              }
  80          }
  81          $return = html_writer::label(get_string('nameradiobutton', 'data'), 'menuf_'. $this->field->id, false, array('class' => 'accesshide'));
  82          $return .= html_writer::select($options, 'f_'.$this->field->id, $value);
  83          return $return;
  84      }
  85  
  86      function parse_search_field() {
  87          return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
  88      }
  89  
  90      function generate_sql($tablealias, $value) {
  91          global $DB;
  92  
  93          static $i=0;
  94          $i++;
  95          $name = "df_radiobutton_$i";
  96          $varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
  97  
  98          return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
  99      }
 100  
 101  }
 102  


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