EVOLUTION-NINJA
Edit File: Notification.php
<?php namespace App\Controllers\flowD; use App\Controllers\BaseController; use CodeIgniter\RESTful\ResourceController; use CodeIgniter\API\ResponseTrait; use App\Models\RegisterUserModel; use App\Models\NotificationModel; use App\Models\NotificationModel_All; class Notification extends BaseController { use ResponseTrait; public function __construct() { helper(['form','url']); } public function Notification() { $db = \Config\Database::connect(); $dr_id = session()->get('dr_id'); $builder = $db->table('notification_table'); $builder -> select('notification_table.*,notification_all.notify_id,notification_all.user_id_del,notification_table.time'); $builder->join('register_user', 'register_user.id = notification_table.user_id'); $builder->join('notification_all', 'notification_all.notify_id = notification_table.id','left'); $query = $builder->where('user_id',$dr_id); $query = $builder->orderBy('id','DESC'); $query = $builder->get(); $details = $query->getResult(); //--------// $builder1 = $db->table('notification_table'); $builder1 -> select('notification_table.*,notification_all.notify_id,notification_all.user_id_del,notification_table.time'); //$builder1->join('register_user', 'register_user.id = notification_table.user_id'); $builder1->join('notification_all', 'notification_all.notify_id = notification_table.id','left'); $query1 = $builder1->where('sending_to','All'); $query1 = $builder1->orderBy('id','DESC'); $query1 = $builder1->get(); $details1 = $query1->getResult(); //print_r($details1);die(); $data['comments'] = $details; $data['comments1'] = $details1; return view('flowD/notify_v',$data); } public function delete_notify() { $db = \Config\Database::connect(); $id = $this->request->getVar('id'); $model = new NotificationModel(); $model->select('*'); $data['val'] = $model->where('id',$id)->first(); $sending_to = $data['val']['sending_to']; if($sending_to != 'All'){ $builder = $db->table('notification_table'); $builder->where('id', $id); $del = $builder->delete(); } else{ $user_id = session()->get('dr_id'); $details = array( 'user_id_del'=>$user_id, 'notify_id'=>$id ); $add_note = new NotificationModel_All(); $add_note->save($details); $del = $add_note->insertID(); } if($del){ return json_encode(array( 'result' =>1, 'message' => 'Deletion Is Successful' )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Error', // 'data' => $details )); } } function Send_Notification(){ $dr_id = session()->get('dr_id'); if($dr_id){ return view('flowD/add_notification_v'); } else{ return view('login'); } } function Send_Notification_roles(){ $dr_id = session()->get('dr_id'); if($dr_id){ return view('flowD/add_notification_roles_v'); } else{ return view('login'); } } public function add_notification() { $title = $this->request->getVar('title_add'); $message = $this->request->getVar('message'); $date = date("Y-m-d"); date_default_timezone_set("Asia/Calcutta"); //India time (GMT+5:30) $time = date('H:i:s'); $details = array( //'user_id'=>$user_id, 'type'=>$title, 'message'=>$message, 'sending_to'=>"All", 'status'=>'active', 'created_at'=>$date, 'time'=> $time ); $add_note = new NotificationModel(); $add_note->save($details); $insertedID = $add_note->insertID(); if($insertedID){ return json_encode(array( 'result' => 1, 'message' => 'Notification Added successfully ' )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Something went wrong.....' )); } } public function add_notification_roles() { $title = $this->request->getVar('title_add'); $role = $this->request->getVar('role'); $message = $this->request->getVar('message'); $date = date("Y-m-d"); date_default_timezone_set("Asia/Calcutta"); //India time (GMT+5:30) $time = date('H:i:s'); // print_r($_POST); $model5 = new RegisterUserModel(); $model5->where('role_id',$role); $model5->select('id'); $details2 = $model5->get()->getResultArray(); foreach($details2 as $key=>$val){ $details = array( 'user_id'=>$val['id'], 'type'=>$title, 'message'=>$message, //'sending_to'=>"All", 'status'=>'active', 'created_at'=>$date, 'time'=> $time ); $add_note = new NotificationModel(); $add_note->save($details); $insertedID = $add_note->insertID(); } if($insertedID){ return json_encode(array( 'result' => 1, 'message' => 'Notification Added successfully ' )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Something went wrong.....' )); } } // public function Add_Notification() // { // $user_id = '525'; // $title = 'Testing'; // $message = 'This is a test Notification'; // $date = date("Y-m-d"); // $details = array( // //'user_id'=>$user_id, // 'type'=>$title, // 'message'=>$message, // 'sending_to'=>"All", // 'status'=>'active', // 'created_at'=>$date // ); // $add_note = new NotificationModel(); // $add_note->save($details); // $insertedID = $add_note->insertID(); // } public function Notification_header() { $db = \Config\Database::connect(); $dr_id = session()->get('dr_id'); $builder = $db->table('notification_table'); $builder -> select('notification_table.*'); $builder->join('register_user', 'register_user.id = notification_table.user_id'); $query = $builder->where('user_id',$dr_id); $query = $builder->get(); $details = $query->getResult(); $builder1 = $db->table('notification_table'); $builder1 -> select('notification_table.*,notification_all.notify_id,notification_all.user_id_del'); //$builder1->join('register_user', 'register_user.id = notification_table.user_id'); $builder1->join('notification_all', 'notification_all.notify_id = notification_table.id','left'); $query1 = $builder1->where('sending_to','All'); $query1 = $builder1->orderBy('id','DESC'); $query1 = $builder1->get(); $details1 = $query1->getResult(); $data['comments'] = $details; $data['comments1'] = $details1; // print_r($details);die(); if($details){ return json_encode(array( 'result' =>1, 'message' => 'Successful', 'comments' => $details, 'comments1' => $details1, )); } else if($details1){ return json_encode(array( 'result' =>1, 'message' => 'Successful', 'comments' => $details, 'comments1' => $details1, )); } else{ return json_encode(array( 'result' => 0, 'message' => 'Error', // 'data' => $details )); } } public function catagory_view(){ $db = \Config\Database::connect(); return view('flowD/category_one'); } } ?>