Sebuahhobi98

error_logic_chat

Mar 21st, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public function get_chat(){
  2. $chat=$this->input->get('chats');
  3. $user=$this->ion_auth->user()->row();
  4. if($chat==NULL || empty($chat) || $chat==''){
  5. $this->db->where('group_chat','xyxy');
  6. $this->db->order_by('waktu', 'ASC');
  7. $get=$this->db->get('chat');
  8. if($get->num_rows()>0){
  9. $data1=array();
  10. $data2=array();
  11. $data3=array();
  12. $data4=array();
  13. $data5=array();
  14. $no=1;
  15. foreach ($get->result() as $key) {
  16. $penentu='';
  17. if($key->pengirim!==$user->id){
  18. $penentu='left';
  19. }else{
  20. $penentu='right';
  21. }
  22.  
  23. $data1[]=$key->chat;
  24. $data2[]=$penentu;
  25. $data3[]=$key->waktu;
  26. $data4[]=$key->pengirim;
  27. $data5[]=$key->penerima;
  28. $no++;
  29. }
  30. $data=array(
  31. 'text' => $data1,
  32. 'position' => $data2,
  33. 'waktu' => $data3,
  34. 'id_pengirim' => $data4,
  35. 'id_penerima' => $data5,
  36. 'id_login' => $user->id,
  37. 'nama' => $user->first_name
  38. );
  39. echo json_encode($data);
  40. }
  41. }else{
  42. date_default_timezone_set('Asia/jakarta');
  43. $user=$this->ion_auth->user()->row();
  44. $data=array(
  45. 'waktu' => date('Y-m-d H:m:s'),
  46. 'pengirim' => $user->first_name=='Abi'? '3':'2',
  47. 'penerima' => $user->first_name=='Abi'? '2':'3',
  48. 'chat' => $chat,
  49. 'group_chat' => 'xyxy'
  50. );
  51. $this->db->insert('chat', $data);
  52.  
  53. $chat=$this->input->get('chats');
  54. $this->db->where('chat',$chat);
  55. $get=$this->db->get('chat');
  56. $dataa=array();
  57. foreach ($get->result() as $key) {
  58. $penentu='';
  59. if($key->pengirim==$user->id){
  60. $penentu='left';
  61. }else{
  62. $penentu='right';
  63. }
  64. $dataa['text']=$key->chat;
  65. $dataa['waktu']=$key->waktu;
  66. $dataa['position']= $penentu;
  67. }
  68. echo json_encode($dataa);
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment