/** * @return ElasticaQuery */ private function prepareQuery($params, $start = null, $limit = null) { $query = null; $filter = null; $sort = ['_score' => 'desc']; // We'd like to search in both title and description for keywords if (!empty($params['keywords'])) { $query = new QueryString($params['keywords']); $query->setDefaultOperator('AND')->setFields(['title', 'description']); } // Add location filter is location is selected from autosuggest if (!empty($params['location_id'])) { $location = Location::find($params['location_id']); $filter = new GeoDistance('location', ['lat' => $location->lat, 'lon' => $location->lon], $params['radius'] . 'mi'); // Sort by nearest hit $sort = ['_geo_distance' => ['jobs.location' => [(double) $location->lon, (double) $location->lat], 'order' => 'asc', 'unit' => 'mi']]; } // If neither keyword nor location supplied, then return all if (empty($params['keywords']) && empty($params['location_id'])) { $query = new MatchAll(); } // We need a filtered query $elasticaQuery = new ElasticaQuery(new Filtered($query, $filter)); $elasticaQuery->addSort($sort); // Offset and limits if (!is_null($start) && !is_null($limit)) { $elasticaQuery->setFrom($start)->setSize($limit); } // Set up the highlight $elasticaQuery->setHighlight(['order' => 'score', 'fields' => ['title' => ['fragment_size' => 100], 'description' => ['fragment_size' => 200]]]); return $elasticaQuery; }
public static function boot() { parent::boot(); static::creating(function ($model) { if ($model->status == null) { $model->status = static::CREATE; } if ($model->qty == null) { $model->qty = 1; } if ($model->location_id != null) { $location = Location::find($model->location_id, ['name']); if ($location) { $model->location_name = $location->name; } } }); static::created(function ($model) { }); static::updating(function ($model) { if ($model->qty == null) { $model->qty = 1; } }); }
public function saveReferees(Season $season, Competition $competition, Request $request) { $data = $request->all(); $competition->referees()->wherePivot('season_id', '=', $season->id)->detach(); $pairs = $this->getPairs($season, $competition); foreach ($pairs as $pair) { $pair->active = 0; $pair->save(); } $response = ['refs' => array(), 'crefs' => array()]; $country = Country::find($data['country']); $refs = json_decode($data['referees'], true); foreach ($refs as $ref) { $newRef = $competition->storeReferee($ref, $season, 0, $country); if (array_key_exists('styled', $ref)) { if ($ref['styled'] == 'new') { $newRef['location'] = Location::find($newRef->location_id)->name; array_push($response['refs'], $newRef); } } } $crefs = json_decode($data['court_referees'], true); foreach ($crefs as $cref) { $newRef = $competition->storeReferee($cref, $season, 1, $country); if (array_key_exists('styled', $cref)) { if ($cref['styled'] == 'new') { $newRef['location'] = Location::find($newRef->location_id)->name; array_push($response['crefs'], $newRef); } } } $response['pairs'] = $this->getPairs($season, $competition)->toArray(); return $response; }
/** * Delete employee location from DB * * @param $id * @return mixed */ public function deleteLocation($id) { $location = Location::find($id); if (count($location->employees()->get()->toArray())) { return redirect()->back()->with('danger_flash_message', 'You cannot delete a location that is in use.'); } $location->delete(); return redirect()->route('manageLocations')->with('flash_message', 'Location ' . $location->name . ' has been deleted'); }
public function getLocationNameByCode(Request $request, $code) { $location = Location::find($code); if ($location == null) { return response()->json(['name' => ""]); } $name = $location->name; return ['name' => $name]; }
public function destroy($id) { $location = Location::find($id); if ($location->delete()) { return $this->output('Location deleted'); } else { return $this->notFound('Location not found'); } }
public function postDeleteLocation(Request $request) { $locationId = intval($request->input('location_id')); if ($locationId) { Location::find($locationId)->delete(); return response(Location::all()); } return redirect('dashboard/locations')->withErrors('No location id passed'); }
public static function countComments($id) { $comments = \App\Comment::where('id_location', '=', $id); $location = Location::find($id); $location->rating = ceil($comments->avg('rating') / 0.5) * 0.5; $location->voters = $comments->count(); $location->save(); return $avgRating; }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $location_id, $id) { $location = Location::find($location_id); $price = Price::find($id); $price->type = $request->type; $price->price = $request->price; $price->price_date = $request->price_date; $price->location()->associate($location); $price->save(); return redirect()->action('LocationController@show', $price->location->id); }
public static function fromLocationWithCoordinates($location_id, $coordinates) { // DOES NOT SAVE TARGET - // must save through experiment for foreign key check $location = Location::find($location_id); $target = new Target(); $target->location()->associate($location); $target->coordinates = $coordinates; $target->is_decoy = false; return $target; }
/** * Downlod Tournaments * * @return Response */ public function tournaments(Request $request) { $time_period = $request->input('time_period'); $location_id = $request->input('location_id'); $location = Location::find($location_id)->location; $ss = new Scraper(); $new_tournaments = $ss->get_tournaments($location, $time_period); $tournaments = \DB::table('tournaments')->orderBy('start_date', 'desc')->get(); //return view('pages/tournaments', compact('tournaments')); return redirect('admin/scraper')->with('success', 'tournaments downloaded successfully'); }
public function update($city, $id) { $location = Location::find($id); $location->name = Request::input('name'); $location->type = Request::input('type'); $location->time = Request::input('time'); $location->specification = Request::input('specification'); $location->description = Request::input('description'); $location->price = Request::input('price'); $location->address = Request::input('address'); $location->save(); return $location; }
/** * @param $id * @param bool $withUsers * @return mixed * @throws GeneralException */ public function findOrThrowException($id, $hasPcode = false) { if (empty($id)) { throw new GeneralException("Location id is empty."); } if ($hasPcode) { $location = Location::has('pcode')->find($id); } else { $location = Location::find($id); } if (!is_null($location)) { return $location; } throw new GeneralException("That location with id {$id} does not exist."); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('adjacent_location')->delete(); DB::table('locations')->delete(); $locations = [["id" => 1, "name" => "Inn", "description" => "An establishment or building providing lodging and, usually, food and drink for travelers (Starting location)", "image" => "locations/Inn-800px.png", "image_sm" => "locations/Inn-300px.png"], ["id" => 2, "name" => "Town Hall", "description" => "Public forum or meeting in which those attending gather to discuss civic or political issues, hear and ask questions about the ideas of a candidate for public office", "image" => "locations/Townhall-800px.png", "image_sm" => "locations/Townhall-300px.png"], ["id" => 3, "name" => "Smithy", "description" => "A blacksmith's shop. A place to purchase weaponry and armor or train one's skill as a blacksmith", "image" => "locations/Blacksmith-800px.png", "image_sm" => "locations/Blacksmith-300px.png"], ["id" => 4, "name" => "Military academy fortress", "description" => "An institute where soldiers and mercenaries train they martial skills", "image" => "locations/Fortress-800px.png", "image_sm" => "locations/Fortress-300px.png"]]; foreach ($locations as $location) { Location::create($location); } $adjacent_locations = [["location_id" => 1, "adjacent_location_id" => 2, "direction" => "north"], ["location_id" => 1, "adjacent_location_id" => 3, "direction" => "east"], ["location_id" => 1, "adjacent_location_id" => 4, "direction" => "south"]]; foreach ($adjacent_locations as $record) { /** @var $location Location */ $location = Location::find($record['location_id']); /** @var $adjacent_location Location */ $adjacent_location = Location::find($record['adjacent_location_id']); $location->addAdjacentLocation($adjacent_location, $record['direction']); } }
public function update(Request $request, $locationID) { if (!Auth::check() || !Auth::user()->is_admin) { return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403); } $data = $request->only(['name', 'latitude', 'longitude', 'capacity', 'featured_image']); // Validate all input $validator = Validator::make($data, ['name' => 'required', 'latitude' => 'required|numeric|between:-85.05,85.05', 'longitude' => 'required|numeric|between:-180,180', 'capacity' => 'required', 'featured_image' => 'image|sometimes']); if ($validator->fails()) { // If validation fails, redirect back to // registration form with errors return Redirect::back()->withErrors($validator)->withInput(); } if ($request->hasFile('featured_image')) { $data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "news_images", $bestFit = true, $fitDimensions = [1920, 1080]); } else { unset($data['featured_image']); } $location = Location::find($locationID); $location->update($data); return Redirect::route('locations.edit', [$location->id]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $location = Location::find($id); $location->delete(); return Response::make("Success", 204); }
/** * Function that saves an Institution. * * @return Response */ public function saveInstitution() { // Validate Input. $validator = Validator::make(Input::all(), array('name' => 'required', 'id' => 'required', 'phone' => 'required', 'address' => 'required', 'lat' => 'required', 'lon' => 'required', 'creditLimit' => 'required', 'institutionId' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'No se envio la informacion completa!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(['state' => 'No autorizado']); } // Get the credit value. $credit = Input::get('credit') ? true : false; $creditLimit = Input::get('creditLimit'); // Reset creditLimit just in case. if (!$credit) { $creditLimit = 0; } // Get the institution. $institution = Institution::find(Input::get('institutionId')); if (!$institution) { $response['state'] = 'Error'; $response['error'] = 'No existe una institucion con este numero de identifiacion!'; return response()->json($response); } // Now get the location. $location = Location::find($institution->LocationId); // Update Institution. $institution->Name = Input::get('name'); $institution->RUC = Input::get('id'); $institution->Phone = Input::get('phone'); $institution->Email = Input::get('email'); $institution->Address = Input::get('address'); $institution->Excempt = Input::get('excemption'); $institution->Credit = $credit; $institution->CreditLimit = $creditLimit; // Save the Institution. $institution->save(); // Update the location. $location->Name = 'Direccion de ' . Input::get('name'); $location->Latitude = Input::get('lat'); $location->Longitude = Input::get('lon'); // Save the location. $location->save(); return response()->json(['state' => 'Success']); }
/** * Execute the console command. * * @return mixed */ public function handle() { // Get contracts that are still active. $contracts = Contract::where('State', '!=', 'used')->where('State', '!=', 'cancelled')->where('State', '!=', 'paid')->get(); foreach ($contracts as $contract) { // Check if we have visited this month. if ($contract->Visited) { // Check if we should reset this. if ($contract->QuotaInterval == 'mensuales') { if ('01' == date('d')) { $contract->Visited = false; $contract->save(); } } else { if ($contract->QuotaInterval == 'quincenales') { if ('01' == date('d')) { $contract->Visited = false; $contract->save(); } else { if ('16' == date('d')) { $contract->Visited = false; $contract->save(); } } } else { if (date('D') == 'Mon') { $contract->Visited = false; $contract->save(); } } } } // Check if we need to organize a visit for this contract. if (!$contract->Visited) { if ($contract->StartDate < date('Y-m-d')) { $visitDates = explode(',', $contract->PaymentDates); foreach ($visitDates as $date) { if ($date == date('d', strtotime("+3 days"))) { // Check if we already have a visit programmed for this contract. $transports = Transport::where('Type', '=', '8')->where('ReasonId', '=', $contract->Id)->where('Date', '=', date('Y-m-d', strtotime("+3 days")))->get(); if (count($transports) == 0) { // Get an appropriate vehicle for this. $vehicles = Vehicle::where('BranchId', '=', $contract->BranchId)->where('Repair', '=', false)->get(); $vehicle = null; foreach ($vehicles as $v) { if (!$vehicle) { $vehicle = $v; } // In this case the smaller the vehicle the more suitable it should be. // TODO: This could be improved. if ($v->Type < $vehicle->Type) { $vehicle = $v; } } if (!$vehicle) { // In this case we don't have a vehicle and the provider doesn't provide delivery so we must notify an administrator. $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => 'Aergia no fue capaz de organizar el cobro para el contrato ' . $contract->Code . '. Por favor revisar y organizar el cobro de la cuota de este contrato.', 'Url' => '/contract/' . $contract->Id, 'Seen' => false)); } } else { // Get location of client. $client = Client::find($contract->ClientId); $location = Location::find($client->LocationId); $transport = Transport::create(array('Date' => date('Y-m-d', strtotime("+3 day")), 'Time' => '00:00:00', 'VehicleId' => $vehicle->Id, 'DriverId' => 0, 'StartLatitude' => 0, 'StartLongitude' => 0, 'Journey' => '[]', 'EndLatitude' => $location->Latitude, 'EndLongitude' => $location->Longitude, 'EndAddress' => $client->Address, 'Distance' => 0, 'ReasonId' => $contract->Id, 'Type' => 8, 'State' => 2, 'Order' => 0, 'Depreciation' => 0)); // Inform creditor of when you shall collect payment. if ($client->Email != '') { Mail::send('emails.ai.contractReminder', ['contract' => $contract, 'transport' => $transport], function ($message) use($contract, $client) { $message->to($client->Email); $message->subject('Cobro de Cuota de Contrato: ' . $contract->Code); }); } } } } } } } // TODO: Not sure if I want to do something in these cases. switch ($contract->State) { case 'usedpending': break; case 'late': break; } } }
/** * Remove the specified resource from storage. * * @param int $id ID of the location to destroy * @return \Illuminate\Http\Response */ public function destroy($id) { // Get selected location $location = Location::find($id); if ($location == null) { return redirect()->route('dashboard.settings.locations.index')->with('message', 'Error: Location not found'); } // Ensure no screens depend of the location $count = $location->Screens->count(); if ($count != 0) { return redirect()->route('dashboard.settings.locations.index')->with('message', 'Unable to delete location as one or more screens depend on it'); } // Delete $location->delete(); return redirect()->route('dashboard.settings.locations.index')->with('message', 'Location deleted successfully'); }
public function update(Request $request, $id) { $input = $request->all(); $data = array('name' => $input['name'], 'address' => $input['address'], 'link' => stripUnicode($input['name']) . '_' . stripUnicode($input['address']), 'contact' => $input['contact'], 'describe' => $input['describe'], 'sale' => $input['sale'], 'price' => $input['price'], 'category_id' => $input['category_id'], 'area' => $input['area'], 'actived' => '0'); Location::find($id)->update($data); return Redirect::back(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $loc = Location::find($id); if ($loc->targets()->count() == 0) { $loc->delete(); Session::flash('message', "Location {$id} Deleted"); } else { Session::flash('message', "Location {$id} Could Not Be Deleted (IN USE)"); } return redirect()->action('LocationsController@index'); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { // create the new Location $location = Location::find($id); $location->number = $request->number; $location->address = $request->address; $location->type = $request->type; $location->bedrooms = $request->bedrooms; $location->bathrooms = $request->bathrooms; $location->sqft = $request->sqft; $location->built = $request->built; $location->mlsid = $request->mlsid; $location->details = $request->details; $location->save(); return redirect()->action('LocationController@show', $location->id); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function getDelete($id) { // $location = Location::find($id); if (!$location) { return response()->json(JSend::fail(['Data not found'])->encode()); } if ($location->delete()) { return response()->json(JSend::success($location->toArray())->encode()); } else { return response()->json(JSend::fail($location->getErrors()->toArray())->encode()); } }
return ""; }); Route::get('api/profile/image', function () { $player_id = (int) Input::get('playerID'); if (get_headers('http://www.r2sports.com/tourney/imageGallery/gallery/player/' . $player_id . '_normal.jpg')[0] != 'HTTP/1.1 404 Not Found') { $profile = 'http://www.r2sports.com/tourney/imageGallery/gallery/player/' . $player_id . '_normal.jpg'; } else { $profile = '/images/racquet-right.png'; } return $profile; }); Route::get('api/rankings/history', function () { $player_id = (int) Input::get('player_id'); $group_id = Input::get('group_id'); $location_id = (int) Input::get('location_id'); $location = Location::find($location_id); $player = Player::find($player_id); $rankings = Ranking::where('player_id', '=', $player_id)->select('ranking_date', 'location_id', 'ranking')->orderBy('ranking_date')->get(); /*National Ranking*/ $national = Ranking::where('player_id', '=', $player_id)->where('location_id', '=', 0)->select('ranking_date', 'ranking')->orderBy('ranking_date')->get(); $query = "\n\t\tSELECT \n\t\t\tdate_format(ranking_date, '%m/%d/%Y') as ranking_date,\n\t\t\tranking\n\t\tFROM\n\t\t\trankings\n\t\tWHERE\n\t\t\tplayer_id = {$player_id}\n\t\t\tAND location_id = 0\n\t\t\tAND group_id = {$group_id}\n\t\tORDER BY \n\t\t\tranking_date\n\t\t"; $national = \DB::select(DB::raw($query)); $arr_national = array(); foreach ($national as $key => $n) { $row = array(); $row['ranking_date'] = $n->ranking_date; $row['National'] = intval($n->ranking); array_push($arr_national, $row); } //dd($player); /*State Ranking*/
/** * Execute the console command. * * @return mixed */ public function handle() { // Let's get all credit sales that have not been paid yet. $creditSales = Sale::where('Credit', '=', true)->where('Cancelled', '=', false)->get(); // Check if any of them are due soon. $today = date('Y-m-d H:i:s'); foreach ($creditSales as $sale) { // Get the client or institution that made the credit purchase. $creditor = null; if ($sale->CreditorType == 1) { $creditor = Client::find($sale->CreditorId); } else { $creditor = Institution::find($sale->CreditorId); } // First check if the payment is late. if (date('Y-m-d H:i:s', strtotime($sale->Created) + $creditor->CreditDays * 86400) < $today) { // If it's past due for more than a month notify admins so they can deal with it. if (date('Y-m-d H:i:s', strtotime($sale->Created) + ($creditor->CreditDays + 30) * 86400) < $today) { // In this case we don't have a vehicle and the provider doesn't provide delivery so we must notify an administrator. $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => 'Aergia ha tratado de cobrar la venta de credito con factura: ' . $sale->Id . ', sin embargo no se ha registrado el pago de la factura y esta tiene mas de un mes de vencimiento. Aergia no seguira tratando de cobrar esta factura, por favor darle seguimiento al caso.', 'Url' => '/creditdue/' . $sale->Id, 'Seen' => false)); } } else { // Check to see if there is a transport request active to collect payment. $transport = Transport::where('Type', '=', 7)->where('ReasonId', '=', $sale->Id)->where('Date', '>', date('Y-m-d'))->get(); if (count($transport) == 0) { // Get a vehicle that can be used to go to charge creditor. $vehicles = Vehicle::where('BranchId', '=', $sale->BranchId)->where('Repair', '=', false)->get(); $vehicle = null; foreach ($vehicles as $v) { if (!$vehicle) { $vehicle = $v; } // In this case the smaller the vehicle the more suitable it should be. // TODO: This could be improved. if ($v->Type < $vehicle->Type) { $vehicle = $v; } } if (!$vehicle) { // In this case we don't have a vehicle to go charge creditor so we must notify an administrator. $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => 'Aergia no fue capaz de organizar el cobro de la factura: ' . $sale->Id . ' ya que no tuvo vehiculos disponibles para hacerlo. Por favor organizar el cobro de la factura.', 'Url' => '/creditdue/' . $sale->Id, 'Seen' => false)); } } else { // Get location of creditor. $location = Location::find($creditor->LocationId); $paymentCollection = Transport::create(array('Date' => date('Y-m-d', strtotime("+1 day")), 'Time' => '00:00:00', 'VehicleId' => $vehicle->Id, 'DriverId' => 0, 'StartLatitude' => 0, 'StartLongitude' => 0, 'Journey' => '[]', 'EndLatitude' => $location->Latitude, 'EndLongitude' => $location->Longitude, 'EndAddress' => $creditor->Address, 'Distance' => 0, 'ReasonId' => $sale->Id, 'Type' => 7, 'State' => 2, 'Order' => 0, 'Depreciation' => 0)); // Inform creditor of when you shall collect payment. if ($creditor->Email != '') { Mail::send('emails.ai.creditorReminder', ['sale' => $sale, 'creditor' => $creditor, 'transport' => $paymentCollection], function ($message) use($sale, $creditor) { $message->to($creditor->Email); $message->subject('Cobro Factura: ' . $sale->Id); }); } } } } } } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { return Response::json(Location::find($id)); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $location = Location::find($id); $location->delete(); Notification::success('Localidad "' . $location->name . '" eliminada correctamente'); return redirect('locations'); }
public function action(Request $request) { $input = $request->all(); if (isset($input['delete'])) { $id_xoa = $input['checkbox']; foreach ($id_xoa as $id) { Location::find($id)->delete(); } return Redirect::to('/admin'); } if (isset($input['active'])) { $id_active = $input['checkbox']; foreach ($id_active as $id) { $query = DB::table('location')->where('id', $id)->update(['actived' => 1]); } return Redirect::to('/admin'); } }
/** * Function that gets data of specified client. * * @return Response */ public function getClient() { // Validate Input. $validator = Validator::make(Input::all(), array('client' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'Informacion incompleta!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(array()); } // Get the client. $client = Client::where('cedula', '=', Input::get('client'))->first(); $response['name'] = $client->Name; $response['number'] = $client->Phone; $response['address'] = $client->Address; // Get the latitude and longitude of address. $location = Location::find($client->LocationId); $response['lat'] = $location->Latitude; $response['lon'] = $location->Longitude; // Return client info. return response()->json($response); }
public function update(Request $request, $id) { $user_id = $id; $datedoc = Carbon::now(-6); $user = User::find($user_id); if (is_null($user)) { return redirect()->back()->with('status', 'Could not locate record'); } $role_id = $request->input('role_id'); $location_id = $request->input('location_id'); $location = Location::find($location_id); if (is_null($location)) { $locname = ""; $location_id = 0; } else { $locname = $location->name; } $role = Role::find($role_id); if (is_null($location)) { $rolename = ""; $role_id = 0; } else { $rolename = $role->rolename; } $fname = $request->input('fname'); $lname = $request->input('lname'); $email = $request->input('email'); $morechks = array('eie', 'issupervisor'); foreach ($morechks as $morechk) { $user->setAttribute($morechk, Input::has($morechk) ? true : false); } $user->datedoc = $datedoc; $user->datestart = $datedoc; $user->location_id = $location_id; $user->location = $locname; $user->isactive = 1; $user->supervisor_id = $request->input('supervisor_id'); $user->fname = $fname; $user->lname = $lname; $user->email = $email; $user->username = $request->input('username'); $user->fullname = $fname . ' ' . $lname; $user->name = $fname . ' ' . $lname; $user->role = $rolename; $user->role_id = $role_id; $changepass = $request->input('changepass'); if (is_null($changepass)) { $changepass = 0; } if ($changepass == 1) { $datenextpass = $datedoc->addDays(90); $datelastpass = $datedoc; $user->datenextpass = $datenextpass; $user->datelastpass = $datedoc; $password = $request->input('password'); $password = bcrypt($password); $user->password = $password; } $user->save(); return redirect('useradmin')->with('status', 'Updated User'); }