application/controllers/Common.php
/* Add user in my tribe and send notifications to exists users and email to non-existing users */
Add user in my tribe and send notifications to exists users and email to non-existing users
Add user in my tribe and send notifications to exists users and email to non - existing users
public function save_tribe_post(){
    	$post_data = $this->post();
    	$userId = $post_data['userId'];
    	$searchId = $post_data['searchId'];
		$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');
		if ($this->form_validation->run() === false) {
    			$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => validation_errors(),'Result'=>''), 400);    		
		}else{
			$save_tribe = $this->Common_model->save_tribe($post_data);	
			$send_email = false;	
			$tribeMemberCount = 0;
			$get_exists_users = $save_tribe[1];
			$get_not_exist_emails = $save_tribe[2];
			if($save_tribe[0]){
				ob_start();
				$tribeMemberCount = $this->Common_model->count_my_tribe_member($post_data);
				 $response = array('ResponseCode' => 1, 'ResponseMessage' => 'SUCCESS', 'Comments' => $_POST['tribe'],'tribeMemberCount' => $tribeMemberCount,'Result'=>true,'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_info = $this->Common_model->get_user_info($userId,$searchId);
				if($user_info){
					$user_name = $user_info[0]['firstName'];
					$searchName = $user_info[0]['searchName'];
					if(sizeof($get_exists_users)>0)	{
						$deviceToken = ARRAY();
						$users_from_tribe = ARRAY();
						$deleted_users_emails = ARRAY();
						$deleted_users_device_tokens = ARRAY();
						foreach ($get_exists_users as $row) {
							$deviceToken[] = $row["deviceToken"];
							if($row["deleteFlag"] == 0){
								$users_from_tribe[] = $row["deviceToken"];
							}
							if($row["deleteFlag"] == 1){
								$deleted_users_emails[] = $row["email"];
								$deleted_users_device_tokens[] = $row["deviceToken"];
							}
						}
						if(count($users_from_tribe)>0){
							$message = $this->config->item('notification_add_user_in_tribe');
							$message_to_push = str_replace("firstName", $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_INVITATION'
								],
								"push_type"=> $message[1],
								"userId"=> $userId,
								"searchId"=> $searchId
							]);	
							$this->send_multiple_user_notification_ios($users_from_tribe, $payload);
						}
						if(count($deleted_users_emails)>0){						
							if(count($deleted_users_device_tokens)>0){							
								$message = $this->config->item('notification_delete_user_from_tribe');
								$message_to_push = str_replace("firstName", $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_INVITATION'
									],
									"push_type"=> $message[1],
									"userId"=> $userId,
									"searchId"=> $searchId
								]);	
								$file = fopen("test-push-tokens.txt","w");
								$tokens = json_encode($deleted_users_device_tokens);
								fwrite($file,$tokens);
								fclose($file);
								$this->send_multiple_user_notification_ios($deleted_users_device_tokens, $payload);
							}
							$link = "";	
							$status = "deleted";
							$send_email = $this->sendMail($user_name,$searchName,$deleted_users_emails,$link,$status);
						}
					}
					if(sizeof($get_not_exist_emails)>0)	{
						$users_emails = $get_not_exist_emails;
						$link = "https://itunes.apple.com/us/app/urbanco/id1250754314?ls=1&mt=8";
						$status = "added";
						$send_email = $this->sendMail($user_name,$searchName,$users_emails,$link,$status);
					}
				} else {
					$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => 'We are experiencing some technical difficulties, please try again.','Result'=>false), 400);	
				}
			}else{
				$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => 'Fail to make invitation for tribe','Result'=>false), 400);
			}
		}
    }
