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

collection_min_access()

Description

Returns the minimum access (the least permissive) that the current user has to the resources in $collection.

Can be passed a collection ID or the results of a collection search, the result will be the most restrictive
access that is found.

Parameters

ColumnTypeDefaultDescription
$collection integer|array Collection ID as an integer or the result of a search as an array

Return

integer 0 - Open, 1 - restricted, 2 - Confidential

Location

include/collections_functions.php lines 3693 to 3740

Definition

 
function collection_min_access($collection)
{
    global 
$k$internal_share_access$usersearchfilter;
    if (
is_array($collection)) {
        
$result $collection;
    } else {
        
$result do_search("!collection{$collection}"'''relevance'0, -1'desc'false''false'','',false,false);
    }

    if (!
is_array($result) || empty($result)) {
        return 
2;
    }

    if (
checkperm("v")) {
        
// Always has open access
        
return 0;
    }

    if (isset(
$result[0]["resultant_access"])) {
        
$minaccess max(array_column($result,"resultant_access"));
    } else  {
        
# Reset minaccess and allow get_resource_access to determine the min access for the collection
        
$minaccess 0;
        
$usersearchfilter_original $usersearchfilter;
        
# Performance improvement - Don't check search filters again in get_resource_access as $result contains only resources allowed by the search filter.
        
$usersearchfilter '';
        for (
$n 0$n count($result); $n++) {
            
$access get_resource_access($result[$n]); // Use the access already calculated if available
            
if ($access $minaccess) {
                
$minaccess $access;
            }
        }
        
$usersearchfilter $usersearchfilter_original;
    }

    if (
$k != "") {
        
# External access - check how this was shared. If internal share access and share is more open than the user's access return that
        
$params ps_param_fill(array_column($result,"ref"),"i");
        
$params[]="s";$params[]=$k;

        
// Don't check each resource as an access key only ever has one level of access
        
$minextaccess ps_value("SELECT access value FROM external_access_keys WHERE access_key = ? AND (expires IS NULL OR expires > NOW()) LIMIT 1"$params, -1);
        if (
$minextaccess != -&& (!$internal_share_access || ($internal_share_access && ($minextaccess $minaccess)))) {
            return 
$minextaccess;
        }
    }
    return 
$minaccess;
}

This article was last updated 14th January 2025 20:35 Europe/London time based on the source file dated 14th January 2025 10:35 Europe/London time.