Collections functions
General functions
Render functions
Theme permission functions
Resource functions

collection_add_resources()

Description

Add resource(s) $resources to collection $collection

Parameters

ColumnTypeDefaultDescription
$collection mixed
$resources mixed ''
$search ''
$selected false

Return

boolean | string

Location

include/collections_functions.php lines 550 to 590

Definition

 
function collection_add_resources($collection,$resources='',$search='',$selected=false)
    {
    global 
$USER_SELECTION_COLLECTION,$lang;
    if(
            !
is_int_loose($collection)
        ||  (
$resources == '' && $search == '')
        ||  !
collection_writeable($collection)
        ||  
is_featured_collection_category_by_children($collection)
    )
        {
        return 
$lang["cantmodifycollection"];
        }
    
$access_control true;
    
$external_share_keys get_external_shares([
        
'share_collection' => $collection,
        
'share_type' => 0,
        
'ignore_permissions' => true,
    ]);

    if(
$selected){$resources=get_collection_resources($USER_SELECTION_COLLECTION);}
    else if(
$resources ==''){$resources=do_search($search);}

    if(
$resources === false){return $lang["noresourcesfound"];}
    if(!
is_array($resources)){$resources explode(",",$resources);}

    if (
count($resources) == 0){return $lang["noresourcesfound"];}
    
$collection_resources       get_collection_resources($collection);
    
$refs_to_add array_diff($resources$collection_resources);

    
$errors=0;
    foreach(
$refs_to_add as $ref)
        {
        if(!
add_resource_to_collection($ref,$collectionfalse''''$access_control$external_share_keys))
            {
            
$errors++;
            }
        }
    
    if(
$errors ==0){return true;}
    else {return 
$lang["cantaddresourcestocolection"];}
    }

This article was last updated 27th November 2022 11:35 Europe/London time based on the source file dated 25th November 2022 11:40 Europe/London time.