PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/application/classes/Admin/Sort.php

https://bitbucket.org/chrispiechowicz/zepto
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
  1. <?php
  2. /**
  3. * Sort helper
  4. *
  5. * @package zeptocms
  6. * @version 2012/12/14
  7. * @author Chris Piechowicz <info@zeptocms.com>
  8. */
  9. class Admin_Sort
  10. {
  11. /**
  12. * Get current sorting options
  13. *
  14. * @param array $possible possible sort options
  15. * @param array $default default options
  16. * @return array
  17. */
  18. public static function get($possible, Array $default)
  19. {
  20. $sort = Input::get("sort") && in_array(Input::get("sort"), $possible) ? Input::get("sort") : $default["sort"];
  21. $dir = Input::get("dir") && in_array(Input::get("dir"), array("asc", "desc")) ? Input::get("dir") : $default["dir"];
  22. return array($sort, $dir);
  23. }
  24. /**
  25. * Generate sort link
  26. *
  27. * @param string $key column's name
  28. * @param string $url url for links
  29. * @param string $title title of link
  30. * @param array $default default sorting
  31. * @return string
  32. */
  33. public static function link($key, $url, $title, $default)
  34. {
  35. if (!$url) $url = PATH;
  36. $result = "";
  37. $sort = Input::get("sort") ? Input::get("sort") : $default["sort"];
  38. $dir = Input::get("dir") ? Input::get("dir") : $default["dir"];
  39. $query = Url::query() != "" ? Url::query()."&" : "?";
  40. $title_asc = HTML::image("res/img/lib/sort/asc.png", array("class" => "sort", "alt" => __("")));
  41. $title_desc = HTML::image("res/img/lib/sort/desc.png", array("class" => "sort", "alt" => __("")));
  42. if ($sort == $key)
  43. {
  44. if ($dir == "asc")
  45. $result = HTML::anchor($url.$query."sort=".$key."&dir=desc", $title_desc);
  46. else
  47. $result = HTML::anchor($url.$query."?sort=".$key."&dir=asc", $title_asc);
  48. }
  49. else
  50. {
  51. $result =
  52. HTML::anchor($url.$query."sort=".$key."&dir=asc", $title_asc)
  53. ." ".HTML::anchor($url.$query."sort=".$key."&dir=desc", $title_desc);
  54. }
  55. return $title." ".$result;
  56. }
  57. }
  58. ?>