Commit 3a5034a2 by Jansa Jose

Notification Pagination Fix

parent 1ba1267c
...@@ -5160,6 +5160,7 @@ print_r(date('H:i',$ms));exit();*/ ...@@ -5160,6 +5160,7 @@ print_r(date('H:i',$ms));exit();*/
print json_encode($res); print json_encode($res);
} }
public function get_doctor_notification_list(){ public function get_doctor_notification_list(){
header('Content-type: application/json'); header('Content-type: application/json');
$headers = apache_request_headers(); $headers = apache_request_headers();
...@@ -5171,60 +5172,67 @@ print_r(date('H:i',$ms));exit();*/ ...@@ -5171,60 +5172,67 @@ print_r(date('H:i',$ms));exit();*/
$authtoken = $this->Webservice_model->get_doctorid_frm_authtoken($headers['Auth']); $authtoken = $this->Webservice_model->get_doctorid_frm_authtoken($headers['Auth']);
if(isset($_GET['page']) && strlen(trim($_GET['page']," ")) > 0 ) { if(isset($_GET['page']) && strlen(trim($_GET['page']," ")) > 0 ) {
$currentpage = (int)$_GET['page']; $currentpage = (int)$_GET['page'];
//$currentpage = $currentpage==0 ? $currentpage : $currentpage-1; $currentpage = $currentpage==0 ? $currentpage : $currentpage-1;
$start = $currentpage * $per_page; $start = $currentpage * $per_page;
$page_no = $_GET['page'];
} }
else{ else{
$currentpage = 0; $currentpage = 0;
$start = 0; $start = 0;
$page_no = 0;
} }
$total_data = $this->Webservice_model->get_doctor_notification_list($authtoken->doctor_id,0,0); $notificationResult = $this->Webservice_model->get_doctor_notification_list($authtoken->doctor_id, 0, 0);
$result = $this->Webservice_model->get_doctor_notification_list($authtoken->doctor_id,$start,$per_page); $result = $this->Webservice_model->get_doctor_notification_list($authtoken->doctor_id,$start,$per_page);
$count = $this->Webservice_model->get_doctor_notification_list_unread_count($authtoken->doctor_id); $count = $this->Webservice_model->get_doctor_notification_list_unread_count($authtoken->doctor_id);
if($count){ if($count){
$total_count = $count->count; $unread_count = $count->count;
}else{
$unread_count = 0;
}
if($notificationResult != false){
$total_count = count($notificationResult);
}else{ }else{
$total_count = 0; $total_count = 0;
} }
$notifArray = array();
if($result != false){
$total = count($total_data);
}else{
$total = 0;
}
if($total >= $per_page){
$totalPages = (int)($total / $per_page); $notifArray = array();
} // if($result != false){
else{ // $total = count($result);
$totalPages = 1; // }else{
} // $total = 0;
//print_r($result);exit; // }
if($result != ''){ if($total_count >= $per_page){
foreach (array_slice($result,$start,$per_page) as $key => $value) { $totalPages = (int)($total_count % $per_page ==0
$value->read_status = $value->read_status!=0 ? true : false; ? $total_count / $per_page
array_push($notifArray, $value); :($total_count / $per_page)+1);
} }
else{
$totalPages = 1;
}
//print_r($result);exit;
if($result != ''){
foreach (array_slice($result,$start,$per_page) as $key => $value) {
$value->read_status = $value->read_status!=0 ? true : false;
array_push($notifArray, $value);
} }
}
if($result != false){ if($result != false){
$res = array( $res = array(
'status'=>'success', 'status'=>'success',
'data'=>array('unread_count'=>$total_count,'notifications'=>$notifArray), 'data'=>array('unread_count'=>$unread_count,'notifications'=>$notifArray),
'meta' => array('total_pages' => $totalPages, 'meta' => array('total_pages' => $totalPages,
'total' => $total, 'total' => $total_count,
'current_page' =>$currentpage+1, 'current_page' =>$currentpage+1,
'per_page' => $per_page) 'per_page' => $per_page)
); );
}else{ }else{
$res = array( $res = array(
'status'=>'success', 'status'=>'success',
'data'=>array('unread_count'=>$total_count,'notifications'=>[]), 'data'=>array('unread_count'=>$unread_count,'notifications'=>[]),
'meta' => array('total_pages' => $totalPages, 'meta' => array('total_pages' => $totalPages,
'total' => $total, 'total' => $total_count,
'current_page' =>$currentpage+1, 'current_page' =>$currentpage+1,
'per_page' => $per_page) 'per_page' => $per_page)
); );
...@@ -5247,6 +5255,7 @@ print_r(date('H:i',$ms));exit();*/ ...@@ -5247,6 +5255,7 @@ print_r(date('H:i',$ms));exit();*/
} }
public function set_doctor_notification_status(){ public function set_doctor_notification_status(){
header('Content-type: application/json'); header('Content-type: application/json');
$headers = apache_request_headers(); $headers = apache_request_headers();
......
...@@ -3242,7 +3242,7 @@ class Webservice_model extends CI_Model { ...@@ -3242,7 +3242,7 @@ class Webservice_model extends CI_Model {
//SELECT IIF(Obsolete = 'N' or InStock = 'Y', 1, 0) as Saleable, * FROM Product //SELECT IIF(Obsolete = 'N' or InStock = 'Y', 1, 0) as Saleable, * FROM Product
$this->db->select("read_status,id,type,message"); $this->db->select("read_status,id,type,message");
$this->db->order_by('tbl_doctor_notifications.id','DESC'); $this->db->order_by('tbl_doctor_notifications.id','DESC');
if($start!=0 && $per_page!=0){ if($start!=0 || $per_page!=0){
$this->db->limit($per_page,$start); $this->db->limit($per_page,$start);
} }
$result = $this->db->get_where('tbl_doctor_notifications',array('doctor_id'=>$doctorid))->result(); $result = $this->db->get_where('tbl_doctor_notifications',array('doctor_id'=>$doctorid))->result();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment