application/models/mobile_api/Common_model.php
/* function for acept or decline invitation */
function for acept or decline invitation
function for acept or decline invitation
public function accept_decline_invitation($post_data){        
        $userId =  $post_data['userId'];
        $searchId =  $post_data['searchId'];
        $status =  $post_data['status'];
        $tribe_data = array();
        $data  = array('touserId'=>$userId,
                        'searchId'=>$searchId,                       
                       'status' =>$status
                       );
        if($status == 'accept')
        {            
            $sql = "SELECT * FROM tribe WHERE touserId = $userId AND searchId = $searchId AND (status = 'decline' OR status = '' OR status IS NULL)";
            $record = $this->db->query($sql);           
            if($record->num_rows()>0)
            {  
                $this->db->where('touserId',$userId);
                $this->db->where('searchId',$searchId);
                $this->db->update('tribe',$data);
                if($this->db->affected_rows()>0){
                    $_POST['message_invite'] = 'Invitation accepted successfully';
                    $is_update = true;
                    $sql = "SELECT u.userId,u.firstName,u.email,u.deviceToken,u.deleteFlag  
                            FROM users u where (u.userId in (SELECT t.touserId FROM tribe t where t.searchId=$searchId AND t.touserId !=$userId AND t.status = 'accept' AND t.deleteFlag !=1 )
                            OR u.userId in (SELECT t.fromuserId FROM tribe t where t.searchId=$searchId AND t.fromuserId!=$userId)) AND u.deleteFlag !=1";
                    $result = $this->db->query($sql);           
                    if($result->num_rows() > 0)
                    {
                        $is_update = true;
                        $tribe_data = $result->result_array();
                        return array($is_update,$tribe_data);
                    }
                    return array($is_update,$tribe_data);
                }else{
                    $is_update = false;
                    return array($is_update,$tribe_data);
                }
            }else{
                    $is_update = false;
                    return array($is_update,$tribe_data);
                }            
        }
        if($status == 'decline')
        {  
            $sql = "SELECT * FROM tribe WHERE touserId = $userId AND searchId = $searchId AND (status = 'accept' OR status = '' OR status IS NULL)";
            $record = $this->db->query($sql);           
            if($record->num_rows() > 0)
            {  
                $this->db->where('touserId',$userId);
                $this->db->where('searchId',$searchId);
                $this->db->update('tribe',$data);
                if($this->db->affected_rows()>0){
                    $_POST['message_invite'] = 'Invitation declined successfully';
                    $is_update = true;                        
                    return array($is_update,$tribe_data);
                }else{
                    $is_update = false;                        
                    return array($is_update,$tribe_data);
                }
            }else{
                    $is_update = false;                        
                    return array($is_update,$tribe_data);
                }            
        }
    }
public function accept_decline_invitation ( $ post_data ) { $ userId = $ post_data [ 'userId' ] ; $ searchId = $ post_data [ 'searchId' ] ; $ status = $ post_data [ 'status' ] ; $ tribe_data = array ( ) ; $ data = array ( 'touserId' => $ userId , 'searchId' => $ searchId , 'status' => $ status ) ; if ( $ status == 'accept' ) { $ sql = " SELECT * FROM tribe WHERE touserId =  $ userId  AND searchId =  $ searchId  AND (status = 'decline' OR status = '' OR status IS NULL) " ; $ record = $ this -> db -> query ( $ sql ) ; if ( $ record -> num_rows ( ) > 0 ) { $ this -> db -> where ( 'touserId' , $ userId ) ; $ this -> db -> where ( 'searchId' , $ searchId ) ; $ this -> db -> update ( 'tribe' , $ data ) ; if ( $ this -> db -> affected_rows ( ) > 0 ) { $ _POST [ 'message_invite' ] = 'Invitation accepted successfully' ; $ is_update = true ; $ sql = " SELECT u.userId,u.firstName,u.email,u.deviceToken,u.deleteFlag  
                            FROM users u where (u.userId in (SELECT t.touserId FROM tribe t where t.searchId= $ searchId  AND t.touserId != $ userId  AND t.status = 'accept' AND t.deleteFlag !=1 )
                            OR u.userId in (SELECT t.fromuserId FROM tribe t where t.searchId= $ searchId  AND t.fromuserId!= $ userId )) AND u.deleteFlag !=1 " ; $ result = $ this -> db -> query ( $ sql ) ; if ( $ result -> num_rows ( ) > 0 ) { $ is_update = true ; $ tribe_data = $ result -> result_array ( ) ; return array ( $ is_update , $ tribe_data ) ; } return array ( $ is_update , $ tribe_data ) ; } else { $ is_update = false ; return array ( $ is_update , $ tribe_data ) ; } } else { $ is_update = false ; return array ( $ is_update , $ tribe_data ) ; } } if ( $ status == 'decline' ) { $ sql = " SELECT * FROM tribe WHERE touserId =  $ userId  AND searchId =  $ searchId  AND (status = 'accept' OR status = '' OR status IS NULL) " ; $ record = $ this -> db -> query ( $ sql ) ; if ( $ record -> num_rows ( ) > 0 ) { $ this -> db -> where ( 'touserId' , $ userId ) ; $ this -> db -> where ( 'searchId' , $ searchId ) ; $ this -> db -> update ( 'tribe' , $ data ) ; if ( $ this -> db -> affected_rows ( ) > 0 ) { $ _POST [ 'message_invite' ] = 'Invitation declined successfully' ; $ is_update = true ; return array ( $ is_update , $ tribe_data ) ; } else { $ is_update = false ; return array ( $ is_update , $ tribe_data ) ; } } else { $ is_update = false ; return array ( $ is_update , $ tribe_data ) ; } } }
function for acept or decline invitation
function for acept or decline invitation
//echo $sql;exit(); //return true; //return false; //return false;