Added calories

This commit is contained in:
Justin Foell
2021-04-30 13:15:16 -05:00
parent d0d12d25e6
commit c90d5c6d28
6 changed files with 55 additions and 3 deletions
+8 -1
View File
@@ -48,7 +48,9 @@ class WPStrava_ActivitiesListRenderer {
}
$response = "<ul id='activities'>";
foreach ( $activities as $activity ) {
foreach ( $activities as $activity_summary ) {
// Re-get single activity for greater detail (will be cached).
$activity = $strava_activity->get_activity( $atts['client_id'], $activity_summary->id );
$response .= "<li class='activity'>";
$response .= empty( $activity->id ) ?
$activity->name : $strava_activity->get_activity_link( $activity->id, $activity->name );
@@ -81,6 +83,11 @@ class WPStrava_ActivitiesListRenderer {
$response .= sprintf( __( ' climbing %1$s %2$s', 'wp-strava' ), $som->elevation( $activity->total_elevation_gain ), $som->get_elevation_label() );
}
if ( $activity->calories ) {
// Translators: "burning 200 calories."
$response .= sprintf( __( ' burning %1$s calories.', 'wp-strava' ), $som->calories( $activity->calories ) );
}
$response .= '</div></li>';
}
$response .= '</ul>';
+12
View File
@@ -90,6 +90,8 @@ class WPStrava_ActivityRenderer {
</td>';
$avg_speed = '';
$max_speed = '';
$calories_title = '';
$calories = '';
switch ( $strava_activitytype ) {
case WPStrava_ActivityType::TYPE_GROUP_PACE:
@@ -130,6 +132,14 @@ class WPStrava_ActivityRenderer {
$elevation = '';
}
if ( $activity_details->calories ) {
$calories_title = '<th>' . __( 'Calories Burned', 'wp-strava' ) . '</th>';
$calories = '<td data-label="' . __( 'Calories Burned', 'wp-strava' ) . '">
<div class="activity-details-table-info">' . $strava_som->calories( $activity_details->calories ) . '</div>
<div class="activity-details-table-units">' . $strava_som->get_calories_label() . '</div>
</td>';
}
return '
<table class="activity-details-table">
<thead>
@@ -140,6 +150,7 @@ class WPStrava_ActivityRenderer {
' . $avg_title . '
' . $max_title . '
' . $elevation_title . '
' . $calories_title . '
</tr>
</thead>
<tbody>
@@ -159,6 +170,7 @@ class WPStrava_ActivityRenderer {
' . $avg_speed . '
' . $max_speed . '
' . $elevation . '
' . $calories . '
</tr>
</tbody>
</table>
+1 -1
View File
@@ -65,7 +65,7 @@ class WPStrava_AuthRefresh extends WPStrava_Auth {
'client_id' => $client_id,
'redirect_uri' => $this->get_redirect_param(),
'approval_prompt' => 'auto',
'scope' => 'activity:read,read',
'scope' => 'read,activity:read',
),
$this->auth_url
);
+22
View File
@@ -77,4 +77,26 @@ abstract class WPStrava_SOM {
return "{$min}:{$sec}";
}
/**
* Format calories to add appropriate comma.
*
* @param string|int $kcal Kilocalories
* @author Justin Foell <justin@foell.org>
* @since 2.9.0
*/
public function calories( $kcal ) {
return number_format_i18n( $kcal, 0 );
}
/**
* Abbreviated label for kilocalories.
*
* @return string
* @author Justin Foell <justin@foell.org>
* @since 2.9.0
*/
public function get_calories_label() {
return __( 'kcal', 'wp-strava' );
}
}