Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 3446 to 3464

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 17th November 2024 15:05 Europe/London time based on the source file dated 13th November 2024 15:50 Europe/London time.