fix tag query to show all tags of an item, even if not included in query (#810)
This commit is contained in:
@@ -84,10 +84,11 @@ abstract class TimesheetAbstractController extends AbstractController
|
|||||||
$query->setUser($this->getUser());
|
$query->setUser($this->getUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($query->hasTags()) {
|
$tags = $query->getTags(true);
|
||||||
|
if (!empty($tags)) {
|
||||||
$query->setTags(
|
$query->setTags(
|
||||||
new ArrayCollection(
|
new ArrayCollection(
|
||||||
$this->getDoctrine()->getRepository(Tag::class)->findIdsByTagNameList(implode(',', $query->getTags()->toArray()))
|
$this->getDoctrine()->getRepository(Tag::class)->findIdsByTagNameList(implode(',', $tags))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
namespace App\Repository\Query;
|
namespace App\Repository\Query;
|
||||||
|
|
||||||
use App\Entity\Activity;
|
use App\Entity\Activity;
|
||||||
|
use App\Entity\Tag;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Form\Model\DateRange;
|
use App\Form\Model\DateRange;
|
||||||
|
|
||||||
@@ -216,9 +217,22 @@ class TimesheetQuery extends ActivityQuery
|
|||||||
/**
|
/**
|
||||||
* @return iterable
|
* @return iterable
|
||||||
*/
|
*/
|
||||||
public function getTags()
|
public function getTags($allowUnknown = false)
|
||||||
{
|
{
|
||||||
return $this->tags;
|
if (empty($this->tags)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($this->tags as $tag) {
|
||||||
|
if (!$allowUnknown && $tag instanceof Tag && null === $tag->getId()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$result[] = $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,12 +245,4 @@ class TimesheetQuery extends ActivityQuery
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function hasTags()
|
|
||||||
{
|
|
||||||
return !empty($this->tags) && count($this->tags) > 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -383,9 +383,10 @@ class TimesheetRepository extends AbstractRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($query->hasTags()) {
|
$tags = $query->getTags();
|
||||||
$qb->andWhere('tags.id IN (:tags)')
|
if (!empty($tags)) {
|
||||||
->setParameter('tags', $query->getTags()->toArray());
|
$qb->andWhere($qb->expr()->isMemberOf(':tags', 't.tags'))
|
||||||
|
->setParameter('tags', $query->getTags());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getBaseQueryResult($qb, $query);
|
return $this->getBaseQueryResult($qb, $query);
|
||||||
|
|||||||
Reference in New Issue
Block a user