public function scanIsInsideParcel() { $this->middleware('auth'); $pointLocation = new PointLocation(); $events = Event::take(1000)->orderBy('dateGps', 'ASC')->get(); foreach ($events as $key => $value) { $latLonEvent = $value->lat . "," . $value->lon; $event = $value; $parcels = Parcel::orderByRaw('lat - ' . $value->lat . '', 'ASC')->take(20)->get(); foreach ($parcels as $key => $value) { $isPointInside = 0; $parcelsGps = ParcelGps::where('idparcel', $value->id)->orderBy('number', 'ASC')->get(); $polygon = array(); foreach ($parcelsGps as $key => $value) { $latlng = "" . $value->lat . ", " . $value->long . ""; $idparcelEvent = $value->idparcel; array_push($polygon, $latlng); } $isPointInside = $pointLocation->pointInPolygon($latLonEvent, $polygon, $event, $idparcelEvent); if ($isPointInside == 1) { $event = Event::find($event->id); $event->isSync = 1; $event->isInside = 1; $event->idParcelle = $idparcelEvent; $event->save(); $eventprocessed = new ProcessedEvents(); $eventprocessed->idApp = $event->idApp; $eventprocessed->idUser = $event->idUser; $eventprocessed->name = $event->name; $eventprocessed->lon = $event->lon; $eventprocessed->lat = $event->lat; $eventprocessed->dateGps = $event->dateGps; $eventprocessed->timeDate = $event->timeDate; $eventprocessed->isInside = $event->isInside; $eventprocessed->idParcelle = $event->idParcelle; $eventprocessed->altitude = $event->altitude; $eventprocessed->isSync = $event->isSync; $eventprocessed->save(); break; } if ($isPointInside == 0) { $event = Event::find($event->id); $event->isSync = 1; $event->isInside = 0; $event->idParcelle = 0; $event->save(); } } } }
/** * Get all the parcels sent by the authenticated user * @return mixed */ public function getUserSentParcels() { return $this->parcel->where('user_id', '=', \Auth::user()->id)->where('parcelPendingStatus', '=', 1); }
public function showParcelsEventsForm(Request $request) { $user = $request->user; $daterange = $request->daterange; $dateStart = $request->dateStart; $dateEnd = $request->dateEnd; $events = Event::where('idUser', $user)->where('idUser', $user)->whereBetween('dateGps', [$dateStart, $dateEnd])->get(); $users = User::all(); $parcels = Parcel::all(); $parcelsGpsArray = []; foreach ($parcels as $key => $value) { $parcelsGps = ParcelGps::where('idparcel', $value->id)->orderBy('number')->select('lat', 'long')->get(); array_push($parcelsGpsArray, $parcelsGps); } // load the view and pass the parcels return View::make('app.parcel.showevent')->with('parcels', $parcelsGpsArray)->with('events', $events)->with('users', $users)->with('user', $user); }