<< BACK
//JSON Viewer (see json format to array)
-------------------------------------------------------------------------------------------------------------------------
using post method and catch record and return json output in API (Web Services)
function Driver(){
$jsonObj = file_get_contents('php:// input');
$requestData = json_decode($jsonObj,true);
if(isset($requestData['method' ]) && $requestData['method']!="" && $requestData['method']>0){
$method=$requestData['method'] ;
switch($method){
CASE "Login":
$this->loginDriver($ requestData);
break;
CASE "Register":
$this->registerDriver($ requestData);
break;
CASE "FORGOT_PASS":
break;
}
} else {
$data['STATUS']="UNATHORISED USER";
}
echo json_encode($data);
}
********************************************************************************************
function registerDriver($requestData){
$password = $requestData['password'];
$email_id = $requestData['email_id'];
//generate code and return id
$user_id = $this->loginDetails($email_id, $password);
if($user_id){
$ReturnData=array("user_id"=>$ user_id);
$data['DATA']=$ReturnData;
$data['STATUS']="OK";
$data['MSG']="REGISTRATION SUCCESSFULLY";
} else if($mobile_count != '0'){
$data['STATUS']="ERROR";
$data['MSG']="USER ALREADY EXISTS!";
}
echo json_encode($data);
}
********************************************************************************************
function loginDriver($requestData){
$password = $requestData['password'];
$username = $requestData['username'];
$emailExplode = explode('@',$username);
for($i=0;$i<count($ emailExplode);$i++){
$emailCount += $i;
}
$connection = "ht_user_login_details";
if($emailCount != 0){
$checkStatus = $this->home_model-> getAndWhereData($connection,' email_id',$username,'password' ,$password);
} else if($emailCount == 0){
$checkStatus = $this->home_model-> getAndWhereData($connection,' mobile_number',$username,' password',$password);
}
$userCount = $checkStatus->count();
if($userCount == 1){
$driver_Data = array(
'driver_details' => array()
);
while($checkStatus->hasNext()) {
$userData = $checkStatus->getNext();
$driver_Data['driver_details'] = array(
"user_id" => $userData["_id"]->__toString() ,
"email_id" => $userData["email_id"],
"mobile_number" => $userData["mobile_number"],
"password" => $userData["password"],
"status" => $userData["status"],
"IMEI_number" => $userData["IMEI_number"],
"gcm_number" => $userData["gcm_number"],
"verification_code" => $userData["verification_code"] ,
"user_type" => $userData["user_type"],
"date_time" => $userData["date_time"],
"ip" => $userData["ip"]
);
}
$data['DATA']=$driver_Data[' driver_details'];
$data['STATUS']="OK";
$data['MSG']="LOGIN SUCCESSFUL";
} else {
$data['STATUS']="FAILED";
$data['MSG']="Please Enter Valid User Name And Password.";
}
echo json_encode($data);
}
-----------------------------------------------------------------------------------------------------------------------------
using get method and catch record and return json output in API (Web Services)
If record insert/update/delete and return to success msg
function addFeedback(){
$feedback = $_GET['feedback_details'];
$theatre_id = $_GET['theatre_id'];
$screen_id = $_GET['screen_id'];
$user_id = $_GET['user_id'];
$ip = $this->input->ip_address();
$formValues = array(
'feedback_details' => $feedback,
'theatre_id' => $theatre_id,
'screen_id' => $screen_id,
'user_id' => $user_id,
'ip' => $ip
);
$tablename = "kr_theatre_feedback_details";
$this->admin_model->insert_ and_return($tablename, $formValues);
$data=array('success'=>"1");
echo json_encode($data);
}
********************************************************************************************
If fetch record and return array
function getUpcomingMovieList(){
$theatre_id = $_GET['theatre_id'];
$screen_id = $_GET['screen_id'];
$upcomingMovie = $this->admin_model->get_and_ and_where_data("kr_theatre_ upcoming_movie_details"," theatre_id","screen_id"," status",$theatre_id,$screen_ id,'0');
$obj = new stdClass();
$obj->upcoming_movie_list = $upcomingMovie;
echo json_encode($obj);
}
No comments:
Post a Comment