Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

104 рядки
4.1KB

  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_export_button, show_card_age, card_age_warning_days, created_at, created_by, updated_at, updated_by)
  30. VALUES (:board_id, :name, :position, :show_export_button, :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_export_button' => $lane->showExportButton ? 1 : 0,
  36. 'show_card_age' => $lane->showCardAge ? 1 : 0,
  37. 'card_age_warning_days' => $lane->cardAgeWarningDays,
  38. 'created_at' => $lane->createdAt,
  39. 'created_by' => $lane->createdBy,
  40. 'updated_at' => $lane->updatedAt,
  41. 'updated_by' => $lane->updatedBy,
  42. ]
  43. );
  44. $row = $this->database->first('SELECT last_insert_rowid() AS id');
  45. $lane->id = (int) ($row['id'] ?? 0);
  46. return $lane;
  47. }
  48. public function update(SwimLane $lane): void
  49. {
  50. $this->database->execute(
  51. 'UPDATE swim_lanes SET name = :name, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  52. ['name' => $lane->name, 'updated_at' => $lane->updatedAt, 'updated_by' => $lane->updatedBy, 'id' => $lane->id]
  53. );
  54. }
  55. public function updateShowExportButton(int $id, bool $show, string $updatedAt, string $updatedBy): void
  56. {
  57. $this->database->execute(
  58. 'UPDATE swim_lanes SET show_export_button = :show_export_button, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  59. ['show_export_button' => $show ? 1 : 0, 'updated_at' => $updatedAt, 'updated_by' => $updatedBy, 'id' => $id]
  60. );
  61. }
  62. public function updateCardAgeSettings(int $id, bool $showCardAge, int $cardAgeWarningDays, string $updatedAt, string $updatedBy): void
  63. {
  64. $this->database->execute(
  65. 'UPDATE swim_lanes SET show_card_age = :show_card_age, card_age_warning_days = :card_age_warning_days,
  66. updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  67. [
  68. 'show_card_age' => $showCardAge ? 1 : 0,
  69. 'card_age_warning_days' => $cardAgeWarningDays,
  70. 'updated_at' => $updatedAt,
  71. 'updated_by' => $updatedBy,
  72. 'id' => $id,
  73. ]
  74. );
  75. }
  76. public function updatePosition(int $id, int $position, string $updatedAt, string $updatedBy): void
  77. {
  78. $this->database->execute(
  79. 'UPDATE swim_lanes SET position = :position, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  80. ['position' => $position, 'updated_at' => $updatedAt, 'updated_by' => $updatedBy, 'id' => $id]
  81. );
  82. }
  83. public function deleteByBoardId(int $boardId): void
  84. {
  85. $this->database->execute('DELETE FROM swim_lanes WHERE board_id = :board_id', ['board_id' => $boardId]);
  86. }
  87. }

Powered by TurnKey Linux.