$sf_terms_for_code = xapian_get_all_terms(1000, $specific_field['code']); foreach ($sf_terms_for_code as $term) { if (!empty($term)) { $term_array[] = chamilo_get_boolean_query($term['name']); // Here name includes prefix. } } } else { foreach ($values as $term) { if (!empty($term)) { $prefix = $specific_field['code']; $term_array[] = chamilo_get_boolean_query($prefix . $term); } } } } else { $sf_terms_for_code = xapian_get_all_terms(1000, $specific_field['code']); foreach ($sf_terms_for_code as $term) { if (!empty($term)) { $term_array[] = chamilo_get_boolean_query($term['name']); // Here name includes prefix. } } } } // Get right group of terms to show on multiple select. $fixed_queries = array(); $course_filter = NULL; if ( ($cid=api_get_course_id()) != -1 ) { // Results only from actual course. $course_filter = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid); }
/** * Show the search widget * * The form will post to index.php by default, you can pass a value to * $action to use a custom action. * IMPORTANT: you have to call search_widget_prepare() before calling this * function or otherwise the form will not behave correctly. * * @param string $action Just in case your action is not * index.php */ function search_widget_show($action = 'index.php') { require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloQuery.php'; // TODO: load images dinamically when they're avalaible from specific field ui to add $groupId = api_get_group_id(); $sf_terms = array(); $specific_fields = get_specific_field_list(); $url_params = array(); if (($cid = api_get_course_id()) != -1) { // with cid // get search engine terms $course_filter = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid); $dkterms = chamilo_query_simple_query('', 0, 1000, array($course_filter)); //prepare specific fields names (and also get possible URL param names) foreach ($specific_fields as $specific_field) { $temp = array(); if (is_array($dkterms) && count($dkterms) > 0) { foreach ($dkterms[1] as $obj) { $temp = array_merge($obj['sf-' . $specific_field['code']], $temp); } } $sf_terms[$specific_field['code']] = $temp; $url_params[] = 'sf_' . $specific_field['code']; unset($temp); } } else { // without cid // prepare specific fields names (and also get possible URL param names) foreach ($specific_fields as $specific_field) { //get Xapian terms for a specific term prefix, in ISO, apparently $sf_terms[$specific_field['code']] = xapian_get_all_terms(1000, $specific_field['code']); $url_params[] = 'sf_' . $specific_field['code']; } } echo '<h2>' . get_lang('Search') . '</h2>'; // Tool introduction // TODO: Settings for the online editor to be checked (insert an image for example). Probably this is a special case here. if (api_get_course_id() !== -1) { if (!empty($groupId)) { Display::display_introduction_section(TOOL_SEARCH . $groupId); } else { Display::display_introduction_section(TOOL_SEARCH); } } $op = 'or'; if (!empty($_REQUEST['operator']) && in_array($op, array('or', 'and'))) { $op = $_REQUEST['operator']; } //check if URL params are defined (to see if we show the thesaurus or not) $show_thesaurus = false; foreach ($url_params as $param) { if (isset($_REQUEST[$param]) && is_array($_REQUEST[$param])) { $thesaurus_decided = FALSE; foreach ($_REQUEST[$param] as $term) { if (!empty($term)) { $show_thesaurus = true; $thesaurus_decided = TRUE; break; } } if ($thesaurus_decided) { break; } } } // create the form // TODO: use FormValidator display_search_form($action, $show_thesaurus, $sf_terms, $op); }
// term filter if ($term != '__all__') { $filter[] = chamilo_get_boolean_query($prefix . $term); // always and between term and courseid $filter = chamilo_join_queries($filter, null, 'and'); } $sf_terms = get_usual_sf_terms($filter, $specific_fields); } else { // without cid if ($term != '__all__') { $filter[] = chamilo_get_boolean_query($prefix . $term); $sf_terms = get_usual_sf_terms($filter, $specific_fields); } else { // no cid and all/any terms foreach ($specific_fields as $specific_field) { foreach (xapian_get_all_terms(1000, $specific_field['code']) as $raw_term) { if (count($raw_term['name']) > 1) { $normal_term = substr($raw_term['name'], 1); $sf_terms[$specific_field['code']][$normal_term] = $normal_term; } } } } } // build array to return foreach ($sf_terms as $sf_prefix => $term_group) { //if (count($tem_group) > 0) { $first_term = array('__all__' => $operator == 'or' ? '-- Any --' : '-- All -- '); //} if ($sf_prefix != $prefix) { $terms_list[] = array('prefix' => $sf_prefix, 'terms' => array_merge($first_term, $term_group));