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

render_featured_collections_category_permissions()

Description

Render featured collections options in the Permission Manager (admin_group_permissions.php page)

This function will generate and render the following permissions that target featured collection categories
# j[numeric ID of new collection] - valid for FC categories at root level. These are normal permissions.
# -j[numeric ID of new collection] - valid for the rest of FC sub-categories. These permissions are reversed, {@see DrawOption()}!

properties: parent and depth

Parameters

ColumnTypeDefaultDescription
$ctx array Context data to allow caller code to start from different tree levels. Supports the following

Return

void

Location

include/render_functions.php lines 5218 to 5278

Definition

 
function render_featured_collections_category_permissions(array $ctx)
    {
    global 
$lang;

    
$permissions = (isset($ctx["permissions"]) && is_array($ctx["permissions"]) ? $ctx["permissions"] : array());
    
$parent = (isset($ctx["parent"]) ? validate_collection_parent(array("parent" => $ctx["parent"])) : 0);
    
$path_depth = (isset($ctx["depth"]) ? $ctx["depth"] : 0);
    
$branch_path = (isset($ctx["branch_path"]) && is_array($ctx["branch_path"]) ? $ctx["branch_path"] : array());

    
$current_depth $path_depth;
    
$current_branch_path $branch_path;
    
$reverse_permission = ($parent 0);

    foreach(
get_featured_collection_categories($parent, array("access_control" => false)) as $fc)
        {
        
$branch_path $current_branch_path;
        
$branch_path[] = array(
            
"ref"    => $fc["ref"],
            
"name"   => $fc["name"],
            
"parent" => validate_collection_parent($fc),
        );

        
$fc_perm_id = (!$reverse_permission "" "-") . "j{$fc["ref"]}";
        
$description sprintf("%s%s '%s'",
            (
$path_depth == "" str_pad(""$path_depth 7"—") . " "),
            (!
$reverse_permission $lang["can_see_theme_category"] : $lang["can_see_theme_sub_category"]),
            
i18n_get_translated($fc["name"])
        );
        
DrawOption($fc_perm_id$description$reverse_permissiontrue);

        
// Root categories (ie that don't have a parent) get rendered as normal permissions. Sub-categories, get rendered
        // as reverse permissions
        
debug(sprintf("render_featured_collections_category_permissions: Check if allowed to render sub-categories for FC category '%s'"$fc['ref']));
        
$render_subcategories array_reduce($branch_path, function($carry$item) use ($permissions)
            {
            
$root_node is_null($item["parent"]);
            
$perm_id = ($root_node "" "-") . "j{$item["ref"]}";
            
$allow_render = ($root_node in_array($perm_id$permissions) : !in_array($perm_id$permissions));
            
debug(sprintf("render_featured_collections_category_permissions: For perm ID '%s': carry = %s; root_node = %s; allow_render = %s"$perm_idjson_encode($carry), json_encode($root_node), json_encode($allow_render)));

            
// FALSE if at least one featured collection category parent is forbidden
            
return !is_bool($carry) ? $allow_render $carry && $allow_render;
            }, 
null);
        
debug("render_featured_collections_category_permissions: render_subcategories = " json_encode($render_subcategories));
        
debug("render_featured_collections_category_permissions: ");

        if(
$render_subcategories)
            {
            
render_featured_collections_category_permissions(
                array(
                    
"permissions" => $permissions,
                    
"parent" => $fc["ref"],
                    
"depth" => ++$path_depth,
                    
"branch_path" => $branch_path,
                ));

            
// Step back to initial depth level
            
$path_depth $current_depth;
            }
        }
    }

This article was last updated 12th December 2024 20:35 Europe/London time based on the source file dated 12th December 2024 19:40 Europe/London time.