Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_advanced_search_fields()

Parameters

ColumnTypeDefaultDescription
$archive false
$hiddenfields ""

Location

include/search_functions.php lines 42 to 102

Definition

 
function get_advanced_search_fields($archive=false$hiddenfields="")
    {
    global 
$FIXED_LIST_FIELD_TYPES$date_field$daterange_search;
    
# Returns a list of fields suitable for advanced searching. 
    
$return=array();

    
$date_field_already_present=false# Date field not present in searchable fields array
    
$date_field_data=null# If set then this is the date field to be added to searchable fields array

    
$hiddenfields=explode(",",$hiddenfields);

    
$fields=ps_query("SELECT " columns_in("resource_type_field","f") . ", GROUP_CONCAT(rtfrt.resource_type) resource_types FROM resource_type_field f LEFT JOIN resource_type_field_resource_type rtfrt ON rtfrt.resource_type_field = f.ref  WHERE f.advanced_search=1 AND f.active=1 AND (f.keywords_index=1 AND length(f.name)>0) AND (f.global=1 OR rtfrt.resource_type IS NOT NULL) GROUP BY f.ref ORDER BY f.global DESC, f.order_by ASC", [], "schema"); // Constants do not need to be parameters in the prepared statement
    # Apply field permissions and check for fields hidden in advanced search
    
for ($n=0;$n<count($fields);$n++)
        {
        if (
metadata_field_view_access($fields[$n]["ref"]) && !in_array($fields[$n]["ref"], $hiddenfields))
            {
            
$return[]=$fields[$n];
            if(
$fields[$n]["ref"]==$date_field)
                {
                
$date_field_already_present=true;
                }
            }
        }
    
# If not already in the list of advanced search metadata fields, insert the field which is the designated searchable date ($date_field)
    
if(!$date_field_already_present 
        
&& $daterange_search 
        
&& metadata_field_view_access($date_field
        && !
in_array($date_field$hiddenfields))
        {
        
$date_field_data get_resource_type_field($date_field);
        if (!
is_array($date_field_data) || is_null($date_field_data['ref']))
            {
            
debug("WARNING: Invalid \$date_field specified in config : " $date_field);
            return 
$return;
            }
        
# Insert searchable date field so that it appears as the first array entry for a given resource type
        
$return1=array();
        for (
$n=0;$n<count($return);$n++)
            {
            if (
                isset(
$date_field_data)
                && 
count(array_intersect(explode(",",(string)$return[$n]["resource_types"]),explode(",",(string)$date_field_data['resource_types']))) > 0
                
) {
                    
$return1[]=$date_field_data;
                    
$date_field_data=null# Only insert it once
                
}
            
$return1[]=$return[$n];
            }
        
# If not yet added because it's resource type differs from everything in the list then add it to the end of the list
        
if (is_array($date_field_data))
            {
            
$return1[]=$date_field_data;
            
$date_field_data=null# Keep things tidy
            
}
        return 
$return1;
        }
 
    
# Designated searchable date_field is already present in the lost of advanced search metadata fields        }
    
return $return;
    }

This article was last updated 29th May 2024 12:05 Europe/London time based on the source file dated 13th May 2024 14:40 Europe/London time.