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 3752

Definition

 
function collection_min_access($collection)
    {
    global 
$k$internal_share_access;
    if(
is_array($collection))
        {
        
$result $collection;
        }
    else
        {
        
$result do_search("!collection{$collection}"'''relevance'0, -1'desc'false''false'','',false,false);
        if (!
is_array($result))
            {
            
$result = array();
            }
        }
    if(
count($result) > && isset($result[0]["access"]) && !checkperm("v"))
        {
        
$minaccess max(array_column($result,"access"));
        }
    else
        {
        
$minaccess 0;
        }
    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;

        if (
count($result) == 0)
            {   
            return 
false
            }

        
$minextaccess ps_value("SELECT max(access) value FROM external_access_keys WHERE resource IN (" ps_param_insert(count($result)) . ") AND access_key = ? AND (expires IS NULL OR expires > NOW())"$params, -1);
        if(
$minextaccess != -&& (!$internal_share_access || ($internal_share_access && ($minextaccess $minaccess))))
            {
            return 
$minextaccess;
            }
        }

    
# Reset minaccess and allow get_resource_access to determine the min access for the collection 
    
$minaccess 0;

    global 
$usersearchfilter;
    
$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]);
        if(
$access $minaccess)
            {
            
$minaccess $access;
            }
        }
    
$usersearchfilter $usersearchfilter_original;

    return 
$minaccess;
    }

This article was last updated 5th December 2024 07:05 Europe/London time based on the source file dated 4th December 2024 16:35 Europe/London time.