1) { $normal_term = substr($raw_term['name'], 1); $sf_terms[$specific_field['code']][$normal_term] = $normal_term; } } } } } return $sf_terms; } $term = $_GET['term']; $prefix = $_GET['prefix']; $operator = $_GET['operator']; $specific_fields = get_specific_field_list(); $sf_terms = []; if (($cid = api_get_course_id()) != -1) { // with cid // course filter $filter[] = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID.$cid); // 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 = ['__all__' => ($operator == 'or' ? '-- Any --' : '-- All -- ')]; //} if ($sf_prefix != $prefix) { $terms_list[] = [ 'prefix' => $sf_prefix, 'terms' => array_merge($first_term, $term_group), ]; } } echo json_encode($terms_list);