first commit
This commit is contained in:
24
src/Post/Infrastructure/PdoTaxonUsageChecker.php
Normal file
24
src/Post/Infrastructure/PdoTaxonUsageChecker.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user