From f431d0571fc4277bd20761c1c0723bc9b1c9ec36 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Wed, 20 Apr 2022 17:06:50 +0530 Subject: [PATCH] PD officer List for notification : ps --- api/application/config/routes.php | 5 +- api/application/controllers/PD_Controller.php | 97 ++++++++++++++++++- api/application/helpers/pdalerts_helper.php | 30 ++++++ .../helpers/push_notification_helper.php | 2 +- 4 files changed, 127 insertions(+), 7 deletions(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index fda37078..a77fd306 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -359,4 +359,7 @@ $route['optimizeImages/(:num)'] = 'PD_Controller/optimizeImages'; $route['downloadSMCExcelFile/(:num)'] = 'PD_Controller/downloadSMCExcelFile'; $route['compareFaces'] = 'Test/compareFaces'; -$route['googleSheet'] = 'Data_Dump_Controller/googleSheet'; \ No newline at end of file +$route['googleSheet'] = 'Data_Dump_Controller/googleSheet'; + +$route['getListPDOfficersForNotification'] = 'PD_Controller/getListPDOfficersForNotification'; +$route['sendNotificationToOfficers'] = 'PD_Controller/sendNotificationToOfficers'; \ No newline at end of file diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index d163c127..ead4e1ed 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -1826,7 +1826,7 @@ public function assignPDTempalate($data) *GET List of PD officers for PD edit/view page for manual allocation *@param pd */ - public function getListPDOfficers_post() + public function getListPDOfficers_post() { $pdid = $this->post('pdid'); @@ -11761,9 +11761,96 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post() $this->response($data,REST_Controller::HTTP_OK); } } - + + public function getListPDOfficersForNotification_get(){ + + $fields = array('fk_user_id'); + $where_condition_array = array('isactive' => 1); + $list_of_pd_officers = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDOFFICIERSDETAILS); + if(!empty($list_of_pd_officers)){ + foreach($list_of_pd_officers as $key => $pdofficer) + { + $this->db->SELECT('USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILE.profilepic,USERPROFILE.mobile_no,USERPROFILEROLES.user_role,ROLES.role_name'); + $this->db->FROM(USERPROFILE.' as USERPROFILE'); + $this->db->JOIN(USERPROFILEROLES.' as USERPROFILEROLES','USERPROFILE.userid = USERPROFILEROLES.fk_userid'); + $this->db->JOIN(ROLES.' as ROLES','USERPROFILEROLES.user_role = ROLES.role_id'); + $this->db->WHERE('USERPROFILE.userid',$pdofficer['fk_user_id']); + $names = $this->db->GET()->result_array(); + if(count($names)){ + $list_of_pd_officers[$key]['first_name'] = $names[0]['first_name']; + $list_of_pd_officers[$key]['last_name'] = $names[0]['last_name']; + $list_of_pd_officers[$key]['mobile_no'] = $names[0]['mobile_no']; + $list_of_pd_officers[$key]['user_role'] = $names[0]['user_role']; + $list_of_pd_officers[$key]['role_name'] = $names[0]['role_name']; + } + } + } + // Get Central PD Officers List + $central_pd_officers = array(); + + $this->db->SELECT('USERPROFILE.userid as fk_user_id,USERPROFILE.first_name,USERPROFILE.last_name,USERPROFILE.mobile_no,USERPROFILEROLES.user_role,ROLES.role_name'); + $this->db->FROM(USERPROFILE.' as USERPROFILE'); + $this->db->JOIN(USERPROFILEROLES.' as USERPROFILEROLES','USERPROFILE.userid = USERPROFILEROLES.fk_userid'); + $this->db->JOIN(ROLES.' as ROLES','USERPROFILEROLES.user_role = ROLES.role_id'); + $this->db->WHERE('ROLES.role_id',2); + $central_pd_officers = $this->db->GET()->result_array(); + + + if(!empty($list_of_pd_officers) && !empty($central_pd_officers)){ + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'PD-Officer and Central PD-Officer Records Available!'; + $data['records'] = array('pdofficers' => $list_of_pd_officers,'centralpdofficers' => $central_pd_officers); + + }else if(empty($list_of_pd_officers) && !empty($central_pd_officers)){ + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'PD-Officer Records Not Found!'; + $data['records'] = array('pdofficers' => array(),'centralpdofficers' => $central_pd_officers); + }else if(empty($central_pd_officers) && !empty($list_of_pd_officers)){ + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'Central PD-Officer Records Not Found!'; + $data['records'] = array('pdofficers' => $list_of_pd_officers,'centralpdofficers' => array()); + }else{ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Officers Records Not Found!'; + } + $this->response($data,REST_Controller::HTTP_OK); + } + public function sendNotificationToOfficers_post(){ + $records = $this->post('records'); + $users = $records['user_id']; // alluser,multiuser,particularuser + $msg = $records['msg']; // alluser,multiuser,particularuser + // print_r($this->post());die(); + + if(!empty($msg) && !empty($users)){ + // $fields = array('notification_token_id','mob_token'); + // $where_condition_array = array(); + // $tokens = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,USERNOTIFICATIONTOKENS); + // pd offier's mobile token get form notification table + PDALERTS::sendNotificationToOfficers($records); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'Notification Sended'; + }else{ + if(empty($msg)){ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Message Data Not Found!'; + }else if(empty($users)){ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Users Not Found!'; + }else{ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Records Not Found!'; + } + } + $this->response($data,REST_Controller::HTTP_OK); + } -} - - +} \ No newline at end of file diff --git a/api/application/helpers/pdalerts_helper.php b/api/application/helpers/pdalerts_helper.php index 5cb0eef7..adb5d3cc 100644 --- a/api/application/helpers/pdalerts_helper.php +++ b/api/application/helpers/pdalerts_helper.php @@ -842,6 +842,36 @@ class PDALERTS } $mail->SmtpClose(); } + + public static function sendNotificationToOfficers($records) + { + $users = $records['user_id']; // alluser,multiuser,particularuser + $msg = $records['msg']; // msg + $CI =&get_instance(); + $CI->load->helper('push_notification'); + // notification_token_id, fk_user_id, web_token, mob_token, createdon, updatedon + $CI->db->SELECT("USERNOTIFICATIONTOKENS.notification_token_id,USERNOTIFICATIONTOKENS.fk_user_id,USERNOTIFICATIONTOKENS.mob_token"); + $CI->db->FROM(USERNOTIFICATIONTOKENS." as USERNOTIFICATIONTOKENS"); + $CI->db->JOIN(USERPROFILEROLES.' as USERPROFILEROLES','USERPROFILEROLES.fk_userid = USERNOTIFICATIONTOKENS.fk_user_id'); + // $CI->db->WHERE('ROLES.role_id',2); + if(is_array($users) && count($users)){ + if($users[0] != 0){ + $CI->db->WHERE_IN('USERNOTIFICATIONTOKENS.fk_user_id ',$users); + }else{ + $CI->db->WHERE_IN("USERPROFILEROLES.user_role",[2,22]);//pd officer roles only + // $CI->db->WHERE_IN("USERPROFILEROLES.user_role",[2,5,22]); + } + } + $CI->db->WHERE('USERNOTIFICATIONTOKENS.mob_token != ""'); + $notification_details = $CI->db->GET()->result_array(); + + $additional_data_for_logs['to_whom'] = 'PDOFFICERS'; + $web_token = ""; + for($i=0;$iinfo("PUSH NOTIFICATION ",array('firebase_result' => $result,'additional_data' => $additional_data,'token_type' => ($type == 1? 'WEB' : 'MOB'),'token' => $token)); + MYLOG::logFunction(null,(isset($additional_data['pd_id'])?$additional_data['pd_id']:""))->info("PUSH NOTIFICATION ",array('firebase_result' => $result,'additional_data' => $additional_data,'token_type' => ($type == 1? 'WEB' : 'MOB'),'token' => $token)); } }