MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / data / field / radiobutton / field.class.php
blob0ed463184f10a6d712a21dff46ed79a159211a05
1 <?php // $Id$
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 ///////////////////////////////////////////////////////////////////////////
25 class data_field_radiobutton extends data_field_base {
27 var $type = 'radiobutton';
29 function data_field_radiobutton($field=0, $data=0) {
30 parent::data_field_base($field, $data);
34 function display_add_field($recordid=0) {
35 global $CFG;
37 if ($recordid){
38 $content = trim(get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid));
39 } else {
40 $content = '';
43 $str = '<div title="'.s($this->field->description).'">';
44 $str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
46 $i = 0;
47 foreach (explode("\n",$this->field->param1) as $radio) {
48 $radio = trim($radio);
49 if ($radio === '') {
50 continue; // skip empty lines
52 $str .= '<input type="radio" id="field_'.$this->field->id.'_'.$i.'" name="field_' . $this->field->id . '" ';
53 $str .= 'value="' . s($radio) . '" ';
55 if ($content == $radio) {
56 // Selected by user.
57 $str .= 'checked />';
58 } else {
59 $str .= '/>';
62 $str .= '<label for="field_'.$this->field->id.'_'.$i.'">'.$radio.'</label><br />';
63 $i++;
65 $str .= '</fieldset>';
66 $str .= '</div>';
67 return $str;
70 function display_search_field($value = '') {
71 global $CFG;
72 $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
73 $options = array();
74 if(!empty($temp)) {
75 $options[''] = ''; //Make first index blank.
76 foreach ($temp as $key) {
77 $options[$key] = $key; //Build following indicies from the sql.
80 return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
83 function parse_search_field() {
84 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
87 function generate_sql($tablealias, $value) {
88 return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') ";