public function request_in_progress() { $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { $request = Requests::where('status', '=', 1)->where('is_completed', '=', 0)->where('is_cancelled', '=', 0)->where('owner_id', '=', $owner_id)->orderBy('created_at', 'desc')->first(); if ($request) { $request_id = $request->id; } else { $request_id = -1; } $response_array = array('request_id' => $request_id, 'success' => true); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function logout() { if (Request::isMethod('post')) { $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { $owner_data->latitude = 0; $owner_data->longitude = 0; $owner_data->device_token = 0; /* $owner_data->is_login = 0; */ $owner_data->save(); $response_array = array('success' => true, 'error' => 'Successfully Log-Out'); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } } $response = Response::json($response_array, $response_code); return $response; }
public function user_set_destination() { $request_id = Input::get('request_id'); $token = Input::get('token'); $owner_id = Input::get('id'); $dest_lat = Input::get('dest_lat'); $dest_long = Input::get('dest_long'); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'owner_id' => $owner_id, 'dest_lat' => $dest_lat, 'dest_long' => $dest_long), array('request_id' => 'required|integer', 'token' => 'required', 'owner_id' => 'required|integer', 'dest_lat' => 'required', 'dest_long' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->owner_id == $owner_data->id) { Requests::where('id', $request_id)->update(array('D_latitude' => $dest_lat, 'D_longitude' => $dest_long)); if ($request->current_walker) { $msg_array = array(); $msg_array['request_id'] = $request_id; $msg_array['unique_id'] = 4; $last_destination = Requests::find($request_id); $owner = Owner::find($owner_id); $request_data = array(); $request_data['owner'] = array(); $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name; $request_data['owner']['picture'] = $owner->picture; $request_data['owner']['phone'] = $owner->phone; $request_data['owner']['address'] = $owner->address; $request_data['owner']['latitude'] = $owner->latitude; $request_data['owner']['longitude'] = $owner->longitude; $request_data['owner']['dest_latitude'] = $last_destination->D_latitude; $request_data['owner']['dest_longitude'] = $last_destination->D_longitude; $request_data['owner']['rating'] = $owner->rate; $request_data['owner']['num_rating'] = $owner->rate_count; $request_data['dog'] = array(); if ($dog = Dog::find($owner->dog_id)) { $request_data['dog']['name'] = $dog->name; $request_data['dog']['age'] = $dog->age; $request_data['dog']['breed'] = $dog->breed; $request_data['dog']['likes'] = $dog->likes; $request_data['dog']['picture'] = $dog->image_url; } $msg_array['request_data'] = $request_data; $title = "Set Destination"; $message = $msg_array; if ($request->confirmed_walker == $request->current_walker) { send_notifications($request->confirmed_walker, "walker", $title, $message); } } $response_array = array('success' => true, 'error' => "Destination Set Successfully"); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with Owner ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Request ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function services_details() { $walker_id = Input::get('id'); $token = Input::get('token'); $validator = Validator::make(array('walker_id' => $walker_id, 'token' => $token), array('walker_id' => 'required|integer', 'token' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) { // check for token validity if (is_token_active($walker_data->token_expiry) || $is_admin) { $provserv = ProviderServices::where('provider_id', $walker_id)->get(); foreach ($provserv as $key) { $type = ProviderType::where('id', $key->type)->first(); $serv_name[] = $type->name; $serv_base_price[] = $key->base_price; $serv_per_distance[] = $key->price_per_unit_distance; $serv_per_time[] = $key->price_per_unit_time; } $response_array = array('success' => true, 'serv_name' => $serv_name, 'serv_base_price' => $serv_base_price, 'serv_per_distance' => $serv_per_distance, 'serv_per_time' => $serv_per_time); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Walker ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function update_profile() { $token = Input::get('token'); $owner_id = Input::get('id'); $first_name = Input::get('first_name'); $last_name = Input::get('last_name'); $email = Input::get('email'); $phone = Input::get('phone'); $password = Input::get('password'); $picture = Input::file('picture'); $bio = Input::get('bio'); $address = Input::get('address'); $state = Input::get('state'); $country = Input::get('country'); $zipcode = Input::get('zipcode'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id, 'email' => $email, 'picture' => $picture, 'zipcode' => $zipcode), array('token' => 'required', 'owner_id' => 'required|integer', 'email' => 'email', 'picture' => 'mimes:jpeg,bmp,png', 'zipcode' => 'integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { // Do necessary operations $owner = Owner::find($owner_id); if ($first_name) { $owner->first_name = $first_name; } if ($last_name) { $owner->last_name = $last_name; } if ($email) { $owner->email = $email; } if ($phone) { $owner->phone = $phone; } if ($bio) { $owner->bio = $bio; } if ($address) { $owner->address = $address; } if ($state) { $owner->state = $state; } if ($country) { $owner->country = $country; } if ($zipcode) { $owner->zipcode = $zipcode; } if ($password) { $owner->password = Hash::make($password); } if (Input::hasFile('picture')) { // upload image $file_name = time(); $file_name .= rand(); $file_name = sha1($file_name); $ext = Input::file('picture')->getClientOriginalExtension(); Input::file('picture')->move(public_path() . "/uploads", $file_name . "." . $ext); $local_url = $file_name . "." . $ext; // Upload to S3 if (Config::get('app.s3_bucket') != "") { $s3 = App::make('aws')->get('s3'); $pic = $s3->putObject(array('Bucket' => Config::get('app.s3_bucket'), 'Key' => $file_name, 'SourceFile' => public_path() . "/uploads/" . $local_url)); $s3->putObjectAcl(array('Bucket' => Config::get('app.s3_bucket'), 'Key' => $file_name, 'ACL' => 'public-read')); $s3_url = $s3->getObjectUrl(Config::get('app.s3_bucket'), $file_name); } else { $s3_url = asset_url() . '/uploads/' . $local_url; } $owner->picture = $s3_url; } $owner->save(); $response_array = array('success' => true, 'id' => $owner->id, 'first_name' => $owner->first_name, 'last_name' => $owner->last_name, 'phone' => $owner->phone, 'email' => $owner->email, 'picture' => $owner->picture, 'bio' => $owner->bio, 'address' => $owner->address, 'state' => $owner->state, 'country' => $owner->country, 'zipcode' => $owner->zipcode, 'login_by' => $owner->login_by, 'social_unique_id' => $owner->social_unique_id, 'device_token' => $owner->device_token, 'device_type' => $owner->device_type, 'token' => $owner->token); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }