/**
  * Dump a workout to string.
  *
  * @param Workout $workout The workout to dump.
  * @return string
  */
 public function dumpToString(Workout $workout)
 {
     $data = array();
     $tracks = $workout->getTracks();
     foreach ($tracks as $track) {
         $data[] = array('workout' => array('points' => $this->writeTrackPoints($track->getTrackpoints())));
     }
     return json_encode($data, JSON_PRETTY_PRINT);
 }
 /**
  * Write the tracks to the GPX.
  *
  * @param XMLWriter $xmlWriter The XML writer.
  * @param Workout $workout The workout.
  */
 protected function writeTracks(XMLWriter $xmlWriter, Workout $workout)
 {
     foreach ($workout->getTracks() as $track) {
         $xmlWriter->startElement('trk');
         $xmlWriter->writeElement('type', $track->getSport());
         $xmlWriter->startElement('trkseg');
         $this->writeTrackPoints($xmlWriter, $track->getTrackpoints());
         $xmlWriter->endElement();
         $xmlWriter->endElement();
     }
 }
 /**
  * Write the tracks to the TCX.
  *
  * @param XMLWriter $xmlWriter The XML writer.
  * @param Workout $workout The workout.
  */
 protected function writeTracks(XMLWriter $xmlWriter, Workout $workout)
 {
     $xmlWriter->startElement('Activities');
     foreach ($workout->getTracks() as $track) {
         $xmlWriter->startElement('Activity');
         $xmlWriter->writeAttribute('Sport', ucfirst($track->getSport()));
         // Use the start date time as the ID. This could be anything.
         $xmlWriter->writeElement('Id', $this->formatDateTime($track->getStartDateTime()));
         $xmlWriter->startElement('Lap');
         $xmlWriter->writeAttribute('StartTime', $this->formatDateTime($track->getStartDateTime()));
         $xmlWriter->writeElement('TotalTimeSeconds', $track->getDuration()->getTotalSeconds());
         $xmlWriter->writeElement('DistanceMeters', $track->getLength());
         $this->writeLapHeartRateDate($xmlWriter, $track);
         $xmlWriter->startElement('Track');
         $this->writeTrackPoints($xmlWriter, $track->getTrackpoints());
         $xmlWriter->endElement();
         $xmlWriter->endElement();
         $xmlWriter->endElement();
     }
     $xmlWriter->endElement();
 }
 /**
  * Post a workout to endomondo.
  *
  * Each track of a workout is uploaded individually.
  *
  * @param Workout $workout
  * @return array IDs of the workouts posted on endomondo.
  */
 public function postWorkout(Workout $workout)
 {
     $workoutIds = array();
     foreach ($workout->getTracks() as $track) {
         $workoutIds[] = $this->postTrack($track);
     }
     return $workoutIds;
 }