<?php

/**
 * @author wbachur
 */
class Eppe_Paginator_Adapter_Rb implements Zend_Paginator_Adapter_Interface {

	/**
	 * String
	 *
	 * @var string
	 */
	protected $_beanName = null;

	/**
	 * Item count
	 *
	 * @var integer
	 */
	protected $_count = null;

	/**
	 * Query after WHERE clause
	 *
	 * @var string
	 */
	protected $_query = null;

	/**
	 * Constructor
	 *
	 * @param string $beanName
	 * @param string $query after WHERE clause
	 */
	public function __construct($beanName, $countQuery, $query) {
		$this->_query = $query;
		$this->_beanName = $beanName;
		$this->_count = R::getCell($countQuery);
	}

	/**
	 * Returns an array of items for a page.
	 *
	 * @param  integer $offset Page offset
	 * @param  integer $itemCountPerPage Number of items per page
	 * @return array
	 */
	public function getItems($offset, $itemCountPerPage) {
		return R::getAll($this->_query . ' LIMIT ' . $offset . ',' . $itemCountPerPage);
	}

	/**
	 * Returns the total number of rows in the array.
	 *
	 * @return integer
	 */
	public function count() {
		return $this->_count;
	}
}

