Collections functions
General functions
Render functions
Theme permission functions
Resource functions

put_resource_data()

Description

Updates $resource with the name/value pairs in $data - this relates to the resource table column, not metadata.

Parameters

ColumnTypeDefaultDescription
$resource int ID of resource
$data array Array of data to be applied to resource

Return

boolean

Location

include/resource_functions.php lines 468 to 495

Definition

 
function put_resource_data($resource,$data)
    {
    global 
$edit_contributed_by;

    
// Check access
    
if (!get_edit_access($resource)) {return false;}

    
// Define safe columns
    
$safe_columns=array("resource_type","creation_date","rating","user_rating","archive","access","mapzoom","modified","geo_lat","geo_long");
    
$safe_column_types=array("i","s","d","i","i","i","d","s","s","s");

    
// Permit the created by column to be changed also
    
if (checkperm("v") && $edit_contributed_by) {$safe_columns[]="created_by";}

    
$sql="";$params=array();
    foreach (
$data as $column=>$value)
        {
        if (!
in_array($column,$safe_columns)) {return false;} // Attempted to update a column outside of the expected set
        
if ($sql!="") {$sql.=",";}
        
$sql.=$column "=?";
        
$params[]=$safe_column_types[array_search($column,$safe_columns)]; // Fetch type to use
        
$params[]=$value;
        }
    if (
$sql=="") {return false;} // Nothing to do.
    
$params[]="i";$params[]=$resource;
    
ps_query("update resource set $sql where ref=?",$params);
    return 
true;
    }

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