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_collection()

Description

Render a featured collection (as tiles on the collections_featured.php page)

Parameters

ColumnTypeDefaultDescription
$ctx array Context data to allow caller code to decide rendering requirements
$fc array Featured collection data structure

Return

void

Location

include/render_functions.php lines 4935 to 5106

Definition

 
function render_featured_collection(array $ctx, array $fc)
    {
    if(empty(
$fc))
        {
        return;
        }

    global 
$baseurl_short$lang$k$flag_new_themes$flag_new_themes_age$view_title_field;

    
$is_smart_featured_collection = (isset($ctx["smart"]) ? (bool) $ctx["smart"] : false);
    
$full_width = (isset($ctx["full_width"]) && $ctx["full_width"]);
    
$general_url_params = (isset($ctx["general_url_params"]) && is_array($ctx["general_url_params"]) ? $ctx["general_url_params"] : array());
    
$show_resources_count = (isset($ctx["show_resources_count"]) ? (bool) $ctx["show_resources_count"] : false);
    
$reorder = (bool) ($ctx['reorder'] ?? false);


    
$html_container_class = array("FeaturedSimplePanel""HomePanel""DashTile""FeaturedSimpleTile");
    
$html_container_style = array();
    
$html_container_data_items = [];

    
// Make featured collection tile sortable
    
if($reorder && !$is_smart_featured_collection)
        {
        
$html_container_class[] = 'SortableItem';
        
$html_container_data_items['data-fc-ref'] = $fc['ref'];
        }


    
// Set main featured collection URL (e.g for collections it's the !collection[ID], for categories it's for collection_featured.php)
    
$html_fc_a_href generateURL("{$baseurl_short}pages/search.php"$general_url_params, array("search" => "!collection{$fc["ref"]}"));
    
$html_fc_a_href = (isset($ctx["href"]) && trim($ctx["href"]) !== "" $ctx["href"] : $html_fc_a_href);


    
$html_contents_class = array("FeaturedSimpleTileContents");
    
$html_contents_icon = (isset($ctx["icon"]) && trim($ctx["icon"]) != "" $ctx["icon"] : ICON_CUBE);
    
$fc_display_name strip_prefix_chars(i18n_get_collection_name($fc),"*");

    
$html_contents_h2 $html_contents_icon $fc_display_name;
    
$html_contents_h2_style = array();
    if(!
$is_smart_featured_collection && $flag_new_themes && (time() - strtotime((string)$fc["created"])) < (60 60 24 $flag_new_themes_age))
        {
        
$html_contents_h2 .= sprintf(' <div class="NewFlag">%s</div>'escape($lang['newflag']));
        }
    if(
$full_width)
        {
        
$html_container_class[] = "FullWidth";
        
$html_contents_h2_style[] = "max-width: unset;";

        
$action_selection_id "themes_action_selection{$fc["ref"]}_bottom_{$fc["ref"]}";

        if(
$show_resources_count && !$is_smart_featured_collection)
            {
            
$html_contents_h2 .= sprintf(
                
' <span data-tag="resources_count" data-fc-ref="%s">%s</span>',
                
escape($fc['ref']),
                
escape($lang['counting_resources']));
            }
        }


    
$theme_images = (isset($ctx["images"]) ? $ctx["images"] : array());
    
$theme_images array_map(
        function(
$theme_image) use ($view_title_field$lang){
            if (!isset(
$theme_image['ref'])) {return $theme_image;} // Invalid data [t35944]
            
$ref $theme_image['ref'];
            
$resource_data get_resource_data($ref);
            if (
$resource_data===false) {return $theme_image;} // Resource not found
            
$theme_image['alt_text'] = $resource_data['field' $view_title_field] ?? $lang['resource-1'] . ' ' $ref;
            return 
$theme_image;
        }
    , 
$theme_images);
    if(!empty(
$theme_images))
        {
        
$html_container_class[] = "FeaturedSimpleTileImage";

        if(
count($theme_images) == 1)
            {
            
$alt_string $theme_images[0]['alt_text'] ?? "";
            
$theme_image_path $theme_images[0]["path"] ?? "";
            
$html_container_style[] = "background: url({$theme_image_path});";
            
$html_container_style[] = "background-size: cover;";
            
$theme_images = array();
            }
        }


    
$html_container_data '';
    foreach(
$html_container_data_items as $name => $value)
        {
        
$html_container_data .= sprintf(' %s="%s"'$nameescape($value));
        }

    
$tools = (isset($ctx["tools"]) && is_array($ctx["tools"]) && !$full_width $ctx["tools"] : array());
    
$html_actions_style = ['display: none;'];

    
// DEVELOPER NOTE: anything past this point should be set. All logic is handled above
    
?>
    <div id="FeaturedSimpleTile_ echo md5($fc['ref']); ?>
         class=" echo implode(" "$html_container_class); ?>
         alt=" echo escape($alt_string ?? ''?>"
         style=" echo implode(" "$html_container_style); ?> echo $html_container_data?> >
        <a href=" echo $html_fc_a_href?>" onclick="return CentralSpaceLoad(this, true);" id="featured_tile_ echo $fc["ref"]; ?>" class="FeaturedSimpleLink">
            <div id="FeaturedSimpleTileContents_ echo $fc["ref"]; ?>" class=" echo implode(" "$html_contents_class); ?>">
            
            
foreach($theme_images as $i => $theme_image)
                {
                
$gap 200 count($theme_images);
                
$space $i $gap;
                
$style = array(
                    
"left: {$space}px;",
                    
"transform: rotate(" . (20 - ($i 12)) . "deg);"
                
);
                
?>
                <img src=" echo $theme_image['path']; ?>
                     alt=" echo escape($theme_image['alt_text'] ?? ""); ?>
                     class="TileGroupImageBase" 
                     style=" echo implode(" "$style); ?>" >
                
                
}
                
?>
                <h2 style=" echo implode(" "$html_contents_h2_style); ?>"> echo $html_contents_h2?></h2>
            </div>
        </a>
    
    
if(!empty($tools))
        {
        
?>
        <div id="FeaturedSimpleTileActions_ echo md5($fc['ref']); ?>" class="FeaturedSimpleTileActions" style=" echo implode(" "$html_actions_style); ?>">
        
        
foreach($tools as $tool)
            {
            if(empty(
$tool))
                {
                continue;
                }

            
$href = (isset($tool["href"]) && trim($tool["href"]) != "" $tool["href"] : "#");
            
$text $tool["text"]; // if this is missing, code is wrong somewhere else

            
$tool_onclick = (isset($tool["modal_load"]) && $tool["modal_load"] ? 'return ModalLoad(this, true);' 'return CentralSpaceLoad(this, true);');
            if(isset(
$tool["custom_onclick"]) && trim($tool["custom_onclick"]) != "")
                {
                
$tool_onclick $tool["custom_onclick"];
                }
            
?>
            <div class="tool">
                <a href=" echo $href?>" onclick=" echo $tool_onclick?>">
                    <span> echo LINK_CARET?> echo escape($text); ?></span>
                </a>
            </div>
            
            
}
            
?>
        </div><!-- End of FeaturedSimpleTileActions_ echo md5($fc['ref']); ?> -->
        
        
}
    elseif(
$full_width && !$is_smart_featured_collection)
        {
        
?>
        <div class="ListTools">
            <div class="ActionsContainer">
                <select class="fcollectionactions" id=" echo $action_selection_id ?>" data-actions-loaded="0" data-actions-populating="0" data-col-id=" echo $fc["ref"];?>" onchange="action_onchange_ echo $action_selection_id ?>(this.value);">
                    <option> echo escape($lang["actions-select"]); ?></option>
                </select>
            </div>            
        </div><!-- End of ListTools -->
        
        
}
        
?>
    </div><!-- End of FeaturedSimpleTile_ echo $fc["ref"]; ?>-->

    
}

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 13th November 2024 14:05 Europe/London time.