Skip to content

Commit

Permalink
MDL-14417 fixed sql for menu adv search - multimenu already fixed tod…
Browse files Browse the repository at this point in the history
…ay; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Apr 19, 2008
1 parent 029cf84 commit a4e3818
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
34 changes: 27 additions & 7 deletions mod/data/field/menu/field.class.php
Expand Up @@ -57,17 +57,37 @@ function display_add_field($recordid=0) {
return $str;
}

function display_search_field($value = '') {
function display_search_field($content = '') {
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');

$usedoptions = array();
$sql = "SELECT DISTINCT content
FROM {$CFG->prefix}data_content
WHERE fieldid={$this->field->id} AND content IS NOT NULL";
if ($used = get_records_sql($sql)) {
foreach ($used as $data) {
$value = $data->content;
if ($value === '') {
continue;
}
$usedoptions[$value] = $value;
}
}

$options = array();
if(!empty($temp)) {
$options[''] = ''; //Make first index blank.
foreach ($temp as $key) {
$options[$key] = $key; //Build following indicies from the sql.
foreach (explode("\n",$this->field->param1) as $option) {
$option = trim($option);
if (!isset($usedoptions[$option])) {
continue;
}
$options[$option] = $option;
}
if (!$options) {
// oh, nothing to search for
return '';
}
return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);

return choose_from_menu($options, 'f_'.$this->field->id, stripslashes($content), ' ', '', 0, true);
}

function parse_search_field() {
Expand Down
4 changes: 2 additions & 2 deletions mod/data/field/multimenu/field.class.php
Expand Up @@ -81,11 +81,11 @@ function display_search_field($value = '') {
$usedoptions = array();
$sql = "SELECT DISTINCT content
FROM {$CFG->prefix}data_content
WHERE fieldid={$this->field->id}";
WHERE fieldid={$this->field->id} AND content IS NOT NULL";
if ($used = get_records_sql($sql)) {
foreach ($used as $data) {
$valuestr = $data->content;
if (is_null($valuestr) or $valuestr === '') {
if ($valuestr === '') {
continue;
}
$values = explode('##', $valuestr);
Expand Down

0 comments on commit a4e3818

Please sign in to comment.