/**
  * 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)
 {
     // Cast to integers, as $itemCountPerPage can be string sometimes and that would fail later checks
     $offset = (int) $offset;
     $itemCountPerPage = (int) $itemCountPerPage;
     if ($this->_lastOffset === $offset && $this->_lastItemCount === $itemCountPerPage && null !== $this->_lastItems) {
         return $this->_lastItems;
     }
     $this->_lastOffset = $offset;
     $this->_lastItemCount = $itemCountPerPage;
     // Optimization: by using the MySQL feature SQL_CALC_FOUND_ROWS
     // we can get the count and the results in a single query.
     $db = $this->_select->getAdapter();
     if (null === $this->_count && $db instanceof \Zend_Db_Adapter_Mysqli) {
         $this->_select->limit($itemCountPerPage, $offset);
         $sql = $this->_select->__toString();
         if (\MUtil_String::startsWith($sql, 'select ', true)) {
             $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, 7);
         }
         $this->_lastItems = $db->fetchAll($sql);
         $this->_count = $db->fetchOne('SELECT FOUND_ROWS()');
     } else {
         $this->_lastItems = $this->_selectAdapter->getItems($offset, $itemCountPerPage);
     }
     if (is_array($this->_lastItems)) {
         if (isset($this->_model->prefetchIterator) && $this->_model->prefetchIterator) {
             $this->_lastItems = new \ArrayIterator($this->_lastItems);
         }
         $this->_lastItems = $this->_model->processAfterLoad($this->_lastItems, false, false);
     }
     return $this->_lastItems;
 }