/**
  * This method is invoked from the `Sortable` class and it contains the
  * logic for sorting (or unsorting) the resource index. It provides a basic
  * wrapper to the `ResourceManager`'s `fetch()` method.
  *
  * @see toolkit.ResourceManager#getSortingField
  * @see toolkit.ResourceManager#getSortingOrder
  * @see toolkit.ResourceManager#fetch
  * @param string $sort
  *  The field to sort on which should match one of the table's column names.
  *  If this is not provided the default will be determined by
  *  `ResourceManager::getSortingField`
  * @param string $order
  *  The direction to sort in, either 'asc' or 'desc'. If this is not provided
  *  the value will be determined by `ResourceManager::getSortingOrder`.
  * @param array $params
  *  An associative array of params (usually populated from the URL) that this
  *  function uses. The current implementation will use `type` and `unsort` keys
  * @throws Exception
  * @throws SymphonyErrorPage
  * @return array
  *  An associative of the resource as determined by `ResourceManager::fetch`
  */
 public function sort(&$sort, &$order, array $params)
 {
     $type = $params['type'];
     if (!is_null($sort)) {
         General::sanitize($sort);
     }
     // If `?unsort` is appended to the URL, then sorting information are reverted
     // to their defaults
     if (isset($params['unsort'])) {
         ResourceManager::setSortingField($type, 'name', false);
         ResourceManager::setSortingOrder($type, 'asc');
         redirect(Administration::instance()->getCurrentPageURL());
     }
     // By default, sorting information are retrieved from
     // the filesystem and stored inside the `Configuration` object
     if (is_null($sort) && is_null($order)) {
         $sort = ResourceManager::getSortingField($type);
         $order = ResourceManager::getSortingOrder($type);
         // If the sorting field or order differs from what is saved,
         // update the config file and reload the page
     } elseif ($sort !== ResourceManager::getSortingField($type) || $order !== ResourceManager::getSortingOrder($type)) {
         ResourceManager::setSortingField($type, $sort, false);
         ResourceManager::setSortingOrder($type, $order);
         redirect(Administration::instance()->getCurrentPageURL());
     }
     return ResourceManager::fetch($params['type'], array(), array(), $sort . ' ' . $order);
 }
 /**
  * This method is invoked from the `Sortable` class and it contains the
  * logic for sorting (or unsorting) the resource index. It provides a basic
  * wrapper to the `ResourceManager`'s `fetch()` method.
  *
  * @see toolkit.ResourceManager#getSortingField
  * @see toolkit.ResourceManager#getSortingOrder
  * @see toolkit.ResourceManager#fetch
  * @param string $sort
  *  The field to sort on which should match one of the table's column names.
  *  If this is not provided the default will be determined by
  *  `ResourceManager::getSortingField`
  * @param string $order
  *  The direction to sort in, either 'asc' or 'desc'. If this is not provided
  *  the value will be determined by `ResourceManager::getSortingOrder`.
  * @param array $params
  *  An associative array of params (usually populated from the URL) that this
  *  function uses. The current implementation will use `type` and `unsort` keys
  * @return array
  *  An associative of the resource as determined by `ResourceManager::fetch`
  */
 public function sort(&$sort, &$order, array $params)
 {
     $type = $params['type'];
     // If `?unsort` is appended to the URL, then sorting information are reverted
     // to their defaults
     if ($params['unsort']) {
         ResourceManager::setSortingField($type, 'name', false);
         ResourceManager::setSortingOrder($type, 'asc');
         redirect(Administration::instance()->getCurrentPageURL());
     }
     // By default, sorting information are retrieved from
     // the filesystem and stored inside the `Configuration` object
     if (is_null($sort) && is_null($order)) {
         $sort = ResourceManager::getSortingField($type);
         $order = ResourceManager::getSortingOrder($type);
     } else {
         if ($sort != ResourceManager::getSortingField($type) || $order != ResourceManager::getSortingOrder($type)) {
             ResourceManager::setSortingField($type, $sort, false);
             ResourceManager::setSortingOrder($type, $order);
             redirect(Administration::instance()->getCurrentPageURL());
         }
     }
     return ResourceManager::fetch($params['type'], array(), array(), $sort . ' ' . $order);
 }