Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 921 to 1013

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'''));
    
$sort = (in_array(mb_strtoupper($sort), array("ASC""DESC")) ? 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"
            '
,
            
$baseurl_short,
            
urlencode($search),
            
$name,
            
urlencode($archive),
            
urlencode($k),
            
urlencode($restypes)
        );

        
$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 19th March 2024 08:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.