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

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 2549 to 2603

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''falsefalsetruefalse);
        }
        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''falsefalsetruetrue);
        if (
is_array($editresults)) {
            
$editcount count($editresults);
            
$editable_resource_refs array_column($editresults"ref");
        }

        if (
$resultcount == $editcount) {
            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 15th February 2025 20:35 Europe/London time based on the source file dated 13th February 2025 10:30 Europe/London time.