Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_resource_log()

Description

Get resource log records. The standard field titles are translated using $lang. Custom field titles are i18n translated.

available columns in the sql statement so they must match!

Parameters

ColumnTypeDefaultDescription
$resource int Resource ID - set to NULL and specify r.ref=>[id] in the $filters array to retrieve a specific log entry by log ref
$fetchrows int -1 If $fetchrows is set we don't have to loop through all the returned rows. @see ps_query()
$filters array array List of filters to include in the where clause. The key of the array is linked to the

Return

array

Location

include/resource_functions.php lines 3774 to 3844

Definition

 
function get_resource_log($resource$fetchrows = -1, array $filters = array())
    {
    
// Logs can sometimes contain confidential information and the user
    // looking at them must have admin permissions set
    
if(!checkperm('v'))
        {
        return array();
        }

    
$extrafields hook('get_resource_log_extra_fields');
    
$extrafields is_a($extrafields,PreparedStatementQuery::class) ? $extrafields : new PreparedStatementQuery();

    
// Create filter SQL
    
$filterarr = array(); $params = [];
    if(
is_int_loose($resource))
        {
        
$filterarr[] = "r.resource= ?";
        
$params array_merge($params, ['i'$resource]);
        }
    foreach(
$filters as $column => $filter_value)
        {
        
$filterarr[] = trim($column) . "= ?";
        
$params array_merge($params, ['s'$filter_value]);
        }
    
$sql_filter "WHERE " implode(" AND "$filterarr);

    
$sql_query = new PreparedStatementQuery(
        
"SELECT r.ref,
                        r.resource,
                        r.date,
                        u.username,
                        u.fullname,
                        r.type,
                        rtf.type AS resource_type_field,
                        rtf.ref AS field,
                        f.title,
                        r.notes,
                        r.diff,
                        r.usageoption,
                        r.purchase_price,
                        r.purchase_size,
                        r.previous_value,
                        ps.name AS size,
                        r.access_key,
                        ekeys_u.fullname AS shared_by 
{$extrafields->sql}
                   FROM resource_log AS r
        LEFT OUTER JOIN user AS u ON u.ref = r.user
        LEFT OUTER JOIN resource_type_field AS f ON f.ref = r.resource_type_field
        LEFT OUTER JOIN external_access_keys AS ekeys ON r.access_key = ekeys.access_key AND r.resource = ekeys.resource
        LEFT OUTER JOIN user AS ekeys_u ON ekeys.user = ekeys_u.ref
              LEFT JOIN preview_size AS ps ON r.purchase_size = ps.id
        LEFT OUTER JOIN resource_type_field AS rtf ON r.resource_type_field = rtf.ref
                        
{$sql_filter}
               GROUP BY r.ref
               ORDER BY r.ref DESC"
,
        
array_merge($extrafields->parameters$params));

    
$log sql_limit_with_total_count($sql_query,$fetchrows,0);

    for(
$n 0$n count($log['data']); $n++)
        {
        if(
$fetchrows != -&& $log['data'][$n] == 0)
            {
            continue;
            }

        
$log['data'][$n]['title'] = lang_or_i18n_get_translated($log['data'][$n]['title'], 'fieldtitle-');
        }

    return 
$log;
    }

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