Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_resource_type_fields()

Description

Gets all metadata fields, optionally for a specified array of resource types

Parameters

ColumnTypeDefaultDescription
$restypes array "" Optional array of resource types to check
$field_order_by string "ref" Order by column
$field_sort string "asc" Sort order
$find string "" Parameter value to search for
$fieldtypes array array List of field types to include
$include_inactive boolean false Should inactive resources be checked, default is false

Return

array

Location

include/resource_functions.php lines 7726 to 7843

Definition

 
function get_resource_type_fields($restypes=""$field_order_by="ref"$field_sort="asc"$find=""$fieldtypes = array(), $include_inactive=false)
    {

    
$fields array_column(ps_query('DESCRIBE resource_type_field'), 'Field');
    
$valid_sorts = ['asc''ascending''desc''descending'];
    if(!
in_array($field_order_by,  $fields)){$field_order_by 'ref';}
    if(!
in_array(strtolower($field_sort), $valid_sorts)){$field_sort 'asc';}

    
$conditionsql=""$params = [];
    if(
is_array($restypes))
        {
        
$conditionsql " WHERE resource_type IN ("ps_param_insert(count($restypes)) .")";
        
$params ps_param_fill($restypes'i');
        }
    if (
$include_inactive==false)
        {
        if(
$conditionsql != "")
            {
            
$conditionsql .= " AND active=1 ";
            }
        else
            {
            
$conditionsql .= " WHERE active=1 ";
            }
        }
    if(
$find!="")
        {
        if(
$conditionsql != "")
            {
            
$conditionsql .= " AND ( ";
            }
        else
            {
            
$conditionsql .= " WHERE ( ";
            }
        
$conditionsql.=" name LIKE ? OR title LIKE ? OR tab_name LIKE ? OR exiftool_field LIKE ? OR help_text LIKE ? OR ref LIKE ? OR tooltip_text LIKE ? OR display_template LIKE ?)";
        
$params array_merge($params, ['s'"%$find%"'s'"%$find%"'s'"%$find%"'s'"%$find%"'s'"%$find%"'s'"%$find%"'s'"%$find%"'s'"%$find%"]);
        }

    
$newfieldtypes array_filter($fieldtypes,function($v){return (string)(int)$v == $v;});

    if(
count($newfieldtypes) > 0)
        {
        if(
$conditionsql != "")
            {
            
$conditionsql .= " AND ( ";
            }
        else
            {
            
$conditionsql .= " WHERE ( ";
            }
        
$conditionsql .= " type IN ("ps_param_insert(count($newfieldtypes)) ."))";
        
$params array_merge($paramsps_param_fill($newfieldtypes'i'));
        }
    
// Allow for sorting, enabled for use by System Setup pages
    //if(!in_array($field_order_by,array("ref","name","tab_name","type","order_by","keywords_index","resource_type","display_field","required"))){$field_order_by="ref";}

    
$allfields ps_query("
        SELECT ref,
               name,
               title,
               type,
               order_by,
               keywords_index,
               partial_index,
               resource_type,
               resource_column,
               display_field,
               use_for_similar,
               iptc_equiv,
               display_template,
               tab,
               required,
               smart_theme_name,
               exiftool_field,
               advanced_search,
               simple_search,
               help_text,
               display_as_dropdown,
               external_user_access,
               autocomplete_macro,
               hide_when_uploading,
               hide_when_restricted,
               value_filter,
               exiftool_filter,
               omit_when_copying,
               tooltip_text,
               regexp_filter,
               sync_field,
               display_condition,
               onchange_macro,
               field_constraint,
               linked_data_field,
               automatic_nodes_ordering,
               fits_field,
               personal_data,
               include_in_csv_export,
               browse_bar,
               active,
               read_only,
               full_width
          FROM resource_type_field" 
$conditionsql " ORDER BY active desc," $field_order_by " " $field_sort$params"schema"); // TO DO - JN to ensure order by params locked to expected as per comment on r20006



    // Sort by translated strings if sorting by title
    
if(strtolower($field_order_by) == "title")
        {
        
$sortflag strtolower($field_sort) == "asc" SORT_ASC SORT_DESC;
        foreach(
$allfields as $field)
            {
            
$translations[] = i18n_get_translated($field["title"]);
            }
        
array_multisort($translations,$sortflag,SORT_STRING,$allfields);
        }

    return 
$allfields;
    }

This article was last updated 30th September 2022 16:05 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.