Ejemplo n.º 1
0
 /**
  * @covers YAYOG\History::addWorkout
  * @covers YAYOG\History::getWorkouts
  */
 public function testAddWorkout()
 {
     $workouts = array(new Workout(), new Workout(), new Workout());
     foreach ($workouts as $workout) {
         $this->history->addWorkout($workout);
     }
     $this->assertSame($workouts, $this->history->getWorkouts());
 }
Ejemplo n.º 2
0
 /**
  * Creates and returns the HTML used to display the provided history, including the exercises
  * for each workout, a comparison with previous workouts and the javascript data.
  *
  * @param History $history The history to render
  * @return string HTML string of the workouts
  */
 public function renderHistory(History $history)
 {
     $workouts = $history->getWorkouts();
     $renderedWorkouts = array();
     $chartData = array('current' => array(), 'prev' => array());
     $prevTimestamp = null;
     foreach ($workouts as $workout) {
         $date = $workout->getDate();
         $timestamp = ($date->getTimestamp() + (int) $date->format('Z')) * 1000;
         $renderedWorkouts[] = sprintf('<h3 id="workout-%s">%s <small>(%s)&ensp;%s</small></h3>%s', $workout->getId(), $workout->getLabel(), $this->renderRelativeDate($date), $this->renderType($workout->getType()), $this->renderExercises($workout->getExercises()));
         // create a break if the previous workout was more than 5 days ago
         if ($prevTimestamp && $timestamp - $prevTimestamp > 432000000) {
             $chartData['current'][] = array($timestamp - 1, null);
             if (count($chartData['prev'])) {
                 $chartData['prev'][] = array($timestamp - 1, null);
             }
         }
         $prevWorkout = $workout->getPreviousWorkout();
         if ($prevWorkout) {
             $chartData['prev'][] = array($timestamp, $prevWorkout->getTotalReps());
         }
         $chartData['current'][] = array('name' => $workout->getLabel(), 'id' => $workout->getId(), 'x' => $timestamp, 'y' => $workout->getTotalReps());
         $prevTimestamp = $timestamp;
     }
     $js = '<script type="text/javascript">var chartData = ' . json_encode($chartData) . ';</script>';
     return '<div>' . join('', array_reverse($renderedWorkouts)) . '</div>' . $js;
 }