Files
kimai/src/AppBundle/Repository/Query/BaseQuery.php
Kevin Papst fa8e976e76 Repository cleanup #40 (#41)
* added base classes for repositories and queries #40
* prepared controller and repositories to use fetchByQuery() #40
* removed findAll() which has added pagination to the original doctrine method #40
2018-01-07 11:18:42 +01:00

120 lines
2.1 KiB
PHP

<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Repository\Query;
/**
* Base class for advanced Repository queries.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class BaseQuery
{
const DEFAULT_PAGESIZE = 25;
const DEFAULT_PAGE = 1;
/**
* @var int
*/
protected $page = self::DEFAULT_PAGE;
/**
* @var int
*/
protected $pageSize = self::DEFAULT_PAGESIZE;
/**
* @var string
*/
protected $orderBy = 'id';
/**
* @var string
*/
protected $order = 'ASC';
/**
* @return int
*/
public function getPage()
{
return $this->page;
}
/**
* @param int $page
* @return BaseQuery
*/
public function setPage($page)
{
$this->page = $page;
return $this;
}
/**
* @return int
*/
public function getPageSize()
{
return $this->pageSize;
}
/**
* @param int $pageSize
* @return BaseQuery
*/
public function setPageSize($pageSize)
{
if (!empty($pageSize) && (int)$pageSize > 0) {
$this->pageSize = (int)$pageSize;
}
return $this;
}
/**
* @return string
*/
public function getOrderBy()
{
return $this->orderBy;
}
/**
* You need to validate carefully if this value is used from a user-input.
*
* @param string $orderBy
* @return BaseQuery
*/
public function setOrderBy($orderBy)
{
$this->orderBy = $orderBy;
return $this;
}
/**
* @return string
*/
public function getOrder()
{
return $this->order;
}
/**
* @param string $order
* @return BaseQuery
*/
public function setOrder($order)
{
if (in_array($order, ['ASC', 'DESC'])) {
$this->order = $order;
}
return $this;
}
}