fix tag query to show all tags of an item, even if not included in query (#810)

This commit is contained in:
Kevin Papst
2019-05-25 16:27:01 +02:00
committed by GitHub
parent 46905e9504
commit d18019159b
3 changed files with 23 additions and 15 deletions

View File

@@ -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))
) )
); );
} }

View File

@@ -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;
}
} }

View File

@@ -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);