/** * Set the state data * * @param array|object An associative array of state data by name * @return KModelPaginator */ public function setData(array $data) { parent::setData($data); if ($this->total == 0) { $limit = 0; $offset = 0; $count = 0; $current = 0; } else { $total = (int) $this->total; $limit = (int) max($this->limit, 1); $offset = (int) max($this->offset, 0); if ($limit > $total) { $offset = 0; } if (!$this->limit) { $offset = 0; $limit = $total; } $count = (int) ceil($total / $limit); if ($offset > $total) { $offset = ($count - 1) * $limit; } $current = (int) floor($offset / $limit) + 1; } $this->limit = $limit; $this->offset = $offset; $this->count = $count; $this->current = $current; return $this; }