Jacek Kowalski
4 hours ago 6b9278a5d57091fce636dbb640b380cfb990db6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types=1);
 
namespace App\Repository;
 
use App\Entity\Label;
use App\Enum\LabelType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
 
/**
 * @extends ServiceEntityRepository<Label>
 */
class LabelRepository extends ServiceEntityRepository {
    public function __construct(ManagerRegistry $registry) {
        parent::__construct($registry, Label::class);
    }
 
    /**
     * @return list<array{label: string, books: int}>
     */
    public function findUsage(): array {
        /** @var list<array{label: string, books: int}> */
        return $this->createQueryBuilder('l')
            ->select('l.label AS label', 'COUNT(l.id) AS books')
            ->where('l.type = :type')
            ->setParameter('type', LabelType::TEXT->value)
            ->groupBy('l.label')
            ->orderBy('l.label', 'ASC')
            ->getQuery()
            ->getResult();
    }
}