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

Description

Renders sort order functionality as a dropdown box

Parameters

ColumnTypeDefaultDescription
$order_fields array
$default_sort_order

Location

include/render_functions.php lines 940 to 1034

Definition

 
function render_sort_order(array $order_fields,$default_sort_order)
    {
    global 
$order_by$baseurl_short$lang$search$archive$restypes$k$sort$date_field;

    
// use query strings here as this is used to render elements and sometimes it
    // can depend on other params
    
$modal  = ('true' == getval('modal'''));
    
$access  getval('access''');
    
$sort validate_sort_value($sort) ? mb_strtoupper($sort) : 'DESC';
    
?>
    <select id="sort_order_selection" onChange="UpdateResultOrder();" aria-label=" echo escape($lang["sortorder"]) ?>">
    
    
    $options 
'';
    foreach(
$order_fields as $name => $label)
        {
        
// date shows as 'field'.$date_field rather than 'date' for collection searches so let's fix it
        
if($name=='field'.$date_field)
            {
            
$name='date';
            }
        
        
// Are we constructing the option for the default order (ie. the first entry in the order_fields array)
        
$current_is_default = ($name == $default_sort_order);

        
// Is the currently set order that of the current field
        
$selected = ($order_by == $name || ($name=='date' && $order_by=='field'.$date_field));
        
        
// Build the option:
        
$option '<option value="' $name '"';

        
// Set selection attribute if necessary
        
if(($selected && $current_is_default) || $selected)
            {
            
$option .= ' selected';
            }

        
$option .= sprintf('
                data-url="%spages/search.php?search=%s&amp;order_by=%s&amp;archive=%s&amp;k=%s&amp;restypes=%s&amp;access=%s"
            '
,
            
$baseurl_short,
            
urlencode($search),
            
$name,
            
urlencode($archive),
            
urlencode($k),
            
urlencode($restypes),
            
urlencode($access)
        );

        
$option .= '>';
        
$option .= $label;
        
$option .= '</option>';

        
// Add option to the options list
        
$options .= $option;
        }

        
hook('render_sort_order_add_option''', array($options));
        echo 
$options;
    
?>
    </select>
    &nbsp;
    <a href="#" class="update_result_order_button" onClick="UpdateResultOrder(true);" aria-label=" echo escape($sort === "ASC" $lang['sortorder-asc'] : $lang['sortorder-desc']) ?>">
        <i id="sort_selection_toggle" class="fa fa-sort-amount- echo mb_strtolower($sort); ?>"></i>
    </a>

    <script>
    function UpdateResultOrder(toggle_order)
        {
        var selected_option = jQuery('#sort_order_selection :selected');
        var option_url      = selected_option.data('url');
        var sort_by         = jQuery('#sort_order_selection').find(":selected").val();

        if (toggle_order)
            {
            var selected_sort_option=' echo $sort == 'ASC' 'DESC' 'ASC'?>';
            }
        else
            {
            if(sort_by == 'resourcetype' || sort_by == 'collection')
                {
                // The default sort should be ascending when sorting by resource type
                var selected_sort_option = 'ASC';
                }
            else
                {
                var selected_sort_option = 'DESC';
                }
            }
        option_url += '&sort=' + selected_sort_option;
          echo $modal 'Modal' 'CentralSpace'?>Load(option_url);
        }
    </script>
    
    
}

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 3rd December 2024 11:55 Europe/London time.