Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

allow_multi_edit()

Description

Returns true or false, can all resources in this collection be edited by the user?

Parameters

ColumnTypeDefaultDescription
$collection array|int Collection IDs
$collectionid array 0

Return

boolean

Location

include/collections_functions.php lines 2748 to 2812

Definition

 
function allow_multi_edit($collection,$collectionid 0)
    {
    global 
$resource;

    if (
is_array($collection) && $collectionid == 0)
        {
        
// Do this the hard way by checking every resource for edit access
        
for ($n=0;$n<count($collection);$n++)
            {
            
$resource $collection[$n];
            if (!
get_edit_access($collection[$n]["ref"],$collection[$n]["archive"],$collection[$n]))
                {
                return 
false;
                }
            }
        
# All have edit access
        
return true;    
        }
    else
        {
        
// Instead of checking each resource we can do a comparison between a search for all resources in collection and a search for editable resources
        
$resultcount 0;
        
$all_resource_refs=array();
        if(!
is_array($collection))
            {
            
// Need the collection resources so need to run the search
            
$collectionid $collection;
            
# Editable_only=false (so returns resources whether editable or not)
            
$collection do_search("!collection{$collectionid}"''''0, -1''false0falsefalse''falsefalsetrue,false);
            }
        if(
is_array($collection))
            {
            
$resultcount count($collection);
            
$all_resource_refs=array_column($collection,"ref");
            }
        
$editcount 0;
        
$editable_resource_refs=array();
        
# Editable_only=true (so returns editable resources only)
        
$editresults =  do_search("!collection{$collectionid}"''''0, -1''false0falsefalse''falsefalsetrue,true);
        if(
is_array($editresults))
            {
            
$editcount count($editresults);
            
$editable_resource_refs=array_column($editresults,"ref");
            }

        if(
$resultcount == $editcount)
            {
            if(
hook('denyaftermultiedit''', array($collection))) { return false; }
            return 
true;
            }

        
# Counts differ meaning there are non-editable resources
        
$non_editable_resource_refs=array_diff($all_resource_refs,$editable_resource_refs);
        
        
# Is grant edit present for all non-editables?
        
foreach($non_editable_resource_refs as $non_editable_ref
            {
            if ( !
hook('customediteaccess','',array($non_editable_ref)) ) { return false; }
            }
        
        
# All non_editables have grant edit
        
return true;

        }
    }

This article was last updated 19th March 2024 09:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.