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_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 4202 to 4268

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.previous_value,
                        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 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 17th November 2024 15:35 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.