/**
  * Display a listing of all available countries
  *
  * Country name
  * Country flag URL
  * Country center geo (Lat/Long)
  * Country top left geo (Lat/Long)
  * Country bottom right geo (Lat/Long)
  *
  * Path: /staticapi/places/country
  */
 public function index()
 {
     $countries = Place::where('type', '=', "country")->get();
     $formattedCountries = array();
     foreach ($countries as $country) {
         $formattedCountries[] = ['country_id' => $country->id, 'country_name' => $country->name, 'country_second_name' => $country->second_name, 'country_center_location' => ['longitude' => $country->center_longitude, 'latitude' => $country->center_latitude], 'country_top_left_location' => ['longitude' => $country->top_left_longitude, 'latitude' => $country->top_left_latitude], 'country_bottom_right_location' => ['longitude' => $country->bottom_right_longitude, 'latitude' => $country->bottom_right_latitude]];
     }
     return Response::json(array('data' => $formattedCountries, 'status_code' => 200), 200);
 }
 public function place()
 {
     $places = \App\Place::where('active', 1)->with('kategori')->get();
     $data = [];
     foreach ($places as $place) {
         array_push($data, ['place_id' => $place->id, 'nama' => $place->nama, 'kategori' => $place->kategori->nama, 'harga' => $place->harga]);
     }
     $display['place'] = $data;
     return $display;
 }
 /**
  * Display a listing of all states within the given country
  *
  * State name
  * State second name
  * State center geo (Lat/Long)
  * State top left geo (Lat/Long)
  * State bottom right geo (Lat/Long)
  *
  * Path: /staticapi/places/country/{$countryId}/state
  *
  * @return Response with status_code 200 if OK, 400 otherwise
  */
 public function index($countryId)
 {
     $states = Place::where([['type', '=', "state"], ['parent', '=', $countryId]])->get();
     $formattedStates = array();
     if ($states->isEmpty()) {
         if (Place::where([['type', '=', "country"], ['id', '=', $countryId]])->first() == null) {
             throw new BadRequestException('This country does not exist.');
         }
     } else {
         foreach ($states as $state) {
             $formattedStates[] = ['state_id' => $state->id, 'state_name' => $state->name, 'state_second_name' => $state->second_name, 'state_center_location' => ['longitude' => $state->center_longitude, 'latitude' => $state->center_latitude], 'state_top_left_location' => ['longitude' => $state->top_left_longitude, 'latitude' => $state->top_left_latitude], 'state_bottom_right_location' => ['longitude' => $state->bottom_right_longitude, 'latitude' => $state->bottom_right_latitude]];
         }
     }
     return Response::json(array('data' => $formattedStates, 'status_code' => 200, 'params' => array('country' => $countryId)), 200);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $ennasr = Place::where([['type', '=', "city"], ['name', '=', 'Ennasr']])->first();
     $sahloul = Place::where([['type', '=', "city"], ['name', '=', 'Sahloul']])->first();
     $jawhara = Place::where([['type', '=', "city"], ['name', '=', 'Cité Jawhara']])->first();
     $sousse = Place::where([['type', '=', "state"], ['name', '=', 'Sousse']])->first();
     if ($ennasr == null || $sahloul == null || $jawhara == null || $sousse == null) {
         echo "Some places are missing.";
         return;
     }
     $mosque1 = Mosque::create(['name' => 'Mosquée Farhat Hached Jawhara', 'second_name' => null, 'latitude' => '35.832436', 'longitude' => '10.622167', 'prayer_start' => '13:00', 'prayer_start_confirmations' => 2, 'prayer_end' => '13:30', 'prayer_end_confirmations' => 1, 'interior_space' => 4, 'interior_space_confirmations' => 1, 'parking_space' => 4.5, 'parking_space_confirmations' => 4, 'address' => 'Avenue du 20 Mars 1956, Sousse', 'city' => $jawhara->id, 'state' => $sousse->id]);
     $mosque2 = Mosque::create(['name' => 'Great Grand Mosque', 'second_name' => 'Great Grand Mosque', 'latitude' => '35.827061', 'longitude' => '10.639773', 'prayer_start' => '12:30', 'prayer_start_confirmations' => 4, 'prayer_end' => '12:50', 'prayer_end_confirmations' => 1, 'interior_space' => 3.5, 'interior_space_confirmations' => 1, 'parking_space' => 1.6, 'parking_space_confirmations' => 4, 'address' => 'Rue Othmane Osmane, Sousse', 'state' => $sousse->id]);
     $mosque3 = Mosque::create(['name' => 'Al-Fath Mosque', 'second_name' => 'Mosqué Al Fath', 'latitude' => '35.842952', 'longitude' => '10.617726', 'prayer_start' => '13:00', 'prayer_start_confirmations' => 12, 'prayer_end' => '13:45', 'prayer_end_confirmations' => 5, 'interior_space' => 4.8, 'interior_space_confirmations' => 10, 'parking_space' => 4.3, 'parking_space_confirmations' => 4, 'address' => '', 'city' => $jawhara->id, 'state' => $sousse->id]);
     $mosque4 = Mosque::create(['name' => 'Mosquee assabr', 'second_name' => 'Mosquee assabr', 'latitude' => '35.842986', 'longitude' => '10.597665', 'prayer_start' => '12:50', 'prayer_start_confirmations' => 4, 'prayer_end' => '13:15', 'prayer_end_confirmations' => 4, 'interior_space' => 2.2, 'interior_space_confirmations' => 5, 'parking_space' => 1, 'parking_space_confirmations' => 1, 'address' => 'Hammam Sousse', 'city' => $sahloul->id, 'state' => $sousse->id]);
     $mosque5 = Mosque::create(['name' => 'Fatima Ez-Zahra Mosque', 'second_name' => 'Fatima Ez-Zahra Mosque', 'latitude' => '35.842307', 'longitude' => '10.588133', 'prayer_start' => '13:20', 'prayer_start_confirmations' => 17, 'prayer_end' => '14:00', 'prayer_end_confirmations' => 8, 'interior_space' => 2.6, 'interior_space_confirmations' => 3, 'parking_space' => null, 'parking_space_confirmations' => 0, 'address' => 'Sahloul, Sousse', 'city' => $sahloul->id, 'state' => $sousse->id]);
     $mosque6 = Mosque::create(['name' => 'Mosquée El Salam', 'second_name' => '', 'latitude' => '36.859904', 'longitude' => '10.163426', 'prayer_start' => '13:10', 'prayer_start_confirmations' => 21, 'prayer_end' => '13:35', 'prayer_end_confirmations' => 10, 'interior_space' => 3.1, 'interior_space_confirmations' => 17, 'parking_space' => 4.9, 'parking_space_confirmations' => 28, 'address' => 'Ennasr, Ariana', 'city' => $ennasr->id, 'state' => $ennasr['parent']]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $this->validate($request, ['city_id' => 'integer|exists:city,id', 'tag_id' => 'integer|exists:tag,id', 'type' => 'string|in:' . implode(',', Place::types())]);
     if ($request->has('city_id')) {
         $city = City::find($request->input('city_id'));
     } else {
         $city = City::where('geoname_id', 658225)->first();
         if (!count($city)) {
             $city = City::first();
         }
     }
     $query = Place::where('city_id', $city->id);
     if ($request->has('search')) {
         $words = explode(" ", $request->input('search'));
         $query->whereHas('translations', function ($sub_query) use($words) {
             foreach ($words as $word) {
                 // If it is Chinese, use LIKE. Else, use full text index.
                 // http://www.regular-expressions.info/unicode.html#script
                 if (preg_match('/\\p{Han}+/u', $word)) {
                     $sub_query->where(function ($q) use($word) {
                         $q->where('name', 'like', '%' . $word . '%')->orWhere('content', 'like', '%' . $word . '%');
                     });
                 } else {
                     $sub_query->whereRaw('MATCH(name,content) AGAINST(? IN BOOLEAN MODE)', [$word . '*']);
                 }
             }
         });
     }
     if ($request->has('type')) {
         $query = $query->where('type', $request->input('type'));
     }
     if ($request->has('tag_id')) {
         $query = $query->whereHas('tags', function ($sub_query) use($request) {
             $sub_query->where('id', $request->input('tag_id'));
         });
     }
     $query->with('image');
     $places = $query->orderBy('like_count', 'desc')->paginate(24);
     return view('pages.place.index', ['places' => $places, 'city' => $city, 'type' => $request->input('type')]);
 }
Example #6
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $categoriesData = json_decode(file_get_contents("app/Jobs/categories.json"));
     DB::table('categories')->truncate();
     DB::table('ranks')->truncate();
     DB::table('places')->truncate();
     foreach ($categoriesData as $categoryData) {
         if (!isset($categoryData->parents) || !$categoryData->parents) {
             continue;
         }
         if (!in_array("restaurants", $categoryData->parents)) {
             continue;
         }
         Category::create(['name' => $categoryData->title, 'code' => $categoryData->alias]);
     }
     $allCities = City::all();
     foreach ($allCities as $city) {
         Log::info('City: ' . $city->name);
         $allCategories = Category::all();
         foreach ($allCategories as $category) {
             $yelp = new Yelp();
             Log::info('Category: ' . $category->code);
             $businesses = $yelp->best($category->code, $city->name . ', ' . $city->country);
             for ($i = 0; $i < count($businesses); $i++) {
                 $business = $businesses[$i];
                 if (!isset($business->location->coordinate)) {
                     continue;
                 }
                 Log::info('Business: ' . $business->name);
                 $place = Place::where('name', '=', $business->name)->first();
                 if (!$place) {
                     $place = Place::create(['name' => $business->name, 'image_url' => $this->getImageUrl($business), 'external_url' => $business->mobile_url, 'description' => $this->getDescription($business), 'rating' => $business->rating, 'latitude' => $business->location->coordinate->latitude, 'longitude' => $business->location->coordinate->longitude, 'address' => join(', ', $business->location->display_address), 'city_id' => $city->id]);
                 }
                 Rank::create(['category_id' => $category->id, 'place_id' => $place->id, 'rank' => $i + 1, 'city_id' => $city->id]);
             }
             sleep(1);
         }
     }
 }
Example #7
0
 public function index()
 {
     $places = Place::where('status', '=', Place::GEOLOCALIZED)->get();
     return response()->geojson($places);
 }
Example #8
0
 public static function getPlaceById($place_id)
 {
     return Place::where('name', $place_id);
 }
Example #9
0
 /**
 * Url:
 * /public/api/v1.0/update/bus/destination/{dropping_id}
 * 
 * Payload:
    {
        "params": {
            "buses_id": 27,
            "bus_departure_points_id": 5,
            "dropping_point": "Tada",
            "dropping_time": "9am",
            "price": "1003"
        }
    }
 */
 public function updateDroppingDetails(Request $request)
 {
     $data = Input::json()->all();
     $response = $this->response;
     $validateAndHandleError = new ValidateAndHandleError();
     if (!Auth::user()->id) {
         return $validateAndHandleError->invalidUser();
     }
     if (!$request->route('dropping_id')) {
         return $response->errorResponse("dropping_id_not_exist");
     }
     $dropping_id = $request->route('dropping_id');
     if (!isset($data) || !isset($data['params']) || !isset($data['params']['buses_id']) || !isset($data['params']['bus_departure_points_id']) || !isset($data['params']['dropping_point']) || !isset($data['params']['place_id']) || !isset($data['params']['dropping_time']) || !isset($data['params']['price'])) {
         return $response->errorResponse('invalid_params');
         //                return $validateAndHandleError->errorIdentifier("invalid_params");
     }
     $buses_id = $data['params']['buses_id'];
     $bus_departure_points_id = $data['params']['bus_departure_points_id'];
     $dropping_point = $data['params']['dropping_point'];
     $dropping_time = $data['params']['dropping_time'];
     $place_id = $data['params']['place_id'];
     $price = $data['params']['price'];
     /* Null validation */
     $validateNullData = array("buses_id" => $buses_id, "bus_departure_points_id" => $bus_departure_points_id, "dropping_point" => $dropping_point, "dropping_time" => $dropping_time, "price" => $price, "place_id" => $place_id);
     $nullValidator = $validateAndHandleError->multiValidator($validateNullData, "string");
     if ($nullValidator != "success") {
         return $nullValidator;
     }
     /* Bus id is number or not */
     $validateBusId = $validateAndHandleError->multiValidator(['buses_id' => $buses_id, 'dropping_id_not_number' => $dropping_id, 'place_id' => $place_id, 'departure_id_not_number' => $bus_departure_points_id], "number");
     if ($validateBusId != "success") {
         return $validateBusId;
     }
     $place = Place::where('id', $place_id)->get()[0]->place;
     if ($place != $dropping_point) {
         return $response->errorResponse('to_place_mismatch');
         //                return $validateAndHandleError->errorIdentifier("to_place_mismatch");
     }
     /* Validate dropping id present in db or not */
     $check_dropping_id = BusDroppingPoint::where('id', $dropping_id)->get();
     if (count($check_dropping_id) <= 0) {
         return $response->errorResponse("dropping_details_not_available");
     }
     /* for this dropping id check bus_id and departure id is matching or not */
     if ($check_dropping_id[0]->buses_id != $buses_id || $check_dropping_id[0]->bus_departure_points_id != $bus_departure_points_id) {
         return $response->errorResponse("bus_id_and_departure_id_mismatch");
     }
     /* Bus id exist or not */
     $check_bus_availability = Bus::where('id', $buses_id)->get();
     if (count($check_bus_availability) <= 0) {
         return $response->errorResponse("bus_details_not_available");
     }
     /* Departure id exist or not */
     $prev_departure_details = BusDeparturePoint::where('id', $bus_departure_points_id)->get();
     if (count($prev_departure_details) <= 0) {
         return $response->errorResponse('bus_departure_details_does_not_exist');
         //                return $validateAndHandleError->errorIdentifier("bus_departure_details_does_not_exist");
     }
     /* bus id passed through param should be equal with bus id of db */
     if ($prev_departure_details[0]->buses_id != $buses_id) {
         return $response->errorResponse('invalid_departure_details');
         //                return $validateAndHandleError->errorIdentifier("invalid_departure_details");
     }
     $user_id = Auth::user()->id;
     $bus_owners_id = $check_bus_availability[0]->bus_owners_id;
     /* $user_id_temp is used to check whether the details are accessible or not */
     $user_id_temp = BusOwner::where('id', $bus_owners_id)->get()[0]->user_id;
     $user_type = $validateAndHandleError->userIdentifier($user_id);
     /* details are only accessible by admin and bus owner */
     if ($user_type == "customer" || $user_type == "dealer" || $user_type == "unknown" || $user_type == "bus_owner" && $user_id_temp != $user_id) {
         return $response->errorResponse("details_not_accessible");
     }
     $is_dropping_details_updated = BusDroppingPoint::where('id', $dropping_id)->where('buses_id', $buses_id)->where('bus_departure_points_id', $bus_departure_points_id)->update(['dropping_point' => $dropping_point, 'dropping_time' => $dropping_time, 'price' => $price]);
     $info = array('bus_dropping_id' => $dropping_id, 'bus_id' => $buses_id, 'bus_owners_id' => $bus_owners_id, 'departure_id' => $bus_departure_points_id, 'dropping_point' => $dropping_point, 'dropping_time' => $dropping_time, 'price' => $price);
     if ($is_dropping_details_updated == 1) {
         return $response->successResponse(200, "Bus dropping details has been updated successully", $info);
     }
     return $response->errorResponse("update_unsuccessfull");
 }
Example #10
0
 /**
  * Update the specified event in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $event = Event::findOrFail($id);
     $event->name = $request->name;
     $event->description = $request->description;
     $convert_date = date("Y-m-d", strtotime($request->date_start));
     $event->date_start = $convert_date;
     if ($request->date_end) {
         $convert_date = date("Y-m-d", strtotime($request->date_end));
         $event->date_end = $convert_date;
     }
     if ($request->id != null) {
         $place = Place::where('id', '=', $request->id)->first();
         if (!$place) {
             $place = new Place($request->only(['id', 'place_lat', 'place_lng', 'country', 'state', 'city']));
             $place->save();
         }
         $event_place = EventPlace::where('event_id', '=', $id);
         if (!$event_place) {
             $event_place = new EventPlace();
             $event_place->event_id = $id;
             $event_place->place_id = $place->id;
             $event_place->save();
         }
     }
     if (\Input::hasFile('img')) {
         $file = \Input::file('img');
         $filename = '';
         if ($event->photo == '../../default_photo.jpg') {
             $name = str_random(32);
             while (!User::where('avatar', '=', $name . $file->getClientOriginalExtension())->get()->isEmpty()) {
                 $name = str_random(32);
             }
             $filename = $name . '.' . $file->getClientOriginalExtension();
             $event->photo = $filename;
         } else {
             $filename = $event->photo;
         }
         $file->move(public_path() . '/img/events_large', $filename);
         Image::make(public_path() . '/img/events_large/' . $filename)->fit(1024, 576)->save();
         Image::make(public_path() . '/img/events_large/' . $filename)->resize(300, 169)->save(public_path() . '/img/events/' . $filename);
     }
     $event->save();
     \Session::flash('message', 'Event updated successfully');
     return redirect()->route('events.show', $id);
 }
Example #11
0
 /**
  * Add a place visited to the users profile.
  */
 public function beenPlace(Requests\visitedPlaceRequest $request)
 {
     if ($request->id) {
         $place = Place::where('id', '=', $request->id)->first();
         if (!$place) {
             $place = new Place($request->only(['id', 'place_lat', 'place_lng', 'country', 'state', 'city']));
             $place->save();
         }
         $pv = new PlaceVisited();
         $pv->user_id = \Auth::id();
         $pv->place_id = $request->id;
         $pv->save();
     }
     return redirect()->route('myplaces');
 }
 public function arrivalAndDestinationVerifier($to_place_id, $from_place_id, $bus_from, $bus_to)
 {
     $response = $this->response;
     if ($to_place_id == $from_place_id) {
         return $response->errorResponse('from_and_to_id_same');
         //            return $this->errorIdentifier("from_and_to_id_same");
     }
     $from_place = Place::where('id', $from_place_id)->get()[0]->place;
     $to_place = Place::where('id', $to_place_id)->get()[0]->place;
     if ($from_place != $bus_from) {
         return $response->errorResponse('from_place_mismatch');
         //            return $this->errorIdentifier("from_place_mismatch");
     }
     if ($to_place != $bus_to) {
         return $response->errorResponse('to_place_mismatch');
         //            return $this->errorIdentifier("to_place_mismatch");
     }
     return TRUE;
 }
Example #13
0
 /**
  * Search for events and shows the search screen.
  *
  * @return Response
  */
 public function scanEvents($id = null)
 {
     $events = null;
     if ($id) {
         $place = Place::where('id', $id)->first();
         $events = Event::where('date_start', '>=', new \DateTime('today'))->orderBy('date_start')->with(['places'])->get();
         foreach ($events as $event) {
             if ($place->id != '' && $event->places[0]->id == $place->id) {
                 $event->grade = 1;
             } else {
                 if ($place->state != '' && $event->places[0]->state == $place->state) {
                     $event->grade = 2;
                 } else {
                     if ($place->country != '' && $event->places[0]->country == $place->country) {
                         $event->grade = 3;
                     }
                 }
             }
         }
         $events = $events->filter(function ($event) {
             if ($event->grade) {
                 return true;
             }
         });
         $events = $events->toArray();
         // sort alphabetically by grade
         usort($events, array($this, 'compare_events'));
         $events = Collection::make($events);
         //Get current page form url e.g. &page=6
         $currentPage = (int) LengthAwarePaginator::resolveCurrentPage(1);
         if (!$currentPage) {
             $currentPage = 1;
         }
         $currentPage--;
         //Define how many items we want to be visible in each page
         $perPage = 12;
         //Slice the collection to get the items to display in current page
         $currentPageEvents = $events->slice($currentPage * $perPage, $perPage)->all();
         $events = new LengthAwarePaginator($currentPageEvents, count($events), $perPage);
         $events->setPath('/scanner/' . $id);
     }
     return view('scan', compact('events'));
 }