application/controllers/Common.php
/* Function for accept or decline tribe invitation */
Function for accept or decline tribe invitation
Function for accept or decline tribe invitation
public function accept_decline_invitation_post(){
    	$post_data = $this->post();
    	$userId = $post_data['userId'];
    	$searchId = $post_data['searchId'];
    	$status = $post_data['status'];
		$this->form_validation->set_data($post_data);
		$this->form_validation->set_error_delimiters('', '');
		$this->form_validation->set_rules('userId','User Id','required|numeric|callback_user_check');	
		$this->form_validation->set_rules('searchId','Search criteria id','required|numeric|callback_search_criteria_check');
		$this->form_validation->set_rules('status','Status','required');	
		if ($this->form_validation->run() === false) {
    			$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => validation_errors(),'Result'=>''), 400);    		
		}else{
			$accept_decline_invitation = $this->Common_model->accept_decline_invitation($post_data);
			$tribe_users_device_tokens = $accept_decline_invitation[1];	
			if($accept_decline_invitation[0]){
				ob_start();
                $response = array(
                    'ResponseCode' => 1,
                    'ResponseMessage' => 'SUCCESS', 
                    'Comments' => $_POST['message_invite'],
                    'Result' =>$accept_decline_invitation[0],
                    'Status' =>200
                 );
                echo json_encode($response); 
                $size = ob_get_length();
                header("Content-Encoding: none");
                header("Content-Length: {$size}");
                header("Connection: close");
                ob_end_flush();
                ob_flush();
                flush();
				$user_serach_info = $this->Common_model->get_user_serach_info($searchId);
				if($user_serach_info){
					$login_user_info = $this->Common_model->login_user_info($userId);
					if($login_user_info){
						$user_name = $login_user_info[0]['firstName'];
					}else{
						$user_name = "";
					}
					$device_token = $user_serach_info[0]['deviceToken'];
					$searchName = $user_serach_info[0]['searchName'];
					if(sizeof($tribe_users_device_tokens)>0){
						$tribeDeviceToken = ARRAY();	
						foreach ($tribe_users_device_tokens as $row) {
							if($row["deviceToken"]){
								$tribeDeviceToken[] = $row["deviceToken"];
							}							
						}
						if($status == 'accept')
						{
							$message = $this->config->item('notification_for_accept_invitation');
							$category = "CATEGORY_ACCEPT";
							$message_to_push = str_replace("name", $user_name, $message[0]);						
							$message_to_push_event = str_replace("searchName", $searchName, $message_to_push);
							$message_to_push_notification = $message_to_push_event;
							$payload = json_encode([
								'aps' => [
									'alert' => $message_to_push_notification,
									'sound' => 'cat.caf',
									'badge' => 1,
									'content-available' => 1,
									'category' => $category
								],
								"push_type"=> $message[1],
								"userId"=> $userId,
								"searchId"=> $searchId,
								"status"=> $status
							]);	
							$this->send_multiple_user_notification_ios($tribeDeviceToken, $payload);
						}						
					}
					if($status == 'decline')
					{
						$message = $this->config->item('notification_for_decline_invitation');
						$category = "CATEGORY_DECLINE";
						$message_to_push = str_replace("name", $user_name, $message[0]);						
						$message_to_push_event = str_replace("searchName", $searchName, $message_to_push);
						$message_to_push_notification = $message_to_push_event;
						$payload = json_encode([
							'aps' => [
								'alert' => $message_to_push_notification,
								'sound' => 'cat.caf',
								'badge' => 1,
								'content-available' => 1,
								'category' => $category
							],
							"push_type"=> $message[1],
							"userId"=> $userId,
							"searchId"=> $searchId,
							"status"=> $status
						]);	
						$this->send_notification_ios($device_token, $payload);
					}
				}
			}else{
				$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => 'We are experiencing some technical difficulties, please try again.','Result'=>'We are experiencing some technical difficulties, please try again.'), 400);
			}
		}
    }
