PD officer List for notification : ps

This commit is contained in:
VE10-Sanjeev 2022-04-20 17:06:50 +05:30
parent d2e13a6443
commit f431d0571f
4 changed files with 127 additions and 7 deletions

View File

@ -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';
$route['googleSheet'] = 'Data_Dump_Controller/googleSheet';
$route['getListPDOfficersForNotification'] = 'PD_Controller/getListPDOfficersForNotification';
$route['sendNotificationToOfficers'] = 'PD_Controller/sendNotificationToOfficers';

View File

@ -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);
}
}
}

View File

@ -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;$i<count($notification_details);$i++){
$mob_token = $notification_details[$i]['mob_token'] ;
PUSH_NOTIFICATION::sendNotification($web_token,$mob_token,$msg,$additional_data_for_logs);
}
}
}

View File

@ -81,7 +81,7 @@ class PUSH_NOTIFICATION
$result = curl_exec($ch );
curl_close( $ch );
$CI =&get_instance();
MYLOG::logFunction(null,$additional_data['pd_id'])->info("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));
}
}