Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_last_resource_edit_array()

Description

Obtain details of the last resource edited in the given array of resource ids

Parameters

ColumnTypeDefaultDescription
$resources array array Array of resource IDs

Return

array | false Array containing details of last edit (resource ID, timestamp and username of user who performed edit)

Location

include/resource_functions.php lines 6951 to 6986

Definition

 
function get_last_resource_edit_array($resources = array())
    {
    if(
count($resources) == 0)
        {
        return 
false;
        }

    
$plugin_last_resource_edit hook('override_last_resource_edit_array');
    if(
$plugin_last_resource_edit === true)
        {
        return 
false;
        }

    
$chunks array_chunk($resources,SYSTEM_DATABASE_IDS_CHUNK_SIZE);
    foreach(
$chunks as $chunk);
        {
        
$rows  ps_query(
            
"SELECT r.ref, r.modified 
                FROM resource r 
            WHERE r.ref IN (" 
ps_param_insert(count($chunk)) . ") 
            ORDER BY r.modified DESC"
,
            
ps_param_fill($chunk,"i")
        );
        if (!isset(
$lastmodified) || $rows[0]["modified"]>$lastmodified["modified"]){$lastmodified=$rows[0];}
        }
    
$lastuserdetails ps_query("SELECT u.username, u.fullname, rl.date FROM resource_log rl LEFT JOIN user u on u.ref=rl.user WHERE rl.resource = ? AND rl.type='e'",array("i",$lastmodified["ref"]));
    if(
count($lastuserdetails) == 0)
        {
        return 
false;
        }

    
$timestamp max($lastuserdetails[0]["date"],$lastmodified["modified"]);

    
$lastusername = (trim($lastuserdetails[0]["fullname"]) != "") ? $lastuserdetails[0]["fullname"] : $lastuserdetails[0]["username"];
    return array(
"ref" => $lastmodified["ref"],"time" => $timestamp"user" => $lastusername);
    }

This article was last updated 7th February 2023 05:35 Europe/London time based on the source file dated 3rd February 2023 13:55 Europe/London time.