public function accept_decline_invitation_post ( ) { $ post_data = $ this -> post ( ) ; $ userId = $ post_data [ 'userId' ] ; $ searchId = $ post_data [ 'searchId' ] ; $ status = $ post_data [ 'status' ] ; $ this -> form_validation -> set_data ( $ post_data ) ; $ this -> form_validation -> set_error_delimiters ( '' , '' ) ; $ this -> form_validation -> set_rules ( 'userId' , 'User Id' , 'required|numeric|callback_user_check' ) ; $ this -> form_validation -> set_rules ( 'searchId' , 'Search criteria id' , 'required|numeric|callback_search_criteria_check' ) ; $ this -> form_validation -> set_rules ( 'status' , 'Status' , 'required' ) ; if ( $ this -> form_validation -> run ( ) === false ) { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => validation_errors ( ) , 'Result' => '' ) , 400 ) ; } else { $ accept_decline_invitation = $ this -> Common_model -> accept_decline_invitation ( $ post_data ) ; $ tribe_users_device_tokens = $ accept_decline_invitation [ 1 ] ; if ( $ accept_decline_invitation [ 0 ] ) { ob_start ( ) ; $ response = array ( 'ResponseCode' => 1 , 'ResponseMessage' => 'SUCCESS' , 'Comments' => $ _POST [ 'message_invite' ] , 'Result' => $ accept_decline_invitation [ 0 ] , 'Status' => 200 ) ; echo json_encode ( $ response ) ; $ size = ob_get_length ( ) ; header ( " Content-Encoding: none " ) ; header ( " Content-Length:  { $ size } " ) ; header ( " Connection: close " ) ; ob_end_flush ( ) ; ob_flush ( ) ; flush ( ) ; $ user_serach_info = $ this -> Common_model -> get_user_serach_info ( $ searchId ) ; if ( $ user_serach_info ) { $ login_user_info = $ this -> Common_model -> login_user_info ( $ userId ) ; if ( $ login_user_info ) { $ user_name = $ login_user_info [ 0 ] [ 'firstName' ] ; } else { $ user_name = " " ; } $ device_token = $ user_serach_info [ 0 ] [ 'deviceToken' ] ; $ searchName = $ user_serach_info [ 0 ] [ 'searchName' ] ; if ( sizeof ( $ tribe_users_device_tokens ) > 0 ) { $ tribeDeviceToken = ARRAY ( ) ; foreach ( $ tribe_users_device_tokens as $ row ) { if ( $ row [ " deviceToken " ] ) { $ tribeDeviceToken [ ] = $ row [ " deviceToken " ] ; } } if ( $ status == 'accept' ) { $ message = $ this -> config -> item ( 'notification_for_accept_invitation' ) ; $ category = " CATEGORY_ACCEPT " ; $ message_to_push = str_replace ( " name " , $ user_name , $ message [ 0 ] ) ; $ message_to_push_event = str_replace ( " searchName " , $ searchName , $ message_to_push ) ; $ message_to_push_notification = $ message_to_push_event ; $ payload = json_encode ( [ 'aps' => [ 'alert' => $ message_to_push_notification , 'sound' => 'cat.caf' , 'badge' => 1 , 'content-available' => 1 , 'category' => $ category ] , " push_type " => $ message [ 1 ] , " userId " => $ userId , " searchId " => $ searchId , " status " => $ status ] ) ; $ this -> send_multiple_user_notification_ios ( $ tribeDeviceToken , $ payload ) ; } } if ( $ status == 'decline' ) { $ message = $ this -> config -> item ( 'notification_for_decline_invitation' ) ; $ category = " CATEGORY_DECLINE " ; $ message_to_push = str_replace ( " name " , $ user_name , $ message [ 0 ] ) ; $ message_to_push_event = str_replace ( " searchName " , $ searchName , $ message_to_push ) ; $ message_to_push_notification = $ message_to_push_event ; $ payload = json_encode ( [ 'aps' => [ 'alert' => $ message_to_push_notification , 'sound' => 'cat.caf' , 'badge' => 1 , 'content-available' => 1 , 'category' => $ category ] , " push_type " => $ message [ 1 ] , " userId " => $ userId , " searchId " => $ searchId , " status " => $ status ] ) ; $ this -> send_notification_ios ( $ device_token , $ payload ) ; } } } else { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => 'We are experiencing some technical difficulties, please try again.' , 'Result' => 'We are experiencing some technical difficulties, please try again.' ) , 400 ) ; } } }
Function for accept or decline tribe invitation
Function for accept or decline tribe invitation
//print_r($post_data);exit(); //print_r($accept_decline_invitation);exit(); // Get the size of the output. // Disable compression (in case content length is compressed). // Set the content length of the response. // Close the connection. // Flush all output. /* get the user info and search criteria information for send notification to search owner */ //print_r($user_serach_info);exit(); /*Get the device tokens of tribe members for sending push */ //$tribe_users_device_tokens = $this->Common_model->tribe_users_device_tokens($post_data); //print_r($tribe_users_device_tokens);exit(); //send notification //print_r($tribeDeviceToken);exit(); //print_r($payload);exit(); //$this->push_notification($tribeDeviceToken, $payload); //print_r($device_token);exit(); // $this->response(array('ResponseCode' => 1, 'ResponseMessage' => 'SUCCESS', 'Comments' => $_POST['message_invite'],'Result'=>$accept_decline_invitation), 200);