/** * undocumented function * * @param unknown $offset * @param unknown $whence * @return void * @access public */ function offset($offset = null) { if (is_null($offset)) { if (!is_object($this->resource)) { return $this->offset; } return $this->offset; } if (!ctype_digit($offset)) { return false; } if (is_object($this->resource)) { $this->resource->offset($offset); } else { $this->offset = $offset; } }
/** * * @param unknown $query * @param array $config ['db','page','pageSize','orderBy','rows','pager'] * @return multitype:\yii\data\Pagination unknown */ public static function getPagedRows($query, $config = []) { $db = isset($config['db']) ? $config['db'] : null; $countQuery = clone $query; $pager = new Pagination(['totalCount' => $countQuery->count('*', $db)]); if (isset($config['page'])) { $pager->setPage($config['page'], true); } if (isset($config['pageSize'])) { $pager->setPageSize($config['pageSize'], true); } $rows = $query->offset($pager->offset)->limit($pager->limit); if (isset($config['orderBy'])) { $rows = $rows->orderBy($config['orderBy']); } $rows = $rows->all($db); $rowsLable = isset($config['rows']) ? $config['rows'] : 'rows'; $pagerLable = isset($config['pager']) ? $config['pager'] : 'pager'; $ret = []; $ret[$rowsLable] = $rows; $ret[$pagerLable] = $pager; return $ret; }