diff --git a/lang/en_utf8/data.php b/lang/en_utf8/data.php index 015c9ee505f..82db9360084 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 ec37adb8e54..82760cfcae2 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 = ''; } - return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true); + + 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='') {