Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

113 строки
4.6KB

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

Powered by TurnKey Linux.