DbTableSelect.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ GIx4p8S/nwTLaP/4PnVENoJJ7mb1quk6iV64rEWZ/lw=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * db table select pagination adapter
  14. * returns an object of type Cube\Db\Table\Rowset\AbstractRowset
  15. */
  16. namespace Cube\Paginator\Adapter;
  17. use Cube\Db\Select,
  18. Cube\Db\Table\AbstractTable;
  19. class DbTableSelect extends DbSelect
  20. {
  21. /**
  22. *
  23. * table class the row belongs to
  24. *
  25. * @var \Cube\Db\Table\AbstractTable
  26. */
  27. protected $_table = null;
  28. /**
  29. *
  30. * class constructor
  31. *
  32. * @param \Cube\Db\Select $select the select object
  33. * @param \Cube\Db\Table\AbstractTable $table
  34. */
  35. public function __construct(Select $select, AbstractTable $table)
  36. {
  37. parent::__construct($select);
  38. $this->_table = $table;
  39. }
  40. /**
  41. *
  42. * returns an array of items for the selected page
  43. *
  44. * @param integer $offset page offset
  45. * @param integer $itemCountPerPage number of items per page
  46. * @return \Cube\Db\Table\Rowset\AbstractRowset
  47. */
  48. public function getItems($offset, $itemCountPerPage)
  49. {
  50. $this->_select->limit($itemCountPerPage, $offset);
  51. return $this->_table->fetchAll($this->_select);
  52. }
  53. }