Add limit query

@param   KModelContextInterface $context A model context object
@return    void
550339
protected function _beforeFetch(KModelContextInterface $context)
    {
        $model = $context->getSubject();

        if ($model instanceof KModelDatabase && !$context->state->isUnique())
        {
            $state = $context->state;
            $limit = $state->limit;

            if ($limit)
            {
                $offset = $state->offset;
                $total  = $this->count();

                if ($offset !== 0 && $total !== 0)
                {
                    // Recalculate the offset if it is set to the middle of a page.
                    if ($offset % $limit !== 0) {
                        $offset -= ($offset % $limit);
                    }

                    // Recalculate the offset if it is higher than the total
                    if ($offset >= $total) {
                        $offset = floor(($total - 1) / $limit) * $limit;
                    }

                    $state->offset = $offset;
                }

                $context->query->limit($limit, $offset);
            }
        }
    }
76
public function addLimitOffset(int $limit, int $offset): void
    {
        if ($limit === 0 && $offset === 0) {
            return;
        }
        if ($limit === 0 && $offset <> 0) {
            return;
        }
        if ($offset === 0) {
            $this->statement .= ' LIMIT ' . $limit;
        } else {
            $this->statement .= sprintf(' LIMIT %d, %d', $offset, $limit);
        }
        $this->statement .= PHP_EOL;
    }
1268852
protected function _actionSend(KDispatcherContextInterface $context)
    {
        //Send the response
        $context->response->send(false);

        //Terminate the response
        $this->terminate($context);
    }
465682
private function appendLimitAndOffset(QueryBuilder $builder, $limit, $offset)
    {
        $limit = (int) $limit;
        $offset = (int) $offset;

        if ($limit > 0) {
            $builder->limit($limit);
        }

        if ($offset > 0) {
            $builder->skip($offset);
        }
        return $this;
    }
1094944
protected function _afterEdit(KControllerContextInterface $context)
    {
        $name   = $this->getMixer()->getIdentifier()->name;

        foreach ($context->result as $entity)
        {
            if ($entity->getStatus() !== KDatabase::STATUS_FAILED)
            {
                if ($name === $this->_category_entity)
                {
                    if (($entity->old_enabled !== $entity->enabled) || ($entity->old_access !== $entity->access))
                    {
                        $category_context = 'com_'.$this->_package.'.'.$this->_category_entity;

                        $this->_getDispatcher()->trigger('onFinderAfterSave', array($category_context, $entity, false));
                    }
                } else {
                    $this->_getDispatcher()->trigger('onFinderAfterSave', array($this->_event_context, $entity, false));
                }
            }
        }
    }
376842
public void setContextLimits(int contextStart, int contextLimit) {
        if(contextStart<0) {
            this.contextStart=0;
        } else if(contextStart<=rep.length()) {
            this.contextStart=contextStart;
        } else {
            this.contextStart=rep.length();
        }
        if(contextLimit<this.contextStart) {
            this.contextLimit=this.contextStart;
        } else if(contextLimit<=rep.length()) {
            this.contextLimit=contextLimit;
        } else {
            this.contextLimit=rep.length();
        }
        reachedLimit=false;
    }
479812
protected function set_limit($query, $limit = 0, $offset = 0)
    {
        $limit  = intval($limit);
        $offset = intval($offset);
        $end    = $offset + $limit;

        // @TODO: Oracle 12g has better OFFSET support

        if (!$offset) {
            $query = "SELECT * FROM ($query) a WHERE rownum <= $end";
        }
        else {
            $query = "SELECT * FROM (SELECT a.*, rownum as rn FROM ($query) a WHERE rownum <= $end) b WHERE rn > $offset";
        }

        return $query;
    }
267158
public function limit($offset = null, $limit = null)
    {
    	$args = func_get_args();
    	if (count($args) === 0) {
    		throw new Exception('At least 1 argument');
    	}
    	if (count($args) == 1) {
    		$this->limit =  $args[0];
    	} else {
    		list($this->offset, $this->limit) = $args;
    	}
        return $this;
    }
273031
protected function _beforeUpdate(KDatabaseContextInterface $context)
    {
        //Get the modified columns
        $modified   = $this->getTable()->filter($this->getProperties(true));

        if(!empty($modified))
        {
            if($this->hasProperty('modified_by')) {
                $this->modified_by = (int) $this->getObject('user')->getId();
            }

            if($this->hasProperty('modified_on')) {
                $this->modified_on = gmdate('Y-m-d H:i:s');
            }
        }
    }
1148232
public function limit(int $limit, int $offset = null): self
    {
        $this->query['limit'] = ($offset === null)
            ? [abs($limit)] : [abs($limit), abs($offset)];

        return $this;
    }
473633
protected function _actionCancel(KControllerContextInterface $context)
	{
        //Create the redirect
        $context->response->setRedirect($this->getReferrer($context));

        if ($context->result instanceof KModelEntityInterface) {
            $entity = $context->result;
        }
        else
        {
            $model  = $this->getModel();
            $entity = $model->getState()->isUnique() ? $model->fetch() : $model->create();
        }

        return $entity;
	}
1171619
protected function _beforeFetch(ModelContextInterface $context)
    {
        $model = $context->getSubject();

        if ($model instanceof ModelDatabase && !$context->state->isUnique())
        {
            $state = $context->state;
            $limit = $state->limit;

            if ($limit)
            {
                $offset = $state->offset;
                $total  = $this->count();

                if ($offset !== 0 && $total !== 0)
                {
                    // Recalculate the offset if it is set to the middle of a page.
                    if ($offset % $limit !== 0) {
                        $offset -= ($offset % $limit);
                    }

                    // Recalculate the offset if it is higher than the total
                    if ($offset >= $total) {
                        $offset = floor(($total - 1) / $limit) * $limit;
                    }

                    $state->offset = $offset;
                }

                $context->query->limit($limit, $offset);
            }
        }
    }
1268656
protected function _afterAdd(KControllerContextInterface $context)
    {
        $entity  = $context->result;
        $name    = $entity->getIdentifier()->name;

        if ($name === $this->_entity && $entity->getStatus() !== KDatabase::STATUS_FAILED) {
            $this->_getDispatcher()->trigger('onFinderAfterSave', array($this->_event_context, $entity, true));
        }
    }
129524
function setRoundPointsLimit($limit, $multicall = false)
    {
        if (!is_int($limit)) {
            throw new InvalidArgumentException('limit = ' . print_r($limit, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($limit), $multicall);
    }
669920
public function filter(Context $context)
    {
        $this->index++;
        if(empty($this->m_filters) || $this->index >= count($this->m_filters))
            return;
        $filter=$this->m_filters[$this->index];
        return $filter->filter($context,$this);
    }
748430
public function limit(int $limit, $offset=FALSE): QueryBuilderInterface
	{
		$this->state->setLimit($limit);
		$this->state->setOffset($offset);

		return $this;
	}
867858
protected function _lockResource(KControllerContextInterface $context)
    {
        $domain = $this->getMixer()->getIdentifier()->domain;

        if ($domain === 'admin' || $this->getRequest()->query->layout === 'form') {
            parent::_lockResource($context);
        }
    }