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

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"],false,$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 26th June 2022 03:35 Europe/London time based on the source file dated 23rd June 2022 12:32 Europe/London time.