Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function get_chat(){
- $chat=$this->input->get('chats');
- $user=$this->ion_auth->user()->row();
- if($chat==NULL || empty($chat) || $chat==''){
- $this->db->where('group_chat','xyxy');
- $this->db->order_by('waktu', 'ASC');
- $get=$this->db->get('chat');
- if($get->num_rows()>0){
- $data1=array();
- $data2=array();
- $data3=array();
- $data4=array();
- $data5=array();
- $no=1;
- foreach ($get->result() as $key) {
- $penentu='';
- if($key->pengirim!==$user->id){
- $penentu='left';
- }else{
- $penentu='right';
- }
- $data1[]=$key->chat;
- $data2[]=$penentu;
- $data3[]=$key->waktu;
- $data4[]=$key->pengirim;
- $data5[]=$key->penerima;
- $no++;
- }
- $data=array(
- 'text' => $data1,
- 'position' => $data2,
- 'waktu' => $data3,
- 'id_pengirim' => $data4,
- 'id_penerima' => $data5,
- 'id_login' => $user->id,
- 'nama' => $user->first_name
- );
- echo json_encode($data);
- }
- }else{
- date_default_timezone_set('Asia/jakarta');
- $user=$this->ion_auth->user()->row();
- $data=array(
- 'waktu' => date('Y-m-d H:m:s'),
- 'pengirim' => $user->first_name=='Abi'? '3':'2',
- 'penerima' => $user->first_name=='Abi'? '2':'3',
- 'chat' => $chat,
- 'group_chat' => 'xyxy'
- );
- $this->db->insert('chat', $data);
- $chat=$this->input->get('chats');
- $this->db->where('chat',$chat);
- $get=$this->db->get('chat');
- $dataa=array();
- foreach ($get->result() as $key) {
- $penentu='';
- if($key->pengirim==$user->id){
- $penentu='left';
- }else{
- $penentu='right';
- }
- $dataa['text']=$key->chat;
- $dataa['waktu']=$key->waktu;
- $dataa['position']= $penentu;
- }
- echo json_encode($dataa);
- }
- }
Add Comment
Please, Sign In to add comment