From 026093d21a12a8ad6ea58236c54cf742d82adaa5 Mon Sep 17 00:00:00 2001 From: sanjeev Date: Thu, 24 Feb 2022 20:10:49 +0530 Subject: [PATCH] templated json : ps --- .../Template_Management_Controller.php | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/api/application/controllers/Template_Management_Controller.php b/api/application/controllers/Template_Management_Controller.php index 85da4a29..fb44954d 100644 --- a/api/application/controllers/Template_Management_Controller.php +++ b/api/application/controllers/Template_Management_Controller.php @@ -1089,26 +1089,50 @@ class Template_Management_Controller extends REST_Controller { $status = strtoupper(str_replace(' ', '',$records['form_status'])); $where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1); $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2); - foreach ($json_table as $value) $id_array[] = $value['id']; - if(count($json_table)>0 && $status == "COMPLETED"){ - $this->db->where_in('id',$id_array); - $this->db->set('isactive',0); - $this->db->update(TEMPLATE_JSON_V2); - }else if(count($json_table)>0 && ($status == "DRAFT" || $status == "APPROVED")){ - $this->db->where('is_form_status',"COMPLETED"); - $this->db->where_in('id',$id_array); - $this->db->set('isactive',0); - $this->db->update(TEMPLATE_JSON_V2); + + ### Don't Delete Because First Requirement..... multiple draft mode and multiple approve mode but when completed means inactive the draft json and approve json + // foreach ($json_table as $value) $id_array[] = $value['id']; + // if(count($json_table)>0 && $status == "COMPLETED"){ + // $this->db->where_in('id',$id_array); + // $this->db->set('isactive',0); + // $this->db->update(TEMPLATE_JSON_V2); + // }else if(count($json_table)>0 && ($status == "DRAFT" || $status == "APPROVED")){ + // $this->db->where('is_form_status',"COMPLETED"); + // $this->db->where_in('id',$id_array); + // $this->db->set('isactive',0); + // $this->db->update(TEMPLATE_JSON_V2); + // } + // $json = json_encode($records['json'],true); + // $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status); + // $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); + + if($status == "DRAFT"){ + if(count($json_table)>0 && $status == "COMPLETED"){ + $this->db->where_in('id',$json_table[0]['id']); + $this->db->set('isactive',0); + $this->db->update(TEMPLATE_JSON_V2); + } + //draft means insert + $json = json_encode($records['json'],true); + $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status); + $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); + $msg = "Sucessfully Inserted"; + }else if($status == "APPROVED" || $status == "COMPLETED"){ + //status means update + $json_pk_id = $json_table[0]['id']; + $this->db->where('isactive',1); + $this->db->where('id',$json_pk_id); + $this->db->set('is_form_status',$status); + $this->db->update(TEMPLATE_JSON_V2); + $msg = "Sucessfully Updated"; } - $json = json_encode($records['json'],true); - $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id,'is_form_status'=>$status); - $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); + if($json_pk_id) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['json_id'] = $json_pk_id; - $data['msg'] = "Sucessfully Inserted"; + $data['msg'] = $msg; $this->response($data,REST_Controller::HTTP_OK); } else