PageRenderTime 55ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/source/endeleza/model/list.php

https://github.com/ercanozkaya/endeleza
PHP | 127 lines | 52 code | 20 blank | 55 comment | 5 complexity | 1089354e5fe1e0f6ddca3a7716776e9c MD5 | raw file
  1. <?php
  2. /**
  3. * @package Endeleza
  4. * @subpackage Model
  5. * @copyright Copyright (C) 2009 Ercan Ozkaya. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. /**
  9. * List model that handles most of the basic operations for a grid
  10. *
  11. * @package Endeleza
  12. * @subpackage Model
  13. */
  14. class EModelList extends EModel
  15. {
  16. /**
  17. * An array of items.
  18. *
  19. * @var array
  20. */
  21. protected $_items = null;
  22. /**
  23. * Total row count
  24. *
  25. * @var integer
  26. */
  27. protected $_total = null;
  28. /**
  29. * Pagination object
  30. *
  31. * @var object
  32. */
  33. protected $_pagination = null;
  34. /**
  35. * Method to get a list of items.
  36. *
  37. * @return mixed An array of objects on success, false on failure.
  38. */
  39. public function getItems()
  40. {
  41. if (empty($this->_items)) {
  42. $query = $this->_getListQuery();
  43. $this->_items = $this->_getList($query, (int)$this->getState('list.start'), (int)$this->getState('list.limit'));
  44. if ($this->_db->getErrorNum()) {
  45. $this->setError($this->_db->getErrorMsg());
  46. return false;
  47. }
  48. }
  49. return $this->_items;
  50. }
  51. /**
  52. * Method to get the total number of items.
  53. *
  54. * @return int The number of items.
  55. */
  56. public function getTotal()
  57. {
  58. if (empty($this->_total)) {
  59. $query = $this->_getListQuery(true);
  60. $this->_total = $this->_getListCount($query);
  61. if ($this->_db->getErrorNum()) {
  62. $this->setError($this->_db->getErrorMsg());
  63. return false;
  64. }
  65. }
  66. return $this->_total;
  67. }
  68. /**
  69. * Method to get a pagination object.
  70. *
  71. * @return object A JPagination object.
  72. */
  73. public function getPagination()
  74. {
  75. jimport('joomla.html.pagination');
  76. return new JPagination($this->getTotal(), (int)$this->getState('list.start'), (int)$this->getState('list.limit'));
  77. }
  78. /**
  79. * Method to build an SQL query to load the list data.
  80. *
  81. * @return string An SQL query
  82. */
  83. protected function _getListQuery($count = false)
  84. {
  85. }
  86. /**
  87. * Method to auto-populate the model state.
  88. *
  89. * @return void
  90. */
  91. protected function _populateState()
  92. {
  93. parent::_populateState();
  94. // Initialize variables.
  95. $app = JFactory::getApplication();
  96. $context = $this->_context.'.';
  97. // Load the filter state.
  98. $published = $app->getUserStateFromRequest($context.'filter.published', 'published', '*', 'string');
  99. $this->setState('filter.state', ($published == '*' ? null : $published));
  100. $this->setState('filter.search', $app->getUserStateFromRequest($context.'filter.search', 'search', ''));
  101. // Load the list state.
  102. $this->setState('list.start', $app->getUserStateFromRequest($context.'list.start', 'limitstart', 0, 'int'));
  103. $this->setState('list.limit', $app->getUserStateFromRequest($context.'list.limit', 'limit', $app->getCfg('list_limit'), 'int'));
  104. $this->setState('list.ordering', $app->getUserStateFromRequest($context.'list.ordering', 'filter_order', 'a.ordering', 'cmd'));
  105. $this->setState('list.direction', $app->getUserStateFromRequest($context.'list.direction', 'filter_order_Dir', 'ASC', 'word'));
  106. }
  107. }