Collections functions
General functions
Render functions
Theme permission 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 3295 to 3315

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 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']);
        }
    
    
hook('aftercopycollection','',array($copied,$current));
    }

This article was last updated 5th October 2022 02:35 Europe/London time based on the source file dated 4th October 2022 09:50 Europe/London time.