25 lines
638 B
PHP
25 lines
638 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Post\Infrastructure;
|
|
|
|
use Netig\Netslim\Taxonomy\Contracts\TaxonUsageCheckerInterface;
|
|
use PDO;
|
|
|
|
/**
|
|
* Vérifie si un terme de taxonomie est encore référencé par au moins un post.
|
|
*/
|
|
final readonly class PdoTaxonUsageChecker implements TaxonUsageCheckerInterface
|
|
{
|
|
public function __construct(private PDO $db) {}
|
|
|
|
public function isTaxonInUse(int $taxonId): bool
|
|
{
|
|
$stmt = $this->db->prepare('SELECT COUNT(*) FROM posts WHERE category_id = :category_id');
|
|
$stmt->execute([':category_id' => $taxonId]);
|
|
|
|
return (int) $stmt->fetchColumn() > 0;
|
|
}
|
|
}
|