/** * Post one workout track to endomondo. * * @param Track $track * @return null|string * @throws \RuntimeException If the uploading stops at one point. */ private function postTrack(Track $track) { $deviceWorkoutId = '-' . $this->bigRandomNumber(19); $sport = $this->sportMapper->getCodeFromSport($track->getSport()); $duration = $track->getDuration()->getTotalSeconds(); $workoutId = null; $previousPoint = null; $distance = 0; $speed = 0; // Split in chunks of 100 points like the mobile app. foreach (array_chunk($track->getTrackPoints(), 100) as $trackPoints) { $data = array(); foreach ($trackPoints as $trackPoint) { /** @var \SportTrackerConnector\Workout\Workout\TrackPoint $trackPoint */ if ($trackPoint->hasDistance() === true) { $distance = $trackPoint->getDistance(); } elseif ($previousPoint !== null) { $distance += $trackPoint->distance($previousPoint); } if ($previousPoint !== null) { $speed = $trackPoint->speed($previousPoint); } $data[] = $this->flattenTrackPoint($trackPoint, $distance, $speed); $previousPoint = $trackPoint; } $workoutId = $this->postWorkoutData($deviceWorkoutId, $sport, $duration, $data); } // End of workout data. // $data = $this->flattenEndWorkoutTrackPoint($track, $speed); // $workoutId = $this->postWorkoutData($deviceWorkoutId, $sport, $duration, array($data)); return $workoutId; }