2 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
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. //
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: //
21 // http://www.gnu.org/copyleft/gpl.html //
23 ///////////////////////////////////////////////////////////////////////////
25 class data_field_menu
extends data_field_base
{
29 function data_field_menu($field=0, $data=0) {
30 parent
::data_field_base($field, $data);
33 function display_add_field($recordid=0) {
36 $content = get_field('data_content', 'content', 'fieldid', $this->field
->id
, 'recordid', $recordid);
37 $content = trim($content);
42 $str = '<div title="'.s($this->field
->description
).'">';
44 $rawoptions = explode("\n",$this->field
->param1
);
45 foreach ($rawoptions as $option) {
46 $option = trim($option);
48 $options[$option] = $option;
52 $str .= choose_from_menu($options, 'field_'.$this->field
->id
, $content,
53 get_string('menuchoose', 'data'), '', '', true, false, 0, 'field_'.$this->field
->id
);
60 function display_search_field($value = '') {
62 $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix
.'data_content WHERE fieldid='.$this->field
->id
.' GROUP BY content ORDER BY content');
65 $options[''] = ''; //Make first index blank.
66 foreach ($temp as $key) {
67 $options[$key] = $key; //Build following indicies from the sql.
70 return choose_from_menu($options, 'f_'.$this->field
->id
, $value, 'choose', '', 0, true);
73 function parse_search_field() {
74 return optional_param('f_'.$this->field
->id
, '', PARAM_NOTAGS
);
77 function generate_sql($tablealias, $value) {
78 return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') ";