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 display_add_field($recordid=0) {
33 $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
34 $content = trim($content);
39 $str = '<div title="'.s($this->field->description).'">';
41 $rawoptions = explode("\n",$this->field->param1);
42 foreach ($rawoptions as $option) {
43 $option = trim($option);
45 $options[$option] = $option;
50 $str .= html_writer::select($options, 'field_'.$this->field->id, $content, array(''=>get_string('menuchoose', 'data')), array('id'=>'field_'.$this->field->id));
57 function display_search_field($content = '') {
58 global $CFG, $DB, $OUTPUT;
60 $usedoptions = array();
61 $sql = "SELECT DISTINCT content
63 WHERE fieldid=: AND content IS NOT NULL";
64 if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
65 foreach ($used as $data) {
66 $value = $data->content;
70 $usedoptions[$value] = $value;
75 foreach (explode("\n",$this->field->param1) as $option) {
76 $option = trim($option);
77 if (!isset($usedoptions[$option])) {
80 $options[$option] = $option;
83 // oh, nothing to search for
87 return html_writer::select($options, 'f_'.$this->field->id, $content, array(''=>' '));
90 function parse_search_field() {
91 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
94 function generate_sql($tablealias, $value) {
98 return array(" ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = :$name) ", array($name=>$value));