PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Adapto/Datagrid/Limit.php

http://github.com/egeniq/adapto
PHP | 90 lines | 39 code | 12 blank | 39 comment | 5 complexity | 94f41f49a630e83c8767b1c5e1f42ac1 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of the Adapto Toolkit.
  4. * Detailed copyright and licensing information can be found
  5. * in the doc/COPYRIGHT and doc/LICENSE files which should be
  6. * included in the distribution.
  7. *
  8. * @package adapto
  9. * @subpackage utils
  10. *
  11. * @copyright (c) 2000-2007 Ibuildings.nl BV
  12. *
  13. * @license http://www.achievo.org/atk/licensing ATK Open Source License
  14. */
  15. /**
  16. * The data grid limit box. Can be used to render a
  17. * limit box for an ATK data grid.
  18. *
  19. * @author petercv
  20. * @package adapto
  21. * @subpackage datagrid
  22. */
  23. class Adapto_Datagrid_Limit extends Adapto_DGComponent
  24. {
  25. /**
  26. * Returns a list of possible limit values.
  27. *
  28. * @return array list of possible limit values
  29. */
  30. protected function getValues()
  31. {
  32. $defaultLimit = $this->getGrid()->getDefaultLimit();
  33. $limit = $this->getGrid()->getLimit();
  34. $values = array(5, 10, 15, 20, 25, 30, 40, 50, 100, $defaultLimit, $limit);
  35. $values = array_diff($values, array(-1));
  36. $values = array_unique($values);
  37. sort($values);
  38. return $values;
  39. }
  40. /**
  41. * Returns the possible options.
  42. *
  43. * @param array $values possible limits
  44. *
  45. * @return array possible options
  46. */
  47. protected function getOptions($values)
  48. {
  49. $options = array();
  50. $limit = $this->getGrid()->getLimit();
  51. foreach ($values as $value) {
  52. $current = $value == $limit;
  53. $options[] = array('title' => $value, 'value' => $value, 'current' => $current);
  54. }
  55. //Add 'show all' option.
  56. if ($this->getOption('showAll', false)) {
  57. $options[] = array('title' => $this->text('all'), 'value' => -1, 'current' => $limit == -1);
  58. }
  59. return $options;
  60. }
  61. /**
  62. * Renders the limit box for the given data grid.
  63. *
  64. * @return string rendered HTML
  65. */
  66. public function render()
  67. {
  68. $values = $this->getValues();
  69. if ($this->getGrid()->getCount() <= $values[0] || $this->getGrid()->isEditing()) {
  70. return '';
  71. }
  72. $options = $this->getOptions($values);
  73. $call = $this->getGrid()->getUpdateCall(array('atkstartat' => 0), array('atklimit' => '$F(this)'));
  74. $result = $this->getUi()->render('dglimit.tpl', array('options' => $options, 'call' => $call));
  75. return $result;
  76. }
  77. }
  78. ?>