/**
  * Get a track point.
  *
  * @param string $lat The latitude.
  * @param string $lon The longitude.
  * @param string $time The time.
  * @param integer $ele The elevation.
  * @param integer $hr The heart rate.
  * @return TrackPoint
  */
 private function getTrackPoint($lat, $lon, $time, $ele, $hr)
 {
     $trackPoint = new TrackPoint($lat, $lon, new DateTime($time));
     $trackPoint->setElevation($ele);
     $trackPoint->addExtension(new HR($hr));
     return $trackPoint;
 }
 /**
  * Get a track point mock.
  *
  * @param float $latitude The latitude.
  * @param float $longitude The longitude.
  * @param string $dateTime The date and time of the point.
  * @param integer $elevation The elevation (in meters).
  * @param integer $hr The hear rate.
  * @return \SportTrackerConnector\Workout\Workout\TrackPoint
  */
 private function getTrackPoint($latitude, $longitude, $dateTime, $elevation = null, $hr = null)
 {
     $trackPoint = new TrackPoint($latitude, $longitude, new \DateTime($dateTime, new \DateTimeZone('UTC')));
     if ($elevation !== null) {
         $trackPoint->setElevation($elevation);
     }
     if ($hr !== null) {
         $trackPoint->addExtension(new HR($hr));
     }
     return $trackPoint;
 }
 /**
  * Test get extension success.
  */
 public function testGetExtensionSuccess()
 {
     $trackPoint = new TrackPoint(null, null, new DateTime());
     $idExtension = 'existing-extension';
     $extensionMock = $this->getExtensionMock($idExtension);
     $trackPoint->addExtension($extensionMock);
     $this->assertSame($extensionMock, $trackPoint->getExtension($idExtension));
 }
 /**
  * Download a workout.
  *
  * @param integer $idWorkout The ID of the workout to download.
  * @return Workout
  */
 public function downloadWorkout($idWorkout)
 {
     $this->logger->debug('Downloading JSON summary for workout "' . $idWorkout . '"');
     $workout = new Workout();
     $track = new Track();
     try {
         $workoutDetails = $this->getStravaAPI()->getWorkout($idWorkout);
         $this->logger->debug('Writing track points.');
         $pointsSize = count(reset($workoutDetails));
         for ($i = 0; $i < $pointsSize; $i++) {
             $latitude = $workoutDetails['latlng'][$i][0];
             $longitude = $workoutDetails['latlng'][$i][1];
             $dateTime = $workoutDetails['time'][$i];
             $dateTime->setTimezone($this->getTimeZone());
             $trackPoint = new TrackPoint($latitude, $longitude, $dateTime);
             if (isset($workoutDetails['altitude'])) {
                 $trackPoint->setElevation($workoutDetails['altitude'][$i]);
             }
             if (isset($workoutDetails['heartrate'])) {
                 $trackPoint->addExtension(new HR($workoutDetails['heartrate'][$i]));
             }
             $track->addTrackPoint($trackPoint);
         }
     } catch (NoTrackPointsFoundException $e) {
         $this->logger->warning('No track points found for workout "' . $idWorkout . '".');
     }
     $workout->addTrack($track);
     return $workout;
 }
 /**
  * Download a workout.
  *
  * @param integer $idWorkout The ID of the workout to download.
  * @return Workout
  */
 public function downloadWorkout($idWorkout)
 {
     $this->logger->debug('Downloading JSON for workout "' . $idWorkout . '"');
     $json = $this->getEndomondoAPI()->getWorkout($idWorkout);
     $workout = new Workout();
     $track = new Track();
     $track->setSport($this->getSportMapper()->getSportFromCode($json['sport']));
     if (isset($json['points'])) {
         $this->logger->debug('Writing track points.');
         foreach ($json['points'] as $point) {
             $trackPoint = new TrackPoint($point['lat'], $point['lng'], new DateTime($point['time'], $this->getTimeZone()));
             if (isset($point['alt'])) {
                 $trackPoint->setElevation($point['alt']);
             }
             if (isset($point['hr'])) {
                 $trackPoint->addExtension(new HR($point['hr']));
             }
             $track->addTrackPoint($trackPoint);
         }
     } else {
         $this->logger->warning('No track points found for workout "' . $idWorkout . '".');
     }
     $workout->addTrack($track);
     return $workout;
 }