Controlling Results Ordering

Table of Contents

Adding Ordering Capabilities to Your Container Rule
Determining the Current Order Direction

Related to splitting results into a series of pages, you may also want to give users the option to determine the order of results. Recite CMS makes this easy to implement for developers.

By enabling this functionality, you can let the web site creator determine the order of data, and you can let them decide if end-users can override this using a URL paramter.

Adding Ordering Capabilities to Your Container Rule

There are three methods you must define to enable the results ordering functionality. Firstly, usesOrdering() must return true to enable the ordering options. Next, you must return the available orders from getSortOrders(). Finally, you must define the default sort order using getDefaultSortOrder().

Additionally, you can let the web site builder choose if end-users can override the order direction via a URL parameter. To do so, return true from orderCanBeSetInUrl().

The following code demonstrates each of these methods. Note that the getSortOrders() method returns array of key/value pairs. The key is the value you use internally in getDefaultSortOrder and run() (and the value users specify if overriding via the URL), while the value is what is displayed in the container rule options.

Example 6.1. Enabling ordering of results

<?php
    class Driver_containers_rule_weather_controller extends Module_Containers_Driver_Abstract
    {
        // ...
        
        public function usesOrdering()
        {
            return true;
        }

        public function getSortOrders()
        {
            return array(
                'title'  => 'Title (A-Z)',
                'titled' => 'Title (Z-A)'
            );
        }

        public function getDefaultSortOrder()
        {
            return 'titled';
        }

        public function orderCanBeSetInUrl()
        {
            return true;
        }
        
        // ...
    }
?>