Exemplo n.º 1
0
 public function removePitstop()
 {
     if (isset($_POST['itineraryKey']) && isset($_POST['tripId']) && isset($_POST['placeId'])) {
         $itineraryKey = $_POST['itineraryKey'];
         $tripId = $_POST['tripId'];
         $placeId = $_POST['placeId'];
     } else {
         $baseURL = '../public/';
         return \View::make('trips')->with('baseURL', $baseURL);
     }
     $tripItinerary = Trip::getTrip($itineraryKey);
     if (empty($tripItinerary)) {
         $baseURL = '../public/';
         return \View::make('trips')->with('baseURL', $baseURL);
     }
     $pitStops = $tripItinerary[0]->trip_object;
     $pitStops = json_decode($pitStops);
     for ($i = 0; $i < sizeof($pitStops); $i++) {
         $places = $pitStops[$i]->places;
         if ($pitStops[$i]->places == '') {
             $places = null;
         }
         $pitStopObject[$i] = ['city' => $pitStops[$i]->city, 'formatted_address' => $pitStops[$i]->formatted_address, 'lat' => $pitStops[$i]->lat, 'lng' => $pitStops[$i]->lng, 'placeId' => $pitStops[$i]->placeId, 'id' => $tripId, 'key' => $itineraryKey, 'places' => $places];
     }
     $pitStops = $pitStopObject;
     $pitStops = str_replace("'", "", json_encode($pitStops));
     $baseURL = '../public/';
     $pitStops = json_decode($pitStops);
     if (isset($_POST['placesplaceId'])) {
         /* To Remove Place in Pitstop */
         $placesplaceId = $_POST['placesplaceId'];
         $removedId = null;
         $removedPlaceId = null;
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($pitStops[$i]->id == $tripId && $pitStops[$i]->placeId == $placeId) {
                 $removedId = $i;
                 for ($j = 0; $j < sizeof($pitStops[$i]->places); $j++) {
                     if ($pitStops[$i]->places[$j]->placeId == $placesplaceId) {
                         unset($pitStops[$i]->places[$j]);
                         $removedPlaceId = $j;
                     }
                 }
             }
         }
         $k = 0;
         $placesRemovedObject = null;
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($i == $removedId) {
                 for ($j = 0; $j < sizeof($pitStops[$i]->places); $j++) {
                     if ($j == $removedPlaceId) {
                         $k++;
                     }
                 }
             }
             if ($i == $removedId) {
                 for ($m = 0; $m < sizeof($pitStops[$removedId]->places); $m++) {
                     if ($m >= $removedPlaceId) {
                         if (isset($pitStops[$removedId]->places[$m + 1])) {
                             $placesRemovedObject[$m] = $pitStops[$removedId]->places[$m + 1];
                         }
                     } else {
                         $placesRemovedObject[$m] = $pitStops[$removedId]->places[$m];
                     }
                 }
                 $places = $placesRemovedObject;
                 $pitStops[$removedId]->places = $places;
             }
         }
         $pitStops = json_encode($pitStops);
         $updateTrip = Trip::updateTrip($tripId, $pitStops);
     } else {
         /* To Remove PitStop */
         $removedId = null;
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($pitStops[$i]->id == $tripId && $pitStops[$i]->placeId == $placeId) {
                 unset($pitStops[$i]);
                 $removedId = $i;
             }
         }
         $j = 0;
         if (sizeof($pitStops) == 0) {
             $baseURL = '../public/';
             return \View::make('trips')->with('baseURL', $baseURL);
         }
         /* If only two pitstop present */
         if (sizeof($pitStops) == 1) {
             Trip::deleteTrip($tripId);
             $baseURL = '../public/';
             return \View::make('trips')->with('baseURL', $baseURL);
         }
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($i == $removedId) {
                 $j++;
             }
             $places = $pitStops[$j]->places;
             if ($pitStops[$j]->places == '') {
                 $places = null;
             }
             $pitStopRemovedObject[$i] = ['city' => $pitStops[$j]->city, 'formatted_address' => $pitStops[$j]->formatted_address, 'lat' => $pitStops[$j]->lat, 'lng' => $pitStops[$j]->lng, 'placeId' => $pitStops[$j]->placeId, 'id' => $tripId, 'key' => $itineraryKey, 'places' => $places];
             $j++;
         }
         $pitStops = $pitStopRemovedObject;
         $pitStops = json_encode($pitStops);
         $updateTrip = Trip::updateTrip($tripId, $pitStops);
     }
     return \View::make('index')->with('pitStops', $pitStops)->with('itineraryKey', $itineraryKey)->with('tripId', $tripId)->with('errorMessage', '')->with('baseURL', $baseURL);
 }
