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 3357 to 3377

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

This article was last updated 5th February 2023 06:35 Europe/London time based on the source file dated 1st February 2023 15:00 Europe/London time.