Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function create_broadcast_post() // CREATE
- {
- date_default_timezone_set('Asia/Jakarta');
- // $date = date("Y-m-d");
- // $type_user = $this->post('type_user');
- $createdAt = date("Y-m-d H:i:s");
- $dateTime = new DateTime();
- $id_broadcast = $dateTime->getTimestamp();
- $id_event = $this->post('id_event');
- $url = $this->post('url');
- $title = $this->post('title');
- $content = $this->post('description');
- $description = $this->post('desription');
- $schedule_at = $this->post('schedule_at');
- $id_city = $this->post('id_city');
- $id_group = $this->post('id_group');
- if ($status == 'queue') {
- $additional['schedule'] = 'yes';
- $additional['schedule_at'] = $schedule_at;
- $createdAt = $schedule_at;
- } else $additional['schedule'] = 'no';
- $additional_data = json_encode($additional);
- $where['id_event'] = $id_event;
- $id_group = $this->post('id_group');
- //if (!empty($id_group)) $where['id_group'] = $id_group;
- //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
- $this->db->select('id_user');
- $this->db->from('system_expo_queue_broadcast');
- $this->db->where('system_expo_queue_broadcast.id_event', 1); // Tambahkan nama tabel di sini
- $this->db->where('system_expo_queue_broadcast.id_city', 1);
- /*$this->db->where('system_expo_queue_broadcast.id_event', $id_event); // Tambahkan nama tabel di sini
- $this->db->where('system_expo_queue_broadcast.id_city', $id_city); // Nama tabel juga ditambahkan di sini */
- // if (!empty($id_group)) {
- // $this->db->join('system_group', 'system_expo_queue_broadcast.id_group = system_group.id_group', 'inner');
- // $this->db->where('system_group.id_group', $id_group);
- // $this->db->where('system_group.id_event', $id_event); // Ambil dari system_group untuk id_event di sini
- // }
- $query = $this->db->get();
- $data_recipient = $query->result(); // Data user yang memenuhi kriteria
- print_r($data_recipient);
- return;
- //dan bikin query id grup difilter berdasarkan id jadi data yang dikirim user yang ada di group tersebut dan nama dbnya system_group
- foreach ($data_recipient as &$key) {
- $notif_queue = [
- 'id_broadcast' => $id_broadcast,
- 'notif_from' => 1,
- 'url' => $url,
- 'content' => $content,
- 'title' => $title,
- 'status' => $status,
- 'id_event' => $id_event,
- 'id_city' => $id_city,
- 'id_group' => $id_group,
- 'description' => $description,
- 'additional_data' => $additional_data,
- ];
- $this->db->insert("system_expo_queue_broadcast", $notif_queue);
- $id = $this->db->insert_id();
- $queue = new Masrodjie\Queue\Libraries\Queue();
- $queue->push('\App\Jobs\SendQueueNotif', ['id' => $id, 'title' => $title, 'content' => $content, 'id_user' => $key->id_user, 'redirect_url' => $url]);
- $notif['status'] = 'unread';
- $notif['content'] = $content;
- $notif['id_user'] = $key->id_user;
- $notif['notif_from'] = 1;
- $notif['url'] = $url;
- $notif['type'] = 'Other';
- $notif['id_event'] = $id_event;
- $notif['created_at'] = $createdAt;
- $notif['title'] = $title;
- $notif['description'] = $description;
- $notif['additional_data'] = $additional_data;
- $this->db->insert("module_notif", $notif);
- }
- $response = [
- 'code' => 200,
- 'status' => 'success',
- 'result' => $data_recipient,
- 'message' => 'Broadcast to ' . sizeof($data_recipient) . ' users success !',
- ];
- $this->response($response, 200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement