public function create() { $elasticsearch = new Client(); $sight = $this->sightRepository->getById(Input::get('sight_id')); $time = Carbon::now($sight->city->timezone)->hour; $searchQuery['index'] = 'sightseeing'; $searchQuery['type'] = 'sight'; $searchQuery['body'] = ['min_score' => 0.0001, 'query' => ['function_score' => ['query' => ['bool' => ['must' => [0 => ['range' => ['cost' => ['lte' => Input::get('cost')]]]], 'should' => [0 => ['range' => ['closing_hours' => ['gte' => $time]]], 1 => ['range' => ['opening_hours' => ['lte' => $time]]]]]], 'functions' => [0 => ['gauss' => ['location' => ['origin' => $sight->latitude . ',' . $sight->longitude, 'offset' => '0.5km', 'scale' => '0.1km', 'decay' => 0.33]]]]]]]; $suggestions = $elasticsearch->search($searchQuery); $filteredSuggestions = array(); $filteredSuggestions['data'] = []; foreach ($suggestions['hits']['hits'] as $suggestion) { $suggestionAdded = false; foreach ($suggestion['_source']['categories'] as $category) { if (in_array($category['id'], Input::get('categories')) && !$suggestionAdded && $suggestion['_id'] != Input::get('sight_id')) { $filteredSuggestions['data'][] = ['id' => $suggestion['_id'], 'score' => $suggestion['_score']]; $suggestionAdded = true; } } } $maxScore = 0; foreach ($filteredSuggestions['data'] as $suggestion) { if ($suggestion['score'] > $maxScore) { $maxScore = $suggestion['score']; } } $filteredSuggestions['max_score'] = $maxScore; return $filteredSuggestions; }
/** * Handle the command * * @param $command * @return mixed */ public function handle($command) { $client = S3Client::factory(array('key' => $this->config->get('services.s3.key'), 'secret' => $this->config->get('services.s3.secret'))); /* * Delete image from S3 */ $filesystem = new Flysystem(new Adapter($client, $this->config->get('sightseeing.s3-bucket'))); $image = $this->sightRepository->getImageById($command->imageId); $filesystem->delete($image->path); /* * Delete DB record */ $this->sightRepository->deleteImageById($command->imageId); }
/** * Handle the command * * @param $command * @return mixed */ public function handle($command) { $client = S3Client::factory(array('key' => $this->config->get('services.s3.key'), 'secret' => $this->config->get('services.s3.secret'))); /* * Upload image to S3 */ $filesystem = new Flysystem(new Adapter($client, $this->config->get('sightseeing.s3-bucket'))); $extension = $this->filesystem->extension($command->image->getClientOriginalName()); $filename = sha1(time() . time()) . ".{$extension}"; $filesystem->write($filename, file_get_contents($command->image), ['visibility' => 'public']); /* * Create record on the database */ $this->sightRepository->addImageById($command->id, $filename); }
public function show($sightId) { $beacon = $this->beaconRepository->getById($sightId); $sights = $this->sightRepository->getAll(); return \View::make('beacons.show')->with('title', 'Edit Beacon')->with('beacon', $beacon)->with('sights', $sights); }
public function showImage($imageId) { $image = $this->sightRepository->getImageById($imageId); $sight = $image->sight; return \View::make('sights.image')->with('title', 'Editing image')->with('image', $image)->with('sight', $sight); }
public function share($id) { $sight = $this->sightRepository->getById($id); return \View::make('pages.share')->with('sight', $sight); }