Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 sql_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 3650 to 3718

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');
    if(!
$extrafields)
        {
        
$extrafields '';
        }
    
    
// Create filter SQL
    
$filterarr = array();
    if(
is_int_loose($resource))
        {
        
$filterarr[] = "r.resource='" $resource "'";
        }
    foreach(
$filters as $column => $filter_value)
        {
        
$filterarr[] = escape_check(trim($column)) . "='" escape_check($filter_value) . "'";
        }  
    
$sql_filter "WHERE " implode(" AND "$filterarr);

    
$log sql_query(
                
"SELECT r.ref,
                        r.resource,
                        r.date,
                        u.username,
                        u.fullname,
                        r.type,
                        rtf.type AS resource_type_field,
                        f.title,
                        r.notes,
                        r.diff,
                        r.usageoption,
                        r.purchase_price,
                        r.purchase_size,
                        ps.name AS size,
                        r.access_key,
                        ekeys_u.fullname AS shared_by 
{$extrafields}
                   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"
,
        
false,
        
$fetchrows);

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

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

    return 
$log;
    }

This article was last updated 12th May 2021 06:35 Europe/London time based on the source file dated 11th May 2021 10:25 Europe/London time.