Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 2764 to 2807

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'');
        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
        
$minextaccess sql_value("SELECT max(access) value FROM external_access_keys WHERE resource IN ('" implode("','",array_column($result,"ref")) . "') AND access_key = '" escape_check($k) . "' AND (expires IS NULL OR expires > NOW())", -1);
        if(
$minextaccess != -&& (!$internal_share_access || ($internal_share_access && ($minextaccess $minaccess))))
            {
            return (
$minextaccess);
            }
        }

    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 28th November 2020 22:35 Europe/London time based on the source file dated 25th November 2020 10:35 Europe/London time.