Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 3665 to 3721

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;
            }
        }
    
    if (
$minaccess == 3) {
        
# Custom permissions are being used so test access to each resource, restricting access as needed
        
$minaccess 0;
    }

    for(
$n 0$n count($result); $n++)
        {
        
$access get_resource_access($result[$n]);
        if(
$access $minaccess)
            {
            
$minaccess $access;
            }
        }

    return 
$minaccess;
    }

This article was last updated 27th April 2024 09:05 Europe/London time based on the source file dated 25th April 2024 16:25 Europe/London time.