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
$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 3573 to 3639

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 '';
        }

    
$sql_filters "";
    foreach(
$filters as $column => $filter_value)
        {
        
$sql_filters .= sprintf(" AND %s = '%s'",
            
escape_check($column),
            
escape_check($filter_value)
        );
        }
    
$sql_filters ltrim($sql_filters);

    
$log sql_query(
                
"SELECT r.ref,
                        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
                  WHERE r.resource = '
{$resource}'
                        
{$sql_filters}
               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 24th November 2020 06:35 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.