public function testGetData() { $center = array('name' => 'Dublin Office', 'latitude' => 53.3381985, 'longitude' => -6.2592576, 'distance' => 100, 'unit' => 'km'); $testData = array('latitude' => '52.986375', 'user_id' => 12, 'name' => 'Christina McArdle', 'longitude' => '-6.043701'); $expectedReturnValue = 41.676839095744; $distanceObject = new Distance(); $distance = $distanceObject->vincentyGreatCircleDistance($testData['latitude'], $testData['longitude'], $center['latitude'], $center['longitude'], $center['unit']); $this->assertEquals($distance, $expectedReturnValue); }
private function getDistances() { $distances_rs = Distance::orderBy('sort_order', 'asc')->get(); $distances = [0 => 'Choose a distance']; foreach ($distances_rs as $d) { $distances[$d->id] = $d->name; } return $distances; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $validator = \Validator::make($request->all(), ['title' => 'required', 'city' => 'required']); if ($validator->fails()) { return response()->json(array('status' => 500, 'monolog' => array('title' => 'errors', 'message' => implode($validator->errors()->all(), '<br>')))); } DB::beginTransaction(); $user_id = \Auth::user()->get()->id; $property = Property::find($id); $property->user_id = $user_id; // $property->customer_id = $request->customer_id; $property->category_id = $request->category_id; $property->currency = $request->currency; $property->price = $request->price; // $property->discount = $request->discount; $property->type = $request->type; // $property->publish = $request->publish; $property->building_size = $request->building_size; $property->land_size = $request->land_size; // $property->sold = $request->sold; $property->code = $request->code; $property->status = $request->status; $property->year = $request->year; // $property->map_latitude = $request->map_latitude; // $property->map_longitude = $request->map_longitude; $property->city = $request->city; $property->province = $request->province; $property->country = $request->country; $property->slug = $request->slug; // $property->view = $request->view; $property->view_north = $request->view_north; $property->view_east = $request->view_east; $property->view_west = $request->view_west; $property->view_south = $request->view_south; $property->is_price_request = $request->is_price_request; $property->is_exclusive = $request->is_exclusive; $property->owner_name = $request->owner_name; $property->owner_email = $request->owner_email; $property->owner_phone = $request->owner_phone; $property->agent_commission = $request->agent_commission; $property->agent_contact = $request->agent_contact; $property->agent_meet_date = $request->agent_meet_date; $property->agent_inspector = $request->agent_inspector; $property->sell_reason = $request->sell_reason; $property->sell_note = $request->sell_note; $property->other_agent = $request->other_agent; // $property->display = $request->display; $property->orientation = $request->orientation; $property->sell_in_furnish = $request->sell_in_furnish; $property->lease_period = $request->lease_period; $property->lease_year = $request->lease_year; // find province, country $city = \App\City::where('city_name', $request->city)->first(); $property->city = $request->city; $property->province = $city->province->province_name; $property->country = $city->province->country->nicename; $property->save(); Model::unguard(); // lang $language = $property->propertyLanguages()->where('locale', 'en')->first(); if ($language) { $language->title = $request->title; $language->description = $request->description; } else { $language = new \App\PropertyLanguage(); $language->title = $request->title; $language->description = $request->description; $language->locale = 'en'; $language->property_id = $property->id; } $language->save(); // distances if ($request->distance_value) { foreach ($request->distance_value as $key => $value) { $distance = \App\Distance::find($request->distance_id[$key]); $distance->from = $key; $distance->value = $value; $distance->unit = $request->distance_unit[$key]; $distance->save(); } } // documents // if ($request->documents) { // foreach ($request->documents as $key => $value) { // $document = new \App\Document; // $document->property_id = $property->id; // $document->name = $key; // $document->is_included = $value; // $document->save(); // } // } // facilities if ($request->facilities) { foreach ($request->facilities as $key => $value) { $facility = \App\Facility::find($request->facility_id[$key]); $facility->name = $key; $facility->description = $value; $facility->save(); } } // files if ($request->hasFile('files')) { foreach ($request->file('files') as $key => $value) { $destinationPath = 'uploads/property'; $extension = $value->getClientOriginalExtension(); $fileName = date('YmdHis') . '_' . $key . '_kibarer_property' . '.' . $extension; $value->move($destinationPath, $fileName); $propertyFile = new \App\PropertyFile(); $propertyFile->property_id = $property->id; $propertyFile->file = $fileName; $propertyFile->save(); } } Model::reguard(); DB::commit(); return response()->json(array('status' => 200, 'monolog' => array('title' => 'update success', 'message' => 'Property has been updated'))); }