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

display_related_resources()

Description

Render all related resources on view page

Parameters

ColumnTypeDefaultDescription
$context array Array with all required info from the view page

Return

void *

Location

include/render_functions.php lines 6102 to 6331

Definition

 
function display_related_resources($context)
    {
    
$ref                        =  $context["ref"] ?? 0;
    
$k                          =  $context["k"] ?? "";
    
$userref                    =  $context["userref"] ?? 0;
    
$arr_related                =  $context["relatedresources"] ?? [];
    
$internal_share_access      =  $context["internal_share_access"] ?? false;
    
$related_restypes           =  $context["related_restypes"] ?? [];
    
$relatedtypes_shown         =  $context["relatedtypes_shown"] ?? [];
    
$edit_access                =  $context["edit_access"] ?? false;
    
$urlparams                  =  $context["urlparams"] ?? ["ref"=>$ref];    

    global 
$baseurl$baseurl_short$lang$view_title_field$sort_relations_by_filetype$related_resources_title_trim$sort_relations_by_restype$metadata_template_title_field$metadata_template_resource_type;

    
$allrestypes get_resource_types();
    if(
$ref==|| count(array_diff(array_column($allrestypes,"ref"),$relatedtypes_shown)) == 0
        {
        return;
        }
    
?>
    <!--Display panel for related resources-->
    <div class="RecordBox">
    <div class="RecordPanel">
    <div id="RelatedResources">
    <div class="RecordResource">
    <div class="Title"> echo escape($lang["relatedresources"]) ?></div>
    
    
if(checkperm("s")
        && (
$k == "" || $internal_share_access)
        )
        {
        if(
count(array_diff(array_column($arr_related,"resource_type"),$relatedtypes_shown)) > 0)
            {
            
?><a href=" echo $baseurl ?>/pages/search.php?search= echo urlencode("!related" $ref?>" onClick="return CentralSpaceLoad(this,true);" > echo LINK_CARET ?> echo escape($lang["clicktoviewasresultset"]) ?></a>
            <div class="clearerleft"> </div>
            
            
}
        if(
$sort_relations_by_filetype)
            {
            
// Sort by file extension
            
$related_file_extensions array_unique(array_column($arr_related"file_extension"));
            foreach(
$related_file_extensions as $rext)
                {
                
?>
                <h4> echo escape((string) $rext); ?></h4>
                
                
# loop and display the results by file extension
                
for ($n=0;$n<count($arr_related);$n++)          
                    {
                    if(
in_array($arr_related[$n]["resource_type"],$relatedtypes_shown))
                        {
                        
// Don't show this type again.
                        
continue;
                        }
                    if (
$arr_related[$n]["file_extension"]==$rext)
                        {
                        
$rref=$arr_related[$n]["ref"];
                        
$title=$arr_related[$n]["field".$view_title_field];
                        
$access=get_resource_access($rref);
                        
$use_watermark=check_use_watermark();
                        
# swap title fields if necessary
                        
if (
                            isset(
$metadata_template_title_field
                            && isset(
$metadata_template_resource_type)
                            && 
$arr_related[$n]['resource_type'] == $metadata_template_resource_type
                            
) {
                                
$title=$arr_related[$n]["field".$metadata_template_title_field];
                            }
                        
?>
                        <div class="CollectionPanelShell">
                            <table border="0" class="CollectionResourceAlign">
                                <tr><td>
                                        <a href=" echo $baseurl ?>/pages/view.php?ref= echo (int) $rref?>&search= echo urlencode("!related" $ref)?>" onClick="return CentralSpaceLoad(this,true);">
                                        $thumbnail 
get_resource_preview($arr_related[$n],["col"],$access,$use_watermark);
                                        if(
$thumbnail !== false)
                                            {
                                            
render_resource_image($arr_related[$n], $thumbnail["url"], "collection");
                                            }
                                        else
                                            { 
                                            echo 
get_nopreview_html((string) $arr_related[$n]["file_extension"]);
                                            } 
?>
                                        </a>
                                </td></tr>
                            </table>
                        <div class="CollectionPanelInfo"><a href=" echo $baseurl ?>/pages/view.php?ref= echo $rref?>" onClick="return CentralSpaceLoad(this,true);"> echo escape(tidy_trim(i18n_get_translated($title),$related_resources_title_trim)) ?></a>&nbsp;</div>
                         hook("relatedresourceaddlink");?>
                        </div>
                        
                        
}
                    }
                    
?>
                <div class="clearerleft"> </div>
                
                
#end of display loop by resource extension
            
#end of IF sorted relations by extension
        
elseif($sort_relations_by_restype)
            {
            foreach(
$related_restypes as $rtype)
                {
                if(
in_array($rtype,$relatedtypes_shown))
                    {
                    
// Don't show this type again.
                    
continue;
                    }
                
$restypename=ps_value("SELECT name AS value FROM resource_type WHERE ref = ?",array("i",$rtype), """schema");
                
$restypename lang_or_i18n_get_translated($restypename"resourcetype-""-2");
                
?>
                <h4> echo escape($restypename); ?></h4>
                
                
# loop and display the results by file extension
                
for ($n=0;$n<count($arr_related);$n++)          
                    {
                    if (
$arr_related[$n]["resource_type"]==$rtype)
                        {
                        
$rref=$arr_related[$n]["ref"];
                        
$title=$arr_related[$n]["field".$view_title_field];
                        
$access=get_resource_access($rref);
                        
$use_watermark=check_use_watermark();
                        
# swap title fields if necessary
                        
if (
                            isset(
$metadata_template_title_field
                            && isset(
$metadata_template_resource_type)
                            && 
$arr_related[$n]['resource_type'] == $metadata_template_resource_type
                            
) {
                                
$title=$arr_related[$n]["field".$metadata_template_title_field];
                            }
                        
?>
                        <!--Resource Panel-->
                        <div class="CollectionPanelShell">
                            <table border="0" class="CollectionResourceAlign">
                                <tr><td>
                                <a href=" echo $baseurl ?>/pages/view.php?ref= echo (int) $rref?>&search= echo urlencode("!related" $ref)?>" onClick="return CentralSpaceLoad(this,true);">
                                $thumbnail 
get_resource_preview($arr_related[$n],["col"],$access,$use_watermark);
                                if(
$thumbnail !== false)
                                    {
                                    
render_resource_image($arr_related[$n], $thumbnail["url"], "collection");
                                    }
                                else
                                    { 
                                    echo 
get_nopreview_html((string) $arr_related[$n]["file_extension"]);
                                    } 
?>
                                    </a>
                                </td></tr>
                            </table>
                        <div class="CollectionPanelInfo"><a href=" echo $baseurl ?>/pages/view.php?ref= echo $rref?>" onClick="return CentralSpaceLoad(this,true);"> echo escape(tidy_trim(i18n_get_translated($title),$related_resources_title_trim)) ?></a>&nbsp;</div>
                         hook("relatedresourceaddlink");?>
                        </div>
                        
                        
}
                    }
                
?>
                <div class="clearerleft"> </div>
                 
                
#end of display loop by resource extension
            
#end of IF sorted relations
        
else
            {
            
// Related resources (default view)
            
for ($n=0;$n<count($arr_related);$n++)            
                {
                if(
in_array($arr_related[$n]["resource_type"],$relatedtypes_shown))
                    {
                    
// Don't show this type again.
                    
continue;
                    }
                
$rref=$arr_related[$n]["ref"];
                
$title=$arr_related[$n]["field".$view_title_field];
                
$access=get_resource_access($rref);
                
$use_watermark=check_use_watermark();
                
# swap title fields if necessary

                
if (
                    isset(
$metadata_template_title_field
                    && isset(
$metadata_template_resource_type)
                    && 
$arr_related[$n]["resource_type"] == $metadata_template_resource_type
                    
) {
                        
$title=$arr_related[$n]["field".$metadata_template_title_field];
                    }        
                
?>
                <div class="CollectionPanelShell">
                    <table border="0" class="CollectionResourceAlign">
                        <tr>
                            <td>
                                <a href=" echo $baseurl ?>/pages/view.php?ref= echo (int) $rref?>&search= echo urlencode("!related" $ref)?>" onClick="return CentralSpaceLoad(this,true);">
                                $thumbnail 
get_resource_preview($arr_related[$n],["col"],$access,$use_watermark);
                                if(
$thumbnail !== false)
                                    {
                                    
render_resource_image($arr_related[$n], $thumbnail["url"], "collection");
                                    }
                                else
                                    {
                                    echo 
get_nopreview_html((string) $arr_related[$n]["file_extension"]);
                                    }
                                
?></a>
                            </td>
                        </tr>
                        </table>
                        <div class="CollectionPanelInfo"><a href=" echo $baseurl ?>/pages/view.php?ref= echo escape($rref?>" onClick="return CentralSpaceLoad(this,true);"> echo escape(tidy_trim(i18n_get_translated($title),$related_resources_title_trim)) ?></a>&nbsp;</div>
                         hook("relatedresourceaddlink");?>       
                    </div>
                    
                    
}?>
                
                
// End related resources default display
            
// End of if any related resources exist
        
?>
        </div><!-- End of RecordResource -->
         if ($edit_access)
            {
            
// Add link to create new related resource and view as result set
            
$add_related_params = [
                
"ref"=>-$userref,
                
"relateto"=>$ref,
                
"noupload"=>"true",
                
"recordonly"=>"true",
                
"collection_add"=>"false",
                
"redirecturl"=>generateURL($baseurl "/pages/view.php",$urlparams),
                ];
            
$addrelated_url generateURL($baseurl_short "pages/edit.php",$add_related_params);       
            
?>
            <div class="clearerleft"></div>
            <a href=" echo $addrelated_url?>" onclick="return CentralSpaceLoad(this, true);"> echo LINK_PLUS  escape($lang['related_resource_create']); ?></a>
            
            
}?>
        </div><!-- End of RelatedResources -->
    </div><!-- End of RecordPanel -->
    </div><!-- End of RecordBox -->

    
}

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.