public function save_tribe_post ( ) { $ post_data = $ this -> post ( ) ; $ userId = $ post_data [ 'userId' ] ; $ searchId = $ post_data [ 'searchId' ] ; $ 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' ) ; if ( $ this -> form_validation -> run ( ) === false ) { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => validation_errors ( ) , 'Result' => '' ) , 400 ) ; } else { $ save_tribe = $ this -> Common_model -> save_tribe ( $ post_data ) ; $ send_email = false ; $ tribeMemberCount = 0 ; $ get_exists_users = $ save_tribe [ 1 ] ; $ get_not_exist_emails = $ save_tribe [ 2 ] ; if ( $ save_tribe [ 0 ] ) { ob_start ( ) ; $ tribeMemberCount = $ this -> Common_model -> count_my_tribe_member ( $ post_data ) ; $ response = array ( 'ResponseCode' => 1 , 'ResponseMessage' => 'SUCCESS' , 'Comments' => $ _POST [ 'tribe' ] , 'tribeMemberCount' => $ tribeMemberCount , 'Result' => true , '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_info = $ this -> Common_model -> get_user_info ( $ userId , $ searchId ) ; if ( $ user_info ) { $ user_name = $ user_info [ 0 ] [ 'firstName' ] ; $ searchName = $ user_info [ 0 ] [ 'searchName' ] ; if ( sizeof ( $ get_exists_users ) > 0 ) { $ deviceToken = ARRAY ( ) ; $ users_from_tribe = ARRAY ( ) ; $ deleted_users_emails = ARRAY ( ) ; $ deleted_users_device_tokens = ARRAY ( ) ; foreach ( $ get_exists_users as $ row ) { $ deviceToken [ ] = $ row [ " deviceToken " ] ; if ( $ row [ " deleteFlag " ] == 0 ) { $ users_from_tribe [ ] = $ row [ " deviceToken " ] ; } if ( $ row [ " deleteFlag " ] == 1 ) { $ deleted_users_emails [ ] = $ row [ " email " ] ; $ deleted_users_device_tokens [ ] = $ row [ " deviceToken " ] ; } } if ( count ( $ users_from_tribe ) > 0 ) { $ message = $ this -> config -> item ( 'notification_add_user_in_tribe' ) ; $ message_to_push = str_replace ( " firstName " , $ 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_INVITATION' ] , " push_type " => $ message [ 1 ] , " userId " => $ userId , " searchId " => $ searchId ] ) ; $ this -> send_multiple_user_notification_ios ( $ users_from_tribe , $ payload ) ; } if ( count ( $ deleted_users_emails ) > 0 ) { if ( count ( $ deleted_users_device_tokens ) > 0 ) { $ message = $ this -> config -> item ( 'notification_delete_user_from_tribe' ) ; $ message_to_push = str_replace ( " firstName " , $ 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_INVITATION' ] , " push_type " => $ message [ 1 ] , " userId " => $ userId , " searchId " => $ searchId ] ) ; $ file = fopen ( " test-push-tokens.txt " , " w " ) ; $ tokens = json_encode ( $ deleted_users_device_tokens ) ; fwrite ( $ file , $ tokens ) ; fclose ( $ file ) ; $ this -> send_multiple_user_notification_ios ( $ deleted_users_device_tokens , $ payload ) ; } $ link = " " ; $ status = " deleted " ; $ send_email = $ this -> sendMail ( $ user_name , $ searchName , $ deleted_users_emails , $ link , $ status ) ; } } if ( sizeof ( $ get_not_exist_emails ) > 0 ) { $ users_emails = $ get_not_exist_emails ; $ link = " https://itunes.apple.com/us/app/urbanco/id1250754314?ls=1&mt=8 " ; $ status = " added " ; $ send_email = $ this -> sendMail ( $ user_name , $ searchName , $ users_emails , $ link , $ status ) ; } } else { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => 'We are experiencing some technical difficulties, please try again.' , 'Result' => false ) , 400 ) ; } } else { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => 'Fail to make invitation for tribe' , 'Result' => false ) , 400 ) ; } } }
Add user in my tribe and send notifications to exists users and email to non-existing users
Add user in my tribe and send notifications to exists users and email to non - existing users
//print_r($save_tribe);exit(); //print_r($get_exists_users);exit(); //echo "saVE";exit(); // Buffer all upcoming output... // Send your response. /* get the count of tribe members who accepted invitation */ // 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. //sleep(60); //$searchId = $save_tribe; /* Get the user information and search criteria info. */ //print_r($user_info);exit; //print_r($user_info);exit(); /* get the users who exists in database and send push notification */ //print_r($get_exists_users);exit(); //send notification //print_r($get_exists_users);exit(); //print_r($row);exit(); //print_r($deleted_users_device_tokens);exit(); /* send notification to existing user */ //print_r($users_from_tribe);exit(); /* Send email to deleted users */ /* send email to non existing users */ /* send notification to existing user for deleted from tribe */ //print_r($payload);exit(); /* get the users who dont exists in database and send email to them for registration */ //$get_not_exist_emails = $this->Common_model->get_not_exist_emails($post_data); //print_r($get_not_exist_emails);exit(); /* send email to non existing users */ //App link to download app /*
					if($send_email){
						$this->response(array('ResponseCode' => 1, 'ResponseMessage' => 'SUCCESS', 'Comments' => 'Invitation for tribe send successfully.','tribeMemberCount' => $tribeMemberCount,'Result'=>$send_email), 200);
					}else{
						$this->response(array('ResponseCode' => 1, 'ResponseMessage' => 'SUCCESS', 'Comments' => $_POST['tribe'],'tribeMemberCount' => $tribeMemberCount,'Result'=>true), 200);
					}*/