A project management app derived from Mind-Vision-Code
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

65 wiersze
1.8KB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repositories;
  4. use Core\Database;
  5. class ActivityRepository
  6. {
  7. public function __construct(protected ?Database $database = null)
  8. {
  9. $this->database ??= database();
  10. }
  11. public function record(
  12. string $eventType,
  13. string $headline,
  14. string $detail = '',
  15. ?int $projectId = null,
  16. ?int $taskId = null
  17. ): void {
  18. $this->database->execute(
  19. 'INSERT INTO activity_log (project_id, task_id, event_type, headline, detail)
  20. VALUES (:project_id, :task_id, :event_type, :headline, :detail)',
  21. [
  22. 'project_id' => $projectId,
  23. 'task_id' => $taskId,
  24. 'event_type' => $eventType,
  25. 'headline' => $headline,
  26. 'detail' => $detail,
  27. ]
  28. );
  29. }
  30. public function recent(int $limit = 10): array
  31. {
  32. $limit = max(1, min(50, $limit));
  33. return $this->database->query(
  34. 'SELECT a.*, p.name AS project_name, p.code AS project_code, t.title AS task_title
  35. FROM activity_log a
  36. LEFT JOIN projects p ON p.id = a.project_id
  37. LEFT JOIN tasks t ON t.id = a.task_id
  38. ORDER BY a.created_at DESC, a.id DESC
  39. LIMIT ' . $limit
  40. );
  41. }
  42. public function forProject(int $projectId, int $limit = 12): array
  43. {
  44. $limit = max(1, min(50, $limit));
  45. return $this->database->query(
  46. 'SELECT a.*, t.title AS task_title
  47. FROM activity_log a
  48. LEFT JOIN tasks t ON t.id = a.task_id
  49. WHERE a.project_id = :project_id
  50. ORDER BY a.created_at DESC, a.id DESC
  51. LIMIT ' . $limit,
  52. ['project_id' => $projectId]
  53. );
  54. }
  55. }

Powered by TurnKey Linux.