/** * Counts the number of items resulting from a given database query. * * @param JDatabaseQuery $query Query whose results should be counted. * * @throws Exception * @return void */ public function countItems($query) { $cloned = clone $query; $cloned->clear('select')->select('COUNT(*)'); $this->db->setQuery($cloned); $count = $this->db->loadResult(); $offset = isset($this->list['offset']) ? $this->list['offset'] : $this->getState()->get('list.' . $this->prefix . '.offset', 0); $offset = $this->app->input->getInt('limitstart', $offset); $this->getState()->set('list.' . $this->prefix . 'offset', $offset); $defaultLimit = $this->app->get('list_limit'); $limit = isset($this->list['limit']) ? $this->list['limit'] : $this->getState()->get('list.' . $this->prefix . '.limit', $defaultLimit); $this->pagination = new JPagination($count, $offset, $limit, '', $this->app); if ($query instanceof JDatabaseQueryLimitable) { $query->setLimit($limit, $offset); } }