mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-16 18:01:38 +00:00
Add IsGranted to TagController
This commit is contained in:
parent
4a1598165f
commit
943bfd9162
13 changed files with 310 additions and 41 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace Wallabag\Repository;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Wallabag\Entity\Tag;
|
||||
|
@ -13,8 +14,10 @@ use Wallabag\Entity\Tag;
|
|||
*/
|
||||
class TagRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
public function __construct(
|
||||
ManagerRegistry $registry,
|
||||
private string $tablePrefix,
|
||||
) {
|
||||
parent::__construct($registry, Tag::class);
|
||||
}
|
||||
|
||||
|
@ -85,6 +88,36 @@ class TagRepository extends ServiceEntityRepository
|
|||
->getArrayResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all tags per user with nb entries.
|
||||
*
|
||||
* @param int $userId
|
||||
*
|
||||
* @return array<array{tag: Tag, nbEntries: int}>
|
||||
*/
|
||||
public function findAllTagsWithNbEntries($userId)
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata(Tag::class, 't');
|
||||
$rsm->addEntityResult(Tag::class, 't', 'tag');
|
||||
$rsm->addScalarResult('nbEntries', 'nbEntries', 'integer');
|
||||
|
||||
$sql = <<<SQL
|
||||
SELECT DISTINCT {$rsm->generateSelectClause()}, count(e.id) as nbEntries
|
||||
FROM {$this->tablePrefix}tag t
|
||||
LEFT JOIN {$this->tablePrefix}entry_tag et ON et.tag_id = t.id
|
||||
JOIN {$this->tablePrefix}entry e ON e.id = et.entry_id
|
||||
WHERE e.user_id = :userId
|
||||
GROUP BY t.id
|
||||
ORDER BY t.label
|
||||
SQL;
|
||||
|
||||
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
|
||||
$query->setParameter('userId', $userId);
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
|
||||
public function findByLabelsAndUser($labels, $userId)
|
||||
{
|
||||
$qb = $this->getQueryBuilderByUser($userId)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue