From: skodak Date: Wed, 16 Apr 2008 13:20:46 +0000 (+0000) Subject: MDL-14018 advanced search for multiselect menu improved; merged from MOODLE_19_STABLE X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0d505aced89268a99ddd85c4971fe0c53befc5f8;p=moodle.git MDL-14018 advanced search for multiselect menu improved; merged from MOODLE_19_STABLE --- diff --git a/lang/en_utf8/data.php b/lang/en_utf8/data.php index 015c9ee505..82db936008 100644 --- a/lang/en_utf8/data.php +++ b/lang/en_utf8/data.php @@ -217,6 +217,7 @@ $string['savesettings'] = 'Save settings'; $string['savesuccess'] = 'Saved successfully. Your preset will now be available across the site.'; $string['savetemplate'] = 'Save template'; $string['search'] = 'Search'; +$string['selectedrequired'] = 'All selected required'; $string['sendinratings'] = 'Send in my latest ratings'; $string['single'] = 'View single'; $string['singletemplate'] = 'Single template'; diff --git a/mod/data/field/multimenu/field.class.php b/mod/data/field/multimenu/field.class.php index ec37adb8e5..82760cfcae 100755 --- a/mod/data/field/multimenu/field.class.php +++ b/mod/data/field/multimenu/field.class.php @@ -63,23 +63,68 @@ class data_field_multimenu extends data_field_base { function display_search_field($value = '') { global $CFG; - $temp = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content'); - $options = array(); - if(!empty($temp)) { - $options[''] = ''; //Make first index blank. - foreach ($temp as $key) { - $options[$key] = $key; //Build following indicies from the sql. + + if (is_array($value)){ + $content = $value['selected']; + $allrequired = $value['allrequired'] ? 'checked = "checked"' : ''; + } else { + $content = array(); + $allrequired = ''; + } + + static $c = 0; + + $str = ''; + + $str .= ' '; + $str .= ''; + $c++; + + return $str; + } function parse_search_field() { - return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); + $selected = optional_param('f_'.$this->field->id, array(), PARAM_NOTAGS); + $allrequired = optional_param('f_'.$this->field->id.'_allreq', 0, PARAM_BOOL); + if (empty($selected)) { + // no searching + return ''; + } + return array('selected'=>$selected, 'allrequired'=>$allrequired); } function generate_sql($tablealias, $value) { - return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$value') "; + $allrequired = $value['allrequired']; + $selected = $value['selected']; + + if ($selected) { + $conditions = array(); + foreach ($selected as $sel) { + $conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND ({$tablealias}.content LIKE '$sel##%' OR {$tablealias}.content LIKE '%##$sel' OR {$tablealias}.content LIKE '%##$sel##%'))"; + } + if ($allrequired) { + return " (".implode(" AND ", $conditions).") "; + } else { + return " (".implode(" OR ", $conditions).") "; + } + } else { + return " "; + } } function update_content($recordid, $value, $name='') {