Advertisement
abdurahman_argoebie

Untitled

Oct 14th, 2024 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. public function create_broadcast_post() // CREATE
  2. {
  3. date_default_timezone_set('Asia/Jakarta');
  4. // $date = date("Y-m-d");
  5. // $type_user = $this->post('type_user');
  6. $createdAt = date("Y-m-d H:i:s");
  7. $dateTime = new DateTime();
  8. $id_broadcast = $dateTime->getTimestamp();
  9. $id_event = $this->post('id_event');
  10. $url = $this->post('url');
  11. $title = $this->post('title');
  12. $content = $this->post('description');
  13. $description = $this->post('desription');
  14. $schedule_at = $this->post('schedule_at');
  15. $id_city = $this->post('id_city');
  16. $id_group = $this->post('id_group');
  17.  
  18. if ($status == 'queue') {
  19. $additional['schedule'] = 'yes';
  20. $additional['schedule_at'] = $schedule_at;
  21. $createdAt = $schedule_at;
  22. } else $additional['schedule'] = 'no';
  23.  
  24. $additional_data = json_encode($additional);
  25.  
  26. $where['id_event'] = $id_event;
  27.  
  28. $id_group = $this->post('id_group');
  29. //if (!empty($id_group)) $where['id_group'] = $id_group;
  30.  
  31. //buatkan logika query yang semua user yang join di id event pada database system_expo_queue_broadcast yang di kirim dan id city yang dikirim
  32. $this->db->select('id_user');
  33. $this->db->from('system_expo_queue_broadcast');
  34. $this->db->where('system_expo_queue_broadcast.id_event', 1); // Tambahkan nama tabel di sini
  35. $this->db->where('system_expo_queue_broadcast.id_city', 1);
  36. /*$this->db->where('system_expo_queue_broadcast.id_event', $id_event); // Tambahkan nama tabel di sini
  37. $this->db->where('system_expo_queue_broadcast.id_city', $id_city); // Nama tabel juga ditambahkan di sini */
  38.  
  39. // if (!empty($id_group)) {
  40. // $this->db->join('system_group', 'system_expo_queue_broadcast.id_group = system_group.id_group', 'inner');
  41. // $this->db->where('system_group.id_group', $id_group);
  42. // $this->db->where('system_group.id_event', $id_event); // Ambil dari system_group untuk id_event di sini
  43. // }
  44.  
  45. $query = $this->db->get();
  46. $data_recipient = $query->result(); // Data user yang memenuhi kriteria
  47. print_r($data_recipient);
  48. return;
  49.  
  50. //dan bikin query id grup difilter berdasarkan id jadi data yang dikirim user yang ada di group tersebut dan nama dbnya system_group
  51.  
  52. foreach ($data_recipient as &$key) {
  53.  
  54. $notif_queue = [
  55. 'id_broadcast' => $id_broadcast,
  56. 'notif_from' => 1,
  57. 'url' => $url,
  58. 'content' => $content,
  59. 'title' => $title,
  60. 'status' => $status,
  61. 'id_event' => $id_event,
  62. 'id_city' => $id_city,
  63. 'id_group' => $id_group,
  64. 'description' => $description,
  65. 'additional_data' => $additional_data,
  66. ];
  67.  
  68. $this->db->insert("system_expo_queue_broadcast", $notif_queue);
  69. $id = $this->db->insert_id();
  70. $queue = new Masrodjie\Queue\Libraries\Queue();
  71. $queue->push('\App\Jobs\SendQueueNotif', ['id' => $id, 'title' => $title, 'content' => $content, 'id_user' => $key->id_user, 'redirect_url' => $url]);
  72.  
  73. $notif['status'] = 'unread';
  74. $notif['content'] = $content;
  75. $notif['id_user'] = $key->id_user;
  76. $notif['notif_from'] = 1;
  77. $notif['url'] = $url;
  78. $notif['type'] = 'Other';
  79. $notif['id_event'] = $id_event;
  80. $notif['created_at'] = $createdAt;
  81. $notif['title'] = $title;
  82. $notif['description'] = $description;
  83. $notif['additional_data'] = $additional_data;
  84. $this->db->insert("module_notif", $notif);
  85. }
  86.  
  87. $response = [
  88. 'code' => 200,
  89. 'status' => 'success',
  90. 'result' => $data_recipient,
  91. 'message' => 'Broadcast to ' . sizeof($data_recipient) . ' users success !',
  92. ];
  93. $this->response($response, 200);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement