public function getNearbyVenues(Request $request) { $validator = Validator::make($request->all(), $this->rules()); $response = array("status" => null, "message" => null); if ($validator->fails()) { $response['status'] = 'failed'; $response['message'] = $validator->errors()->all(); return json_encode($response); } $lat = $request->get('lat'); $lng = $request->get('lng'); /** * making radius an optional parameter */ $radius = $request->has('radius') ? $request->get('radius') : 0.05; $venues = new BusyVenues($lat, $lng, '2015-07-01', $radius); $message = $venues->getVenuesNearBy(); if (count($message) == 0) { $response['status'] = 'failed'; $response['message'] = 'No response from services'; return json_encode($response); } $response['status'] = 'OK'; $response['message'] = $message; return json_encode($response); }
public function getUserCount(Request $request) { // add validator $query = $request->input('query'); if (!$query) { $query = $request->input('queryFirst'); } $date = $request->input('date'); $rangeFromRequest = $request->input('range'); $range = $rangeFromRequest ? $rangeFromRequest : floor(config('controls.countReportRange') / 2); if ($range == 1) { $dateStart = $dateEnd = strtotime($date); } else { $range /= 2; $range = floor($range); $dateStart = strtotime('-' . $range . ' days', strtotime($date)); $dateEnd = strtotime('+' . $range . ' days', strtotime($date)); } $twit = new Twitter($query, $date); $lat = $request->input('lat'); $lng = $request->input('lng'); $venues = new BusyVenues($lat, $lng, $date, null); $returnData = array($query => array('twitter' => $twit->getCountForRange($dateStart, $dateEnd), 'venues' => $venues->getCountForRange($dateStart, $dateEnd))); return json_encode($returnData); }
public function getResults(Request $request) { $validator = Validator::make($request->all(), $this->rules()); if ($validator->fails()) { return redirect()->route('event')->withErrors($validator)->withInput(); } $query = $request->input('query' . $this->firstID); $date = $request->input('date'); if (!$query) { return redirect()->route('event'); } $twit = new Twitter($query); $lat = $request->input('lat'); $lng = $request->input('lng'); $venues = new BusyVenues($lat, $lng); $firstElement = array('id' => $this->firstID); /** * sorting the array */ $mergeQueries = array_merge($twit->getData(strtotime($date), 0, 10), $venues->getData(strtotime($date), 0, 20)); usort($mergeQueries, array($this, 'date_compare')); $response = array('elements' => array('first' => $firstElement), 'response' => $mergeQueries); return view('search.result')->with('data', $response)->withInput($request->all()); }
public function getResultsForEvent($query, Request $request) { $cacheTag = 'fullResponse'; //config timeline twitter $cacheKey = ''; $cacheLimit = 15; $requestParameters = array_values($request->all()); array_pop($requestParameters); foreach ($requestParameters as $value) { $cacheKey .= $value; } /** * UNCOMMENT IF USING INFINITE SCROLLING IN THE COMPARISON VIEW */ // foreach ($requestParameters as $value) { // if ($this->isFirst($query, $request)) { // if ($value !== $request->input("querySecond")) { // $cacheKey .= $value; // } // } else { // if ($value !== $request->input("queryFirst")) { // $cacheKey .= $value; // } // } // } // if (Cache::has($cacheKey)) { // return Cache::get($cacheKey); // } $date = $request->input('date'); $query = $query ? $query : $request->input('twitterAccount'); $twitterAccount = $request->input('twitterAccount'); $twitTimeline = $twitterAccount ? new TwitterTimeline($twitterAccount, $date) : new TwitterTimeline($query, $date); $twit = new Twitter($query, $date); $lat = $request->input('lat'); $lng = $request->input('lng'); /** * UNCOMMENT IF DELAYED SERVICES API WORKS */ // $trainStations = new TrainStations($lat, $lng, $date); // $stations = $trainStations->getData(); // // if there are any train stations nearby // if (count($stations) > 0) { // $delayedService = new DelayedServices($date); // foreach ($stations as $station) { // $delayedService->getDate($station['tiploc']); // } // } // */ $venues = new BusyVenues($lat, $lng, $date, null); /** * sorting the array */ $searchToken = $request->input('searchToken'); $mergeQueries = array_merge((array) $twit->getData(), $searchToken && $searchToken === 'venue' ? (array) $venues->getVenueData(strtotime($date)) : (array) $venues->getData(), (array) $twitTimeline->getData()); usort($mergeQueries, array($this, 'date_compare')); $response = array('sections' => array(), 'info' => array()); /* getting sections */ $response['sections'] = $this->generateSections($mergeQueries); $twitterInfo = $twit->getInfo(); if (count($twitterInfo) > 0) { $response['info']['twitter'] = $twitterInfo; } if (count($response['sections']) > 0 && $request->input('querySecond') == null) { //&& !is_null(Cache::get($cacheKey))) { Cache::put($cacheKey, $response, $cacheLimit); } return $response; }