_default_sort = $defaults['sort']; $this->_default_order = $defaults['order']; // Allowed sort/order array $this->_allowedSorts = $allowedSorts; $this->_allowedOrders = $allowedOrders; // $_GET keys for sort and order $this->_GET_sort = $GET_sortKeys['sort']; $this->_GET_order = $GET_sortKeys['order']; } /** * Get active or default sort value. * * @return string */ public function getSort() { $sort = null; // Get current sort value from $_GET if (isset($_GET[$this->_GET_sort])) { $sort = $_GET[$this->_GET_sort]; } // If sort is not allowed, reset to default if (!in_array($sort, $this->_allowedSorts)) { $sort = $this->_default_sort; } // All good, return sort return $sort; } /** * Get active or default order value. * * @return string */ public function getOrder() { $order = null; // Get current order value from $_GET if (isset($_GET[$this->_GET_order])) { $order = $_GET[$this->_GET_order]; } // If order is not allowed, reset to default if (!in_array($order, $this->_allowedOrders)) { $order = $this->_default_order; } // All good, return order return $order; } /** * Are we using default sort/order? * * @param string $sort Sort value * @param string $order Order value * @return boolean */ public function isDefault($sort, $order) { return ($this->_default_sort == $sort && $this->_default_order == $order); } }