Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

copy_collection()

Description

Copy a collection contents

Parameters

ColumnTypeDefaultDescription
$copied integer The collection to copy from
$current integer The collection to copy to
$remove_existing boolean false Should existing items be removed?

Return

void

Location

include/collections_functions.php lines 3415 to 3433

Definition

 
function copy_collection($copied,$current,$remove_existing=false)
    {   
    
# Get all data from the collection to copy.
    
$copied_collection=ps_query("select cr.resource, r.resource_type, cr.sortorder from collection_resource cr join resource r on cr.resource=r.ref where collection=?",array("i",$copied),"");
    
    if (
$remove_existing)
        {
        
#delete all existing data in the current collection
        
ps_query("delete from collection_resource where collection=?",array("i",$current));
        
collection_log($current,LOG_CODE_COLLECTION_REMOVED_ALL_RESOURCES,0);
        }
    
    
#put all the copied collection records in
    
foreach($copied_collection as $col_resource)
        {
        
# Use correct function so external sharing is honoured.
        
add_resource_to_collection($col_resource['resource'],$current,true,"",$col_resource['resource_type'], nullnull''$col_resource['sortorder']);
        }
    }

This article was last updated 19th March 2024 06:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.