Exemplo n.º 2
0
 public function removePitstop()
 {
     if (isset($_POST['itineraryKey']) && isset($_POST['tripId']) && isset($_POST['placeId'])) {
         $itineraryKey = $_POST['itineraryKey'];
         $tripId = $_POST['tripId'];
         $placeId = $_POST['placeId'];
     } else {
         $baseURL = '../public/';
         return \View::make('trips')->with('baseURL', $baseURL);
     }
     $tripItinerary = Trip::getTrip($itineraryKey);
     if (empty($tripItinerary)) {
         $jsonPitStops = $_POST['jsonPitStops'];
         $pitStops = json_decode($jsonPitStops);
         /*$baseURL = '../public/';	
         		return \View::make('trips')->with('baseURL', $baseURL);*/
     } else {
         $pitStops = $tripItinerary[0]->trip_object;
         $pitStops = json_decode($pitStops);
     }
     for ($i = 0; $i < sizeof($pitStops); $i++) {
         if (isset($pitStops[$i]->places)) {
             $places = $pitStops[$i]->places;
         } else {
             $places = [];
         }
         $pitStopObject[$i] = ['city' => $pitStops[$i]->city, 'formatted_address' => $pitStops[$i]->formatted_address, 'lat' => $pitStops[$i]->lat, 'lng' => $pitStops[$i]->lng, 'placeId' => $pitStops[$i]->placeId, 'id' => $tripId, 'key' => $itineraryKey, 'places' => $places];
     }
     $pitStops = $pitStopObject;
     $pitStops = str_replace("'", "", json_encode($pitStops));
     $baseURL = '../public/';
     $pitStops = json_decode($pitStops);
     if (isset($_POST['placesplaceId'])) {
         /* To Remove Place in Pitstop */
         $placesplaceId = $_POST['placesplaceId'];
         $removedId = null;
         $removedPlaceId = null;
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($pitStops[$i]->id == $tripId && $pitStops[$i]->placeId == $placeId) {
                 $removedId = $i;
                 for ($j = 0; $j < sizeof($pitStops[$i]->places); $j++) {
                     if ($pitStops[$i]->places[$j]->placeId == $placesplaceId) {
                         unset($pitStops[$i]->places[$j]);
                         $removedPlaceId = $j;
                     }
                 }
             }
         }
         $k = 0;
         $placesRemovedObject = null;
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($i == $removedId) {
                 for ($j = 0; $j < sizeof($pitStops[$i]->places); $j++) {
                     if ($j == $removedPlaceId) {
                         $k++;
                     }
                 }
             }
             if ($i == $removedId) {
                 for ($m = 0; $m < sizeof($pitStops[$removedId]->places); $m++) {
                     if ($m >= $removedPlaceId) {
                         if (isset($pitStops[$removedId]->places[$m + 1])) {
                             $placesRemovedObject[$m] = $pitStops[$removedId]->places[$m + 1];
                         }
                     } else {
                         $placesRemovedObject[$m] = $pitStops[$removedId]->places[$m];
                     }
                 }
                 $places = $placesRemovedObject;
                 $pitStops[$removedId]->places = $places;
             }
         }
         $pitStops = json_encode($pitStops);
         if ($tripId != 0) {
             $updateTrip = Trip::updateTrip($tripId, $pitStops);
         }
     } else {
         /* To Remove PitStop */
         $removedId = null;
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($pitStops[$i]->id == $tripId && $pitStops[$i]->placeId == $placeId) {
                 unset($pitStops[$i]);
                 $removedId = $i;
             }
         }
         $j = 0;
         if (sizeof($pitStops) == 0) {
             $baseURL = '../public/';
             return \View::make('trips')->with('baseURL', $baseURL);
         }
         /* If only two pitstop present */
         if (sizeof($pitStops) == 1) {
             Trip::deleteTrip($tripId);
             $baseURL = '../public/';
             return \View::make('trips')->with('baseURL', $baseURL);
         }
         for ($i = 0; $i < sizeof($pitStops); $i++) {
             if ($i == $removedId) {
                 $j++;
             }
             $places = $pitStops[$j]->places;
             if ($pitStops[$j]->places == '') {
                 $places = null;
             }
             $pitStopRemovedObject[$i] = ['city' => $pitStops[$j]->city, 'formatted_address' => $pitStops[$j]->formatted_address, 'lat' => $pitStops[$j]->lat, 'lng' => $pitStops[$j]->lng, 'placeId' => $pitStops[$j]->placeId, 'id' => $tripId, 'key' => $itineraryKey, 'places' => $places];
             $j++;
         }
         $pitStops = $pitStopRemovedObject;
         $pitStops = json_encode($pitStops);
         if ($tripId != 0) {
             $updateTrip = Trip::updateTrip($tripId, $pitStops);
         }
     }
     $jsonPitStops = $pitStops;
     $pitStops = json_decode($pitStops);
     $finalpitStopObject = null;
     for ($i = 0; $i < sizeof($pitStops); $i++) {
         $pitStopPlaceObject = null;
         for ($j = 0; $j < sizeof($pitStops[$i]->places); $j++) {
             $place = new Place();
             $place->setLat($pitStops[$i]->places[$j]->lat);
             $place->setLng($pitStops[$i]->places[$j]->lng);
             $place->setName($pitStops[$i]->places[$j]->name);
             $place->setPlaceId($pitStops[$i]->places[$j]->placeId);
             $place->setPriceLevel($pitStops[$i]->places[$j]->priceLevel);
             $place->setRating($pitStops[$i]->places[$j]->rating);
             $place->setOpenNow($pitStops[$i]->places[$j]->open_now);
             $place->setVicinity($pitStops[$i]->places[$j]->vicinity);
             $place->setTypes($pitStops[$i]->places[$j]->types);
             $pitStopPlaceObject[$j] = $place;
         }
         $pitStop = new Pitstop();
         $pitStop->setCity($pitStops[$i]->city);
         $pitStop->setFormattedAddress($pitStops[$i]->formatted_address);
         $pitStop->setLat($pitStops[$i]->lat);
         $pitStop->setLng($pitStops[$i]->lng);
         $pitStop->setPlaceId($pitStops[$i]->placeId);
         $pitStop->setPlaces($pitStopPlaceObject);
         $finalpitStopObject[$i] = $pitStop;
     }
     $pitStops = $finalpitStopObject;
     return \View::make('index')->with('pitStops', $pitStops)->with('itineraryKey', $itineraryKey)->with('tripId', $tripId)->with('jsonPitStops', $jsonPitStops)->with('errorMessage', '')->with('baseURL', $baseURL);
 }