/application/classes/Admin/Sort.php
PHP | 62 lines | 35 code | 3 blank | 24 comment | 8 complexity | 7fde18931056f747c9597ccf4d90d937 MD5 | raw file
Possible License(s): LGPL-2.1, MIT, BSD-3-Clause
- <?php
- /**
- * Sort helper
- *
- * @package zeptocms
- * @version 2012/12/14
- * @author Chris Piechowicz <info@zeptocms.com>
- */
- class Admin_Sort
- {
- /**
- * Get current sorting options
- *
- * @param array $possible possible sort options
- * @param array $default default options
- * @return array
- */
- public static function get($possible, Array $default)
- {
- $sort = Input::get("sort") && in_array(Input::get("sort"), $possible) ? Input::get("sort") : $default["sort"];
- $dir = Input::get("dir") && in_array(Input::get("dir"), array("asc", "desc")) ? Input::get("dir") : $default["dir"];
- return array($sort, $dir);
- }
- /**
- * Generate sort link
- *
- * @param string $key column's name
- * @param string $url url for links
- * @param string $title title of link
- * @param array $default default sorting
- * @return string
- */
- public static function link($key, $url, $title, $default)
- {
- if (!$url) $url = PATH;
- $result = "";
- $sort = Input::get("sort") ? Input::get("sort") : $default["sort"];
- $dir = Input::get("dir") ? Input::get("dir") : $default["dir"];
- $query = Url::query() != "" ? Url::query()."&" : "?";
- $title_asc = HTML::image("res/img/lib/sort/asc.png", array("class" => "sort", "alt" => __("")));
- $title_desc = HTML::image("res/img/lib/sort/desc.png", array("class" => "sort", "alt" => __("")));
-
- if ($sort == $key)
- {
- if ($dir == "asc")
- $result = HTML::anchor($url.$query."sort=".$key."&dir=desc", $title_desc);
- else
- $result = HTML::anchor($url.$query."?sort=".$key."&dir=asc", $title_asc);
- }
- else
- {
- $result =
- HTML::anchor($url.$query."sort=".$key."&dir=asc", $title_asc)
- ." ".HTML::anchor($url.$query."sort=".$key."&dir=desc", $title_desc);
- }
- return $title." ".$result;
- }
- }
- ?>