where('`show` = "y"'); return $this; } public function getRandom() { $select = $this->_db->select(); $select->from($this->_getPair(), 'FLOOR(RAND() * COUNT(*))'); $this->_filter($select); $offset = $this->_db->fetchOne($select); $select->reset(); $select->from($this->_getPair()); $this->_filter($select); $select->limit(1, $offset); $item = $this->_db->fetchRow($select); return $item; } protected function _getListPositions() { $select = $this->_db->select();; $select->from($this->_getPair(), 'id'); $select->where('`show` = "y"'); if (Qs_Array::get($this->_selectOptions, 'order')) { $select->order($this->_selectOptions['order']); } $positions = $this->_db->fetchCol($select); $positions = array_flip($positions); return $positions; } protected function _prepareSearchList(array &$list, array $providerOptions) { if (!empty($list)) { $positions = $this->_getListPositions(); $testimonialList = new App_Testimonial_List([]); $ipp = $testimonialList->getDefaultIpp(); foreach ($list as &$row) { $position = (int) $positions[$row['id']]; $position++; $row['page'] = ceil($position / $ipp); } } return parent::_prepareSearchList($list, $providerOptions); } }