toolbar dropdown and visibility improvements (#933)
This commit is contained in:
97
src/Repository/Query/ActivityFormTypeQuery.php
Normal file
97
src/Repository/Query/ActivityFormTypeQuery.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
|
||||
final class ActivityFormTypeQuery
|
||||
{
|
||||
/**
|
||||
* @var Activity|int|null
|
||||
*/
|
||||
private $activity;
|
||||
/**
|
||||
* @var Project|int|null
|
||||
*/
|
||||
private $project;
|
||||
/**
|
||||
* @var Activity|null
|
||||
*/
|
||||
private $activityToIgnore;
|
||||
|
||||
/**
|
||||
* @param Activity|int|null $activity
|
||||
* @param Project|int|null $project
|
||||
*/
|
||||
public function __construct($activity = null, $project = null)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Activity|int|null
|
||||
*/
|
||||
public function getActivity()
|
||||
{
|
||||
return $this->activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity|int|null $activity
|
||||
* @return ActivityFormTypeQuery
|
||||
*/
|
||||
public function setActivity($activity): ActivityFormTypeQuery
|
||||
{
|
||||
$this->activity = $activity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project|int|null
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project|int|null $project
|
||||
* @return ActivityFormTypeQuery
|
||||
*/
|
||||
public function setProject($project): ActivityFormTypeQuery
|
||||
{
|
||||
$this->project = $project;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Activity|null
|
||||
*/
|
||||
public function getActivityToIgnore(): ?Activity
|
||||
{
|
||||
return $this->activityToIgnore;
|
||||
}
|
||||
|
||||
public function setActivityToIgnore(Activity $activityToIgnore): ActivityFormTypeQuery
|
||||
{
|
||||
$this->activityToIgnore = $activityToIgnore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isGlobalsOnly(): bool
|
||||
{
|
||||
return null === $this->activity && null === $this->project;
|
||||
}
|
||||
}
|
||||
@@ -19,29 +19,16 @@ class ActivityQuery extends ProjectQuery
|
||||
/**
|
||||
* @var Project|int|null
|
||||
*/
|
||||
protected $project;
|
||||
private $project;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $orderGlobalsFirst = false;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $globalsOnly = false;
|
||||
private $globalsOnly = false;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isOrderGlobalsFirst(): bool
|
||||
public function __construct()
|
||||
{
|
||||
return $this->orderGlobalsFirst;
|
||||
}
|
||||
|
||||
public function setOrderGlobalsFirst(bool $orderGlobalsFirst): ActivityQuery
|
||||
{
|
||||
$this->orderGlobalsFirst = $orderGlobalsFirst;
|
||||
|
||||
return $this;
|
||||
parent::__construct();
|
||||
$this->setOrderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,4 +68,24 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,29 +25,25 @@ class BaseQuery
|
||||
public const RESULT_TYPE_QUERYBUILDER = 'QueryBuilder';
|
||||
|
||||
/**
|
||||
* @var object|null
|
||||
* @var int
|
||||
*/
|
||||
protected $hiddenEntity;
|
||||
private $page = self::DEFAULT_PAGE;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $page = self::DEFAULT_PAGE;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $pageSize = self::DEFAULT_PAGESIZE;
|
||||
private $pageSize = self::DEFAULT_PAGESIZE;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $orderBy = 'id';
|
||||
private $orderBy = 'id';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $order = self::ORDER_ASC;
|
||||
private $order = self::ORDER_ASC;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resultType = self::RESULT_TYPE_PAGER;
|
||||
private $resultType = self::RESULT_TYPE_PAGER;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
@@ -68,10 +64,7 @@ class BaseQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPageSize()
|
||||
public function getPageSize(): int
|
||||
{
|
||||
return $this->pageSize;
|
||||
}
|
||||
@@ -82,17 +75,14 @@ class BaseQuery
|
||||
*/
|
||||
public function setPageSize($pageSize)
|
||||
{
|
||||
if (!empty($pageSize) && (int) $pageSize > 0) {
|
||||
if ($pageSize !== null && (int) $pageSize > 0) {
|
||||
$this->pageSize = (int) $pageSize;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderBy()
|
||||
public function getOrderBy(): string
|
||||
{
|
||||
return $this->orderBy;
|
||||
}
|
||||
@@ -110,10 +100,7 @@ class BaseQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOrder()
|
||||
public function getOrder(): string
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
@@ -132,6 +119,7 @@ class BaseQuery
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.0
|
||||
* @return string
|
||||
*/
|
||||
public function getResultType()
|
||||
@@ -140,6 +128,7 @@ class BaseQuery
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.0
|
||||
* @param string $resultType
|
||||
* @return $this
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -158,21 +147,20 @@ class BaseQuery
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object|null
|
||||
* Returns whether the query has changed fields, compared to the original state.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getHiddenEntity()
|
||||
public function isDirty(): bool
|
||||
{
|
||||
return $this->hiddenEntity;
|
||||
}
|
||||
if ($this->page !== self::DEFAULT_PAGE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object|string|null $hiddenEntity
|
||||
* @return BaseQuery
|
||||
*/
|
||||
public function setHiddenEntity($hiddenEntity)
|
||||
{
|
||||
$this->hiddenEntity = $hiddenEntity;
|
||||
if ($this->pageSize !== self::DEFAULT_PAGESIZE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
69
src/Repository/Query/CustomerFormTypeQuery.php
Normal file
69
src/Repository/Query/CustomerFormTypeQuery.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\Customer;
|
||||
|
||||
/**
|
||||
* Can be used for advanced queries with the: CustomerRepository
|
||||
*/
|
||||
final class CustomerFormTypeQuery
|
||||
{
|
||||
/**
|
||||
* @var Customer|int|null
|
||||
*/
|
||||
private $customer;
|
||||
/**
|
||||
* @var Customer|null
|
||||
*/
|
||||
private $customerToIgnore;
|
||||
|
||||
/**
|
||||
* @param Customer|int|null $customer
|
||||
*/
|
||||
public function __construct($customer = null)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer|int|null
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer|int|null $customer
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomer($customer): CustomerFormTypeQuery
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer|null
|
||||
*/
|
||||
public function getCustomerToIgnore(): ?Customer
|
||||
{
|
||||
return $this->customerToIgnore;
|
||||
}
|
||||
|
||||
public function setCustomerToIgnore(Customer $customerToIgnore): CustomerFormTypeQuery
|
||||
{
|
||||
$this->customerToIgnore = $customerToIgnore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -9,34 +9,13 @@
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\Customer;
|
||||
|
||||
/**
|
||||
* Can be used for advanced queries with the: CustomerRepository
|
||||
*/
|
||||
class CustomerQuery extends VisibilityQuery
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $ignored = [];
|
||||
|
||||
/**
|
||||
* @param Customer|int $customer
|
||||
* @return $this
|
||||
*/
|
||||
public function addIgnoredEntity($customer)
|
||||
public function __construct()
|
||||
{
|
||||
$this->ignored[] = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getIgnoredEntities()
|
||||
{
|
||||
return $this->ignored;
|
||||
$this->setOrderBy('name');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class ExportQuery extends TimesheetQuery
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
||||
@@ -19,14 +19,7 @@ class InvoiceQuery extends TimesheetQuery
|
||||
/**
|
||||
* @var InvoiceTemplate
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* TODO can this be removed ???
|
||||
*
|
||||
* @var InvoiceTemplate[]
|
||||
*/
|
||||
protected $templates = [];
|
||||
private $template;
|
||||
|
||||
/**
|
||||
* @return InvoiceTemplate
|
||||
|
||||
92
src/Repository/Query/ProjectFormTypeQuery.php
Normal file
92
src/Repository/Query/ProjectFormTypeQuery.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
|
||||
final class ProjectFormTypeQuery
|
||||
{
|
||||
/**
|
||||
* @var Customer|int|null
|
||||
*/
|
||||
private $customer;
|
||||
/**
|
||||
* @var Project|int|null
|
||||
*/
|
||||
private $project;
|
||||
/**
|
||||
* @var Project|null
|
||||
*/
|
||||
private $projectToIgnore;
|
||||
|
||||
/**
|
||||
* @param Project|int|null $project
|
||||
* @param Customer|int|null $customer
|
||||
*/
|
||||
public function __construct($project = null, $customer = null)
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer|int|null
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer|int|null $customer
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomer($customer): ProjectFormTypeQuery
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project|int|null
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project|int|null $project
|
||||
* @return ProjectFormTypeQuery
|
||||
*/
|
||||
public function setProject($project): ProjectFormTypeQuery
|
||||
{
|
||||
$this->project = $project;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project|null
|
||||
*/
|
||||
public function getProjectToIgnore(): ?Project
|
||||
{
|
||||
return $this->projectToIgnore;
|
||||
}
|
||||
|
||||
public function setProjectToIgnore(Project $projectToIgnore): ProjectFormTypeQuery
|
||||
{
|
||||
$this->projectToIgnore = $projectToIgnore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -14,35 +14,17 @@ use App\Entity\Customer;
|
||||
/**
|
||||
* Can be used for advanced queries with the: ProjectRepository
|
||||
*/
|
||||
class ProjectQuery extends VisibilityQuery
|
||||
class ProjectQuery extends CustomerQuery
|
||||
{
|
||||
/**
|
||||
* @var Customer|int|null
|
||||
*/
|
||||
protected $customer;
|
||||
private $customer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $ignored = [];
|
||||
|
||||
/**
|
||||
* @param mixed $entity
|
||||
* @return $this
|
||||
*/
|
||||
public function addIgnoredEntity($entity)
|
||||
public function __construct()
|
||||
{
|
||||
$this->ignored[] = $entity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getIgnoredEntities()
|
||||
{
|
||||
return $this->ignored;
|
||||
parent::__construct();
|
||||
$this->setOrderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,4 +45,20 @@ class ProjectQuery extends VisibilityQuery
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isDirty(): bool
|
||||
{
|
||||
if (parent::isDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->customer !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,6 @@ class TimesheetQuery extends ActivityQuery
|
||||
public const STATE_EXPORTED = 4;
|
||||
public const STATE_NOT_EXPORTED = 5;
|
||||
|
||||
/**
|
||||
* Overwritten for different default order
|
||||
* @var string
|
||||
*/
|
||||
protected $order = self::ORDER_DESC;
|
||||
/**
|
||||
* Overwritten for different default order
|
||||
* @var string
|
||||
*/
|
||||
protected $orderBy = 'begin';
|
||||
/**
|
||||
* @var User|null
|
||||
*/
|
||||
@@ -62,6 +52,9 @@ class TimesheetQuery extends ActivityQuery
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setOrder(self::ORDER_DESC);
|
||||
$this->setOrderBy('begin');
|
||||
$this->dateRange = new DateRange();
|
||||
}
|
||||
|
||||
@@ -245,4 +238,40 @@ 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->user !== 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,16 @@ class VisibilityQuery extends BaseQuery
|
||||
public const SHOW_HIDDEN = 2;
|
||||
public const SHOW_BOTH = 3;
|
||||
|
||||
public const ALLOWED_VISIBILITY_STATES = [
|
||||
self::SHOW_BOTH,
|
||||
self::SHOW_VISIBLE,
|
||||
self::SHOW_HIDDEN,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $visibility = self::SHOW_VISIBLE;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $exclusiveVisibility = false;
|
||||
private $visibility = self::SHOW_VISIBLE;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
@@ -46,7 +48,7 @@ class VisibilityQuery extends BaseQuery
|
||||
}
|
||||
|
||||
$visibility = (int) $visibility;
|
||||
if (in_array($visibility, [self::SHOW_BOTH, self::SHOW_VISIBLE, self::SHOW_HIDDEN], true)) {
|
||||
if (in_array($visibility, self::ALLOWED_VISIBILITY_STATES, true)) {
|
||||
$this->visibility = $visibility;
|
||||
}
|
||||
|
||||
@@ -54,23 +56,18 @@ class VisibilityQuery extends BaseQuery
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isExclusiveVisibility()
|
||||
public function isDirty(): bool
|
||||
{
|
||||
return $this->exclusiveVisibility;
|
||||
}
|
||||
if (parent::isDirty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true, this will ONLY filter the visibility on the main queried object.
|
||||
*
|
||||
* @param bool $exclusiveVisibility
|
||||
* @return $this
|
||||
*/
|
||||
public function setExclusiveVisibility($exclusiveVisibility)
|
||||
{
|
||||
$this->exclusiveVisibility = (bool) $exclusiveVisibility;
|
||||
if ($this->visibility !== self::SHOW_VISIBLE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user