Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

110 Zeilen
3.9KB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repositories;
  4. use App\Models\Job;
  5. use Core\Repository;
  6. class JobRepository extends Repository
  7. {
  8. protected string $table = 'job';
  9. protected string $primaryKey = 'id';
  10. /** @return list<array<string, mixed>> */
  11. public function allWithDetails(): array
  12. {
  13. return $this->database->query(
  14. 'SELECT j.id, j.campaign_id, j.job_type_id, j.attribute_values,
  15. j.created_at, j.updated_at,
  16. ct.name AS campaign_type_name,
  17. jt.name AS job_type_name,
  18. jt.attributes AS job_type_attributes
  19. FROM job j
  20. INNER JOIN campaign c ON j.campaign_id = c.id
  21. INNER JOIN campaign_type ct ON c.campaign_type_id = ct.id
  22. INNER JOIN job_type jt ON j.job_type_id = jt.id
  23. ORDER BY j.id DESC'
  24. );
  25. }
  26. /** @return list<array<string, mixed>> */
  27. public function allWithDetailsForCampaign(int $campaignId): array
  28. {
  29. return $this->database->query(
  30. 'SELECT j.id, j.campaign_id, j.job_type_id, j.attribute_values,
  31. j.created_at, j.updated_at,
  32. ct.name AS campaign_type_name,
  33. jt.name AS job_type_name,
  34. jt.attributes AS job_type_attributes
  35. FROM job j
  36. INNER JOIN campaign c ON j.campaign_id = c.id
  37. INNER JOIN campaign_type ct ON c.campaign_type_id = ct.id
  38. INNER JOIN job_type jt ON j.job_type_id = jt.id
  39. WHERE j.campaign_id = :campaign_id
  40. ORDER BY j.id DESC',
  41. ['campaign_id' => $campaignId]
  42. );
  43. }
  44. public function findWithDetails(int $id): ?array
  45. {
  46. return $this->database->first(
  47. 'SELECT j.id, j.campaign_id, j.job_type_id, j.attribute_values,
  48. j.created_at, j.updated_at,
  49. ct.name AS campaign_type_name,
  50. jt.name AS job_type_name,
  51. jt.attributes AS job_type_attributes
  52. FROM job j
  53. INNER JOIN campaign c ON j.campaign_id = c.id
  54. INNER JOIN campaign_type ct ON c.campaign_type_id = ct.id
  55. INNER JOIN job_type jt ON j.job_type_id = jt.id
  56. WHERE j.id = :id',
  57. ['id' => $id]
  58. );
  59. }
  60. /** Used after INSERT to recover the generated id for audit logging. */
  61. public function findLatestByCampaignAndType(int $campaignId, int $jobTypeId): ?array
  62. {
  63. return $this->database->first(
  64. 'SELECT TOP (1) * FROM job
  65. WHERE campaign_id = :campaign_id AND job_type_id = :job_type_id
  66. ORDER BY id DESC',
  67. ['campaign_id' => $campaignId, 'job_type_id' => $jobTypeId]
  68. );
  69. }
  70. public function create(Job $job): bool
  71. {
  72. return $this->database->execute(
  73. 'INSERT INTO job (campaign_id, job_type_id, attribute_values)
  74. VALUES (:campaign_id, :job_type_id, :attribute_values)',
  75. [
  76. 'campaign_id' => $job->campaignId,
  77. 'job_type_id' => $job->jobTypeId,
  78. 'attribute_values' => json_encode($job->attributeValues, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE),
  79. ]
  80. );
  81. }
  82. public function update(Job $job): bool
  83. {
  84. return $this->database->execute(
  85. 'UPDATE job
  86. SET campaign_id = :campaign_id,
  87. job_type_id = :job_type_id,
  88. attribute_values = :attribute_values,
  89. updated_at = CURRENT_TIMESTAMP
  90. WHERE id = :id',
  91. [
  92. 'campaign_id' => $job->campaignId,
  93. 'job_type_id' => $job->jobTypeId,
  94. 'attribute_values' => json_encode($job->attributeValues, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE),
  95. 'id' => $job->id,
  96. ]
  97. );
  98. }
  99. }

Powered by TurnKey Linux.