added table-column ordering (#1086)
This commit is contained in:
@@ -245,9 +245,23 @@ class ActivityRepository extends EntityRepository
|
||||
->from(Activity::class, 'a')
|
||||
->leftJoin('a.project', 'p')
|
||||
->leftJoin('p.customer', 'c')
|
||||
->addOrderBy('a.' . $query->getOrderBy(), $query->getOrder())
|
||||
;
|
||||
|
||||
$orderBy = $query->getOrderBy();
|
||||
switch ($orderBy) {
|
||||
case 'project':
|
||||
$orderBy = 'p.name';
|
||||
break;
|
||||
case 'customer':
|
||||
$orderBy = 'c.name';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'a.' . $orderBy;
|
||||
break;
|
||||
}
|
||||
|
||||
$qb->addOrderBy($orderBy, $query->getOrder());
|
||||
|
||||
$where = $qb->expr()->andX();
|
||||
|
||||
if (in_array($query->getVisibility(), [ActivityQuery::SHOW_VISIBLE, ActivityQuery::SHOW_HIDDEN])) {
|
||||
|
||||
@@ -212,9 +212,20 @@ class ProjectRepository extends EntityRepository
|
||||
->select('p')
|
||||
->from(Project::class, 'p')
|
||||
->leftJoin('p.customer', 'c')
|
||||
->addOrderBy('p.' . $query->getOrderBy(), $query->getOrder())
|
||||
;
|
||||
|
||||
$orderBy = $query->getOrderBy();
|
||||
switch ($orderBy) {
|
||||
case 'customer':
|
||||
$orderBy = 'c.name';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'p.' . $orderBy;
|
||||
break;
|
||||
}
|
||||
|
||||
$qb->addOrderBy($orderBy, $query->getOrder());
|
||||
|
||||
if (in_array($query->getVisibility(), [ProjectQuery::SHOW_VISIBLE, ProjectQuery::SHOW_HIDDEN])) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('p.visible', ':visible'))
|
||||
|
||||
@@ -16,6 +16,8 @@ use App\Entity\Project;
|
||||
*/
|
||||
class ActivityQuery extends ProjectQuery
|
||||
{
|
||||
public const ACTIVITY_ORDER_ALLOWED = ['id', 'name', 'comment', 'customer', 'project'];
|
||||
|
||||
/**
|
||||
* @var Project|int|null
|
||||
*/
|
||||
@@ -28,7 +30,9 @@ class ActivityQuery extends ProjectQuery
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setOrderBy('name');
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'name',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,24 +72,4 @@ class ActivityQuery extends ProjectQuery
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDirty(): bool
|
||||
{
|
||||
if (parent::isDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->project !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->globalsOnly !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace App\Repository\Query;
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use App\Utils\SearchTerm;
|
||||
use Symfony\Component\Form\FormErrorIterator;
|
||||
|
||||
/**
|
||||
* Base class for advanced Repository queries.
|
||||
@@ -28,6 +29,13 @@ class BaseQuery
|
||||
public const RESULT_TYPE_PAGER = 'PagerFanta';
|
||||
public const RESULT_TYPE_QUERYBUILDER = 'QueryBuilder';
|
||||
|
||||
private $defaults = [
|
||||
'page' => self::DEFAULT_PAGE,
|
||||
'pageSize' => self::DEFAULT_PAGESIZE,
|
||||
'orderBy' => 'id',
|
||||
'order' => self::ORDER_ASC,
|
||||
'searchTerm' => null,
|
||||
];
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -214,29 +222,43 @@ class BaseQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the query has changed fields, compared to the original state.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDirty(): bool
|
||||
protected function set($name, $value)
|
||||
{
|
||||
if ($this->page !== self::DEFAULT_PAGE) {
|
||||
return true;
|
||||
$method = 'set' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->{$method}($value);
|
||||
} elseif (property_exists($this, $name)) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $defaults
|
||||
* @return self
|
||||
*/
|
||||
protected function setDefaults(array $defaults)
|
||||
{
|
||||
$this->defaults = array_merge($this->defaults, $defaults);
|
||||
foreach ($this->defaults as $key => $value) {
|
||||
$this->set($key, $value);
|
||||
}
|
||||
|
||||
if ($this->pageSize !== self::DEFAULT_PAGESIZE) {
|
||||
return true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormErrorIterator $errors
|
||||
* @return self
|
||||
*/
|
||||
public function resetByFormError(FormErrorIterator $errors)
|
||||
{
|
||||
foreach ($errors as $error) {
|
||||
$key = $error->getOrigin()->getName();
|
||||
if (array_key_exists($key, $this->defaults)) {
|
||||
$this->set($key, $this->defaults[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->teams)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (null !== $this->searchTerm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,12 @@ namespace App\Repository\Query;
|
||||
*/
|
||||
class CustomerQuery extends VisibilityQuery
|
||||
{
|
||||
public const CUSTOMER_ORDER_ALLOWED = ['id', 'name', 'comment', 'country', 'number'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setOrderBy('name');
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'name',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ use App\Entity\Customer;
|
||||
*/
|
||||
class ProjectQuery extends CustomerQuery
|
||||
{
|
||||
public const PROJECT_ORDER_ALLOWED = ['id', 'name', 'comment', 'customer', 'orderNumber'];
|
||||
|
||||
/**
|
||||
* @var Customer|int|null
|
||||
*/
|
||||
@@ -24,7 +26,9 @@ class ProjectQuery extends CustomerQuery
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setOrderBy('name');
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'name',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,20 +49,4 @@ class ProjectQuery extends CustomerQuery
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDirty(): bool
|
||||
{
|
||||
if (parent::isDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->customer !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,12 @@ namespace App\Repository\Query;
|
||||
|
||||
class TagQuery extends BaseQuery
|
||||
{
|
||||
public const TAG_ORDER_ALLOWED = ['id', 'name', 'amount'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setOrderBy('name');
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'name',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,12 @@ namespace App\Repository\Query;
|
||||
|
||||
class TeamQuery extends BaseQuery
|
||||
{
|
||||
public const TEAM_ORDER_ALLOWED = ['id', 'name', 'teamlead'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setOrderBy('name');
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'name',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ class TimesheetQuery extends ActivityQuery
|
||||
public const STATE_EXPORTED = 4;
|
||||
public const STATE_NOT_EXPORTED = 5;
|
||||
|
||||
public const TIMESHEET_ORDER_ALLOWED = ['begin', 'end', 'duration', 'rate', 'customer', 'project', 'activity', 'description'];
|
||||
|
||||
/**
|
||||
* @var User|null
|
||||
*/
|
||||
@@ -57,9 +59,11 @@ class TimesheetQuery extends ActivityQuery
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setOrder(self::ORDER_DESC);
|
||||
$this->setOrderBy('begin');
|
||||
$this->dateRange = new DateRange();
|
||||
$this->setDefaults([
|
||||
'order' => self::ORDER_DESC,
|
||||
'orderBy' => 'begin',
|
||||
'dateRange' => new DateRange()
|
||||
]);
|
||||
}
|
||||
|
||||
public function addUser(User $user): self
|
||||
@@ -266,40 +270,4 @@ class TimesheetQuery extends ActivityQuery
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDirty(): bool
|
||||
{
|
||||
if (parent::isDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->activity !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($this->tags)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->timesheetUser !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->state !== self::STATE_ALL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->exported !== self::STATE_ALL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->dateRange->getBegin() !== null || $this->dateRange->getEnd() !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,20 @@ namespace App\Repository\Query;
|
||||
*/
|
||||
class UserQuery extends VisibilityQuery
|
||||
{
|
||||
public const USER_ORDER_ALLOWED = ['id', 'alias', 'username', 'title', 'email'];
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $role;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setDefaults([
|
||||
'orderBy' => 'username',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
|
||||
@@ -54,20 +54,4 @@ class VisibilityQuery extends BaseQuery
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDirty(): bool
|
||||
{
|
||||
if (parent::isDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->visibility !== self::SHOW_VISIBLE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +105,20 @@ class TagRepository extends EntityRepository
|
||||
->leftJoin('tag.timesheets', 'timesheets')
|
||||
->addGroupBy('tag.id')
|
||||
->addGroupBy('tag.name')
|
||||
->addOrderBy('tag.' . $query->getOrderBy(), $query->getOrder())
|
||||
;
|
||||
|
||||
$orderBy = $query->getOrderBy();
|
||||
switch ($orderBy) {
|
||||
case 'amount':
|
||||
$orderBy = 'amount';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'tag.' . $orderBy;
|
||||
break;
|
||||
}
|
||||
|
||||
$qb->addOrderBy($orderBy, $query->getOrder());
|
||||
|
||||
if ($query->hasSearchTerm()) {
|
||||
$searchTerm = $query->getSearchTerm();
|
||||
$searchAnd = $qb->expr()->andX();
|
||||
|
||||
@@ -104,9 +104,21 @@ class TeamRepository extends EntityRepository
|
||||
$qb
|
||||
->select('t')
|
||||
->from(Team::class, 't')
|
||||
->addOrderBy('t.' . $query->getOrderBy(), $query->getOrder())
|
||||
;
|
||||
|
||||
$orderBy = $query->getOrderBy();
|
||||
switch ($orderBy) {
|
||||
case 'teamlead':
|
||||
$qb->leftJoin('t.teamlead', 'lead');
|
||||
$orderBy = 'lead.username';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 't.' . $orderBy;
|
||||
break;
|
||||
}
|
||||
|
||||
$qb->addOrderBy($orderBy, $query->getOrder());
|
||||
|
||||
if (!empty($query->getSearchTerm())) {
|
||||
$qb->andWhere(
|
||||
$qb->expr()->orX(
|
||||
|
||||
@@ -493,7 +493,6 @@ class TimesheetRepository extends EntityRepository
|
||||
}
|
||||
|
||||
$qb
|
||||
->leftJoin('p.customer', 'c')
|
||||
->leftJoin('p.teams', 'teams')
|
||||
->leftJoin('c.teams', 'c_teams');
|
||||
|
||||
@@ -551,9 +550,28 @@ class TimesheetRepository extends EntityRepository
|
||||
->select('t')
|
||||
->from(Timesheet::class, 't')
|
||||
->leftJoin('t.project', 'p')
|
||||
->addOrderBy('t.' . $query->getOrderBy(), $query->getOrder())
|
||||
->leftJoin('p.customer', 'c')
|
||||
;
|
||||
|
||||
$orderBy = $query->getOrderBy();
|
||||
switch ($orderBy) {
|
||||
case 'project':
|
||||
$orderBy = 'p.name';
|
||||
break;
|
||||
case 'customer':
|
||||
$orderBy = 'c.name';
|
||||
break;
|
||||
case 'activity':
|
||||
$qb->leftJoin('t.activity', 'a');
|
||||
$orderBy = 'a.name';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 't.' . $orderBy;
|
||||
break;
|
||||
}
|
||||
|
||||
$qb->addOrderBy($orderBy, $query->getOrder());
|
||||
|
||||
$user = [];
|
||||
if (null !== $query->getUser()) {
|
||||
$user[] = $query->getUser();
|
||||
|
||||
@@ -86,9 +86,11 @@ class UserRepository extends EntityRepository implements UserLoaderInterface
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('u')
|
||||
$qb
|
||||
->select('u')
|
||||
->from(User::class, 'u')
|
||||
->orderBy('u.' . $query->getOrderBy(), $query->getOrder());
|
||||
->orderBy('u.' . $query->getOrderBy(), $query->getOrder())
|
||||
;
|
||||
|
||||
if (UserQuery::SHOW_VISIBLE == $query->getVisibility()) {
|
||||
$qb->andWhere($qb->expr()->eq('u.enabled', ':enabled'));
|
||||
|
||||
Reference in New Issue
Block a user