<?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();
|
}
|
}
|