Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/data/field/radiobutton/field.class.php
Go to the documentation of this file.
00001 <?php
00003 //                                                                       //
00004 // NOTICE OF COPYRIGHT                                                   //
00005 //                                                                       //
00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00007 //          http://moodle.org                                            //
00008 //                                                                       //
00009 // Copyright (C) 1999-onwards Moodle Pty Ltd  http://moodle.com          //
00010 //                                                                       //
00011 // This program is free software; you can redistribute it and/or modify  //
00012 // it under the terms of the GNU General Public License as published by  //
00013 // the Free Software Foundation; either version 2 of the License, or     //
00014 // (at your option) any later version.                                   //
00015 //                                                                       //
00016 // This program is distributed in the hope that it will be useful,       //
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00019 // GNU General Public License for more details:                          //
00020 //                                                                       //
00021 //          http://www.gnu.org/copyleft/gpl.html                         //
00022 //                                                                       //
00024 
00025 class data_field_radiobutton extends data_field_base {
00026 
00027     var $type = 'radiobutton';
00028 
00029     function display_add_field($recordid=0) {
00030         global $CFG, $DB;
00031 
00032         if ($recordid){
00033             $content = trim($DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)));
00034         } else {
00035             $content = '';
00036         }
00037 
00038         $str = '<div title="'.s($this->field->description).'">';
00039         $str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
00040 
00041         $i = 0;
00042         foreach (explode("\n",$this->field->param1) as $radio) {
00043             $radio = trim($radio);
00044             if ($radio === '') {
00045                 continue; // skip empty lines
00046             }
00047             $str .= '<input type="radio" id="field_'.$this->field->id.'_'.$i.'" name="field_' . $this->field->id . '" ';
00048             $str .= 'value="' . s($radio) . '" ';
00049 
00050             if ($content == $radio) {
00051                 // Selected by user.
00052                 $str .= 'checked />';
00053             } else {
00054                 $str .= '/>';
00055             }
00056 
00057             $str .= '<label for="field_'.$this->field->id.'_'.$i.'">'.$radio.'</label><br />';
00058             $i++;
00059         }
00060         $str .= '</fieldset>';
00061         $str .= '</div>';
00062         return $str;
00063     }
00064 
00065      function display_search_field($value = '') {
00066         global $CFG, $DB;
00067 
00068         $varcharcontent = $DB->sql_compare_text('content', 255);
00069         $used = $DB->get_records_sql(
00070             "SELECT DISTINCT $varcharcontent AS content
00071                FROM {data_content}
00072               WHERE fieldid=?
00073              ORDER BY $varcharcontent", array($this->field->id));
00074 
00075         $options = array();
00076         if(!empty($used)) {
00077             foreach ($used as $rec) {
00078                 $options[$rec->content] = $rec->content;  //Build following indicies from the sql.
00079             }
00080         }
00081         return html_writer::select($options, 'f_'.$this->field->id, $value);
00082     }
00083 
00084     function parse_search_field() {
00085         return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
00086     }
00087 
00088     function generate_sql($tablealias, $value) {
00089         global $DB;
00090 
00091         static $i=0;
00092         $i++;
00093         $name = "df_radiobutton_$i";
00094         $varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255);
00095 
00096         return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
00097     }
00098 
00099 }
00100 
 All Data Structures Namespaces Files Functions Variables Enumerations