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_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 8116 to 8224

Definition

 
function get_resource_type_fields($restypes=""$field_order_by="ref"$field_sort="asc"$find=""$fieldtypes = array(), $include_inactive=false)
    {
    
debug_function_call(__FUNCTION__func_get_args());
    if (
$field_order_by != "ref")
        {
        
// Default order by is not being used so check order by columns supplied are valid for the table
        
$fields columns_in("resource_type_field",null,null,true);
        
$fields[] = "tab_name";
        
$order_by_cols explode(','$field_order_by);
        
$valid_order_by_cols = array();
        foreach (
$order_by_cols as $col)
            {
            if(
$col == "resource_type")
                {
                
// Now multiple mapping and resource_type no longer used. Need to reverse order and show global fields first
                
$valid_order_by_cols[] = "global " $field_sort ", resource_types";
                }

            elseif (
in_array(trim($col),  $fields))
                {
                
$valid_order_by_cols[] = trim($col);
                }
            }
        if (
count($valid_order_by_cols) == 0)
            {
            
$field_order_by "ref";
            }
        else
            {
            
$field_order_by implode(', '$valid_order_by_cols);
            }
        }

    
$valid_sorts = ['asc''ascending''desc''descending'];
    if(!
in_array(strtolower($field_sort), $valid_sorts)){$field_sort 'asc';}
    
$conditions = [];
    
$restypeconditions = [];
    
$groupcondition "";$groupparams = [];
    
$joins = [];
    
$params = [];
    if(!
is_array($restypes))
        {
        
$restypes array_filter(explode(",",$restypes),"is_int_loose"); 
        }
    
$restypeselect ",t.name AS tab_name, GROUP_CONCAT(rtfrt.resource_type ORDER BY rtfrt.resource_type) resource_types";
    
$joins[] = " LEFT JOIN resource_type_field_resource_type rtfrt ON rtfrt.resource_type_field = rtf.ref";
    
$joins[] = " LEFT JOIN tab t ON t.ref=rtf.tab";
   
    if(
count($restypes) > 0)
        {
        
// Always return global fields
        
$restypeconditions[]  = "global=1";
        foreach(
$restypes as $restype)
            {
            if(
$restype 0)
                {
                
$restypeconditions[] = "FIND_IN_SET(?,resource_types)";
                
$groupparams[] = "i";$groupparams[] = $restype;
                }
            }
        }

    if(
count($restypeconditions) > 0)
        { 
        
$groupcondition " HAVING ((" implode(") OR (",$restypeconditions) . "))";
        }

    if (
$include_inactive===false)
        {
        
$conditions[]  = " (rtf.active=1)";
        }
    if(
$find!="")
        {
        
$conditions[] =" (rtf.name LIKE ? OR rtf.title LIKE ? OR t.name LIKE ? OR rtf.exiftool_field LIKE ? OR rtf.help_text LIKE ? 
            OR rtf.ref LIKE ? OR rtf.tooltip_text LIKE ? OR rtf.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,"is_int_loose");

    if(
count($newfieldtypes) > 0)
        {        
        
$conditions[] = " rtf.type IN("ps_param_insert(count($newfieldtypes)) .")";
        
$params array_merge($paramsps_param_fill($newfieldtypes'i'));
        }
    
    
$conditionstring count($conditions) > ? (" WHERE " implode(" AND ",$conditions) . " ") : "";

    
$params array_merge($params,$groupparams);

    
$allfieldsquery="SELECT " columns_in("resource_type_field""rtf") . $restypeselect "
        FROM resource_type_field rtf " 
implode(" ",$joins)  . $conditionstring 
        GROUP BY rtf.ref " 
$groupcondition "
        ORDER BY rtf.active desc," 
$field_order_by " " $field_sort;

    
$allfields ps_query($allfieldsquery$params"schema");

    
// 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 28th October 2024 16:35 Europe/London time based on the source file dated 25th October 2024 16:30 Europe/London time.