No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

95 líneas
3.5KB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repositories;
  4. use App\Models\SwimLane;
  5. use Core\Repository;
  6. class SwimLaneRepository extends Repository
  7. {
  8. protected string $table = 'swim_lanes';
  9. /** @return SwimLane[] */
  10. public function findByBoardId(int $boardId): array
  11. {
  12. $rows = $this->database->query(
  13. 'SELECT * FROM swim_lanes WHERE board_id = :board_id ORDER BY position ASC',
  14. ['board_id' => $boardId]
  15. );
  16. return array_map(fn(array $r) => SwimLane::fromRow($r), $rows);
  17. }
  18. public function maxPosition(int $boardId): int
  19. {
  20. $row = $this->database->first(
  21. 'SELECT MAX(position) AS max_pos FROM swim_lanes WHERE board_id = :board_id',
  22. ['board_id' => $boardId]
  23. );
  24. return (int) ($row['max_pos'] ?? -1);
  25. }
  26. public function insert(SwimLane $lane): SwimLane
  27. {
  28. $this->database->execute(
  29. 'INSERT INTO swim_lanes (board_id, name, position, show_card_age, card_age_warning_days, created_at, created_by, updated_at, updated_by)
  30. VALUES (:board_id, :name, :position, :show_card_age, :card_age_warning_days, :created_at, :created_by, :updated_at, :updated_by)',
  31. [
  32. 'board_id' => $lane->boardId,
  33. 'name' => $lane->name,
  34. 'position' => $lane->position,
  35. 'show_card_age' => $lane->showCardAge ? 1 : 0,
  36. 'card_age_warning_days' => $lane->cardAgeWarningDays,
  37. 'created_at' => $lane->createdAt,
  38. 'created_by' => $lane->createdBy,
  39. 'updated_at' => $lane->updatedAt,
  40. 'updated_by' => $lane->updatedBy,
  41. ]
  42. );
  43. $row = $this->database->first('SELECT last_insert_rowid() AS id');
  44. $lane->id = (int) ($row['id'] ?? 0);
  45. return $lane;
  46. }
  47. public function update(SwimLane $lane): void
  48. {
  49. $this->database->execute(
  50. 'UPDATE swim_lanes SET name = :name, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  51. ['name' => $lane->name, 'updated_at' => $lane->updatedAt, 'updated_by' => $lane->updatedBy, 'id' => $lane->id]
  52. );
  53. }
  54. public function updateCardAgeSettings(int $id, bool $showCardAge, int $cardAgeWarningDays, string $updatedAt, string $updatedBy): void
  55. {
  56. $this->database->execute(
  57. 'UPDATE swim_lanes SET show_card_age = :show_card_age, card_age_warning_days = :card_age_warning_days,
  58. updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  59. [
  60. 'show_card_age' => $showCardAge ? 1 : 0,
  61. 'card_age_warning_days' => $cardAgeWarningDays,
  62. 'updated_at' => $updatedAt,
  63. 'updated_by' => $updatedBy,
  64. 'id' => $id,
  65. ]
  66. );
  67. }
  68. public function updatePosition(int $id, int $position, string $updatedAt, string $updatedBy): void
  69. {
  70. $this->database->execute(
  71. 'UPDATE swim_lanes SET position = :position, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  72. ['position' => $position, 'updated_at' => $updatedAt, 'updated_by' => $updatedBy, 'id' => $id]
  73. );
  74. }
  75. public function deleteByBoardId(int $boardId): void
  76. {
  77. $this->database->execute('DELETE FROM swim_lanes WHERE board_id = :board_id', ['board_id' => $boardId]);
  78. }
  79. }

Powered by TurnKey Linux.