Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

104 linhas
4.1KB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repositories;
  4. use App\Models\BoardColumn;
  5. use Core\Repository;
  6. class BoardColumnRepository extends Repository
  7. {
  8. protected string $table = 'board_columns';
  9. /** @return BoardColumn[] */
  10. public function findByBoardId(int $boardId): array
  11. {
  12. $rows = $this->database->query(
  13. 'SELECT * FROM board_columns WHERE board_id = :board_id ORDER BY position ASC',
  14. ['board_id' => $boardId]
  15. );
  16. return array_map(fn(array $r) => BoardColumn::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 board_columns WHERE board_id = :board_id',
  22. ['board_id' => $boardId]
  23. );
  24. return (int) ($row['max_pos'] ?? -1);
  25. }
  26. public function insert(BoardColumn $col): BoardColumn
  27. {
  28. $this->database->execute(
  29. 'INSERT INTO board_columns (board_id, name, position, show_card_count, 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_card_age, :card_age_warning_days, :created_at, :created_by, :updated_at, :updated_by)',
  31. [
  32. 'board_id' => $col->boardId,
  33. 'name' => $col->name,
  34. 'position' => $col->position,
  35. 'show_card_count' => $col->showCardCount ? 1 : 0,
  36. 'show_card_age' => $col->showCardAge ? 1 : 0,
  37. 'card_age_warning_days' => $col->cardAgeWarningDays,
  38. 'created_at' => $col->createdAt,
  39. 'created_by' => $col->createdBy,
  40. 'updated_at' => $col->updatedAt,
  41. 'updated_by' => $col->updatedBy,
  42. ]
  43. );
  44. $row = $this->database->first('SELECT last_insert_rowid() AS id');
  45. $col->id = (int) ($row['id'] ?? 0);
  46. return $col;
  47. }
  48. public function update(BoardColumn $col): void
  49. {
  50. $this->database->execute(
  51. 'UPDATE board_columns SET name = :name, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  52. ['name' => $col->name, 'updated_at' => $col->updatedAt, 'updated_by' => $col->updatedBy, 'id' => $col->id]
  53. );
  54. }
  55. public function updateShowCardCount(int $id, bool $show, string $updatedAt, string $updatedBy): void
  56. {
  57. $this->database->execute(
  58. 'UPDATE board_columns SET show_card_count = :show_card_count, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id',
  59. ['show_card_count' => $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 board_columns 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 board_columns 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 board_columns WHERE board_id = :board_id', ['board_id' => $boardId]);
  86. }
  87. }

Powered by TurnKey Linux.