|
Moodle
2.2.1
http://www.collinsharper.com
|
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_menu extends data_field_base { 00026 00027 var $type = 'menu'; 00028 00029 function display_add_field($recordid=0) { 00030 global $DB, $OUTPUT; 00031 00032 if ($recordid){ 00033 $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); 00034 $content = trim($content); 00035 } else { 00036 $content = ''; 00037 } 00038 00039 $str = '<div title="'.s($this->field->description).'">'; 00040 00041 $rawoptions = explode("\n",$this->field->param1); 00042 foreach ($rawoptions as $option) { 00043 $option = trim($option); 00044 if ($option) { 00045 $options[$option] = $option; 00046 } 00047 } 00048 00049 00050 $str .= html_writer::select($options, 'field_'.$this->field->id, $content, array(''=>get_string('menuchoose', 'data')), array('id'=>'field_'.$this->field->id)); 00051 00052 $str .= '</div>'; 00053 00054 return $str; 00055 } 00056 00057 function display_search_field($content = '') { 00058 global $CFG, $DB; 00059 00060 $varcharcontent = $DB->sql_compare_text('content', 255); 00061 $sql = "SELECT DISTINCT $varcharcontent AS content 00062 FROM {data_content} 00063 WHERE fieldid=? AND content IS NOT NULL"; 00064 00065 $usedoptions = array(); 00066 if ($used = $DB->get_records_sql($sql, array($this->field->id))) { 00067 foreach ($used as $data) { 00068 $value = $data->content; 00069 if ($value === '') { 00070 continue; 00071 } 00072 $usedoptions[$value] = $value; 00073 } 00074 } 00075 00076 $options = array(); 00077 foreach (explode("\n",$this->field->param1) as $option) { 00078 $option = trim($option); 00079 if (!isset($usedoptions[$option])) { 00080 continue; 00081 } 00082 $options[$option] = $option; 00083 } 00084 if (!$options) { 00085 // oh, nothing to search for 00086 return ''; 00087 } 00088 00089 return html_writer::select($options, 'f_'.$this->field->id, $content); 00090 } 00091 00092 function parse_search_field() { 00093 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); 00094 } 00095 00096 function generate_sql($tablealias, $value) { 00097 global $DB; 00098 00099 static $i=0; 00100 $i++; 00101 $name = "df_menu_$i"; 00102 $varcharcontent = $DB->sql_compare_text("{$tablealias}.content", 255); 00103 00104 return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value)); 00105 } 00106 00107 } 00108 00109