Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

get_advanced_search_fields()

Description

Retrieves a list of fields suitable for advanced searching.

This function queries the database for resource type fields that are marked for advanced searching.
It checks for visibility based on user permissions and whether the fields are hidden from the search.
If a designated date field is specified and not already included in the results, it will be added
to the beginning of the list if it matches the resource types of the other fields.

Parameters

ColumnTypeDefaultDescription
$archive bool false Whether to include fields related to archived resources. Defaults to false.
$hiddenfields string "" A comma-separated string of field references that should be hidden from the search.

Return

array An array of searchable fields that can be used in an advanced search form.

Location

include/search_functions.php lines 69 to 129

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 4th December 2024 09:05 Europe/London time based on the source file dated 27th November 2024 09:40 Europe/London time.