Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 2541 to 2561

Definition

 
function copy_collection($copied,$current,$remove_existing=false)
    {    
    
# Get all data from the collection to copy.
    
$copied_collection=sql_query("select cr.resource, r.resource_type from collection_resource cr join resource r on cr.resource=r.ref where collection='" escape_check($copied) . "'","");
    
    if (
$remove_existing)
        {
        
#delete all existing data in the current collection
        
sql_query("delete from collection_resource where collection='" escape_check($current) . "'");
        
collection_log($current,"R",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 24th November 2020 05:35 Europe/London time based on the source file dated 23rd November 2020 16:00 Europe/London time.