StatusModel.php 693 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace Models;
  3. class StatusModel
  4. {
  5. private \PDO $pdo;
  6. public function __construct()
  7. {
  8. if (isset($GLOBALS['pdo']) && $GLOBALS['pdo'] instanceof \PDO) {
  9. $this->pdo = $GLOBALS['pdo'];
  10. return;
  11. }
  12. throw new \RuntimeException('Global PDO connection not initialized');
  13. }
  14. public function getIdByStatus(string $status): ?int
  15. {
  16. $stmt = $this->pdo->prepare('SELECT status_id FROM "status" WHERE LOWER(status_status) = LOWER(:status) LIMIT 1');
  17. $stmt->execute(['status' => $status]);
  18. $id = $stmt->fetchColumn();
  19. return $id === false ? null : (int)$id;
  20. }
  21. }