application/controllers/Common.php
/* Function for add comment in Shortlisted property */
Function for add comment in Shortlisted property
Function for add comment in Shortlisted property
public function add_comments_post(){
    	$post_data = $this->post();
    	$comment = $post_data['comment'];
    	$userId = $post_data['userId'];
    	$searchId = $post_data['searchId'];
    	$shortlistedId = $post_data['shortlistedId'];
		$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('shortlistedId','Shortlisted property id','required|numeric|callback_shortlisted_property_check');		
		if ($this->form_validation->run() === false) {
    			$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => validation_errors(),'Result'=>''), 400);    		
		}else{
			if($comment){	
				$check_upload = $this->handle_commentFile_upload($comment);		
				if(!$check_upload){
					$error = $this->upload->display_errors('', '');
			       	$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => $error, 'Result' => false), 400);
				} 
			}else{
				unset($post_data['comment']);
			}
			$add_comments = $this->Common_model->add_comments($post_data);
			if($add_comments){
				$user_info = $this->Common_model->get_user_property_info($post_data);
				if($user_info){
					$user_name = trim($user_info[0]['firstName']);
					$propertyName = trim($user_info[0]['propertyName']);
					$propertyId = trim($user_info[0]['propertyId']);
					$get_tribes_deviceToken = $this->Common_model->get_tribes_deviceToken($userId,$searchId);
					if($get_tribes_deviceToken){
						$deviceToken = ARRAY();
						foreach ($get_tribes_deviceToken as $row) {
							$deviceToken[] = $row["deviceToken"];							
						}
						$message = $this->config->item('notification_add_comment_on_shortlisted_property');
						$message_to_push = str_replace("firstName", $user_name, $message[0]);						
						$message_to_push_event = str_replace("propertyName", $propertyName, $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_COMMENT"
							],
							"push_type"=> $message[1],
							"userId"=> $userId,
							"searchId"=> $searchId,
							"shortlistedId"=> $shortlistedId
						]);	
						$this->send_multiple_user_notification_ios($deviceToken, $payload);
					}
				}
					$this->response(array('ResponseCode' => 1, 'ResponseMessage' => 'SUCCESS', 'Comments' => 'Comment added successfully', 'Result' =>$add_comments), 200);	           
			}else{
				$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => 'Fail to add comment', 'Result' => $add_comments), 400);
			}
		}
	}
public function add_comments_post ( ) { $ post_data = $ this -> post ( ) ; $ comment = $ post_data [ 'comment' ] ; $ userId = $ post_data [ 'userId' ] ; $ searchId = $ post_data [ 'searchId' ] ; $ shortlistedId = $ post_data [ 'shortlistedId' ] ; $ 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 ( 'shortlistedId' , 'Shortlisted property id' , 'required|numeric|callback_shortlisted_property_check' ) ; if ( $ this -> form_validation -> run ( ) === false ) { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => validation_errors ( ) , 'Result' => '' ) , 400 ) ; } else { if ( $ comment ) { $ check_upload = $ this -> handle_commentFile_upload ( $ comment ) ; if ( ! $ check_upload ) { $ error = $ this -> upload -> display_errors ( '' , '' ) ; $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => $ error , 'Result' => false ) , 400 ) ; } } else { unset ( $ post_data [ 'comment' ] ) ; } $ add_comments = $ this -> Common_model -> add_comments ( $ post_data ) ; if ( $ add_comments ) { $ user_info = $ this -> Common_model -> get_user_property_info ( $ post_data ) ; if ( $ user_info ) { $ user_name = trim ( $ user_info [ 0 ] [ 'firstName' ] ) ; $ propertyName = trim ( $ user_info [ 0 ] [ 'propertyName' ] ) ; $ propertyId = trim ( $ user_info [ 0 ] [ 'propertyId' ] ) ; $ get_tribes_deviceToken = $ this -> Common_model -> get_tribes_deviceToken ( $ userId , $ searchId ) ; if ( $ get_tribes_deviceToken ) { $ deviceToken = ARRAY ( ) ; foreach ( $ get_tribes_deviceToken as $ row ) { $ deviceToken [ ] = $ row [ " deviceToken " ] ; } $ message = $ this -> config -> item ( 'notification_add_comment_on_shortlisted_property' ) ; $ message_to_push = str_replace ( " firstName " , $ user_name , $ message [ 0 ] ) ; $ message_to_push_event = str_replace ( " propertyName " , $ propertyName , $ 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_COMMENT " ] , " push_type " => $ message [ 1 ] , " userId " => $ userId , " searchId " => $ searchId , " shortlistedId " => $ shortlistedId ] ) ; $ this -> send_multiple_user_notification_ios ( $ deviceToken , $ payload ) ; } } $ this -> response ( array ( 'ResponseCode' => 1 , 'ResponseMessage' => 'SUCCESS' , 'Comments' => 'Comment added successfully' , 'Result' => $ add_comments ) , 200 ) ; } else { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => 'Fail to add comment' , 'Result' => $ add_comments ) , 400 ) ; } } }
Function for add comment in Shortlisted property
Function for add comment in Shortlisted property
//$fileType = $post_data['fileType']; //$commentFile = $post_data['commentFile']; //print_r($comment);exit(); /* get the login user info and shortlisted property info for push */ /* Send notification to my tribe members */ //print_r($deviceToken);exit();