Skip to content

Commit

Permalink
Add/value to active state videopress card (#38812)
Browse files Browse the repository at this point in the history
* Add value to active state of VideoPress card

* changelog

* Return videoCount if error on featured stats call

* Update time format to accomodate years

* Update definition of videopress active

* Show stats if user has videos

* Simplify logic of videopress value section

* Left align protect headings per design

* Update monthly views heading to 30-day views

* Add transient

* Specify transient key to my jetpack

* Fixup project versions

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/10407134305

Upstream-Ref: Automattic/jetpack@7015560
  • Loading branch information
CodeyGuyDylan authored and matticbot committed Aug 15, 2024
1 parent 4e74514 commit ad6a239
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This is an alpha version! The changes listed here are not final.

### Added
- Add value to active card state on VideoPress My Jetpack card

### Changed
- Updated package dependencies.

Expand Down
16 changes: 10 additions & 6 deletions src/class-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public static function get_today_plays() {
/**
* Returns the featured stats for VideoPress.
*
* @param int $days (optional) The number of days to consider.
*
* @return array|WP_Error a list of stats, or WP_Error on failure.
*/
public static function get_featured_stats() {
public static function get_featured_stats( $days = 14 ) {
$response = self::fetch_video_plays(
array(
'period' => 'day',
'num' => 14,
'num' => $days,
'complete_stats' => true,
)
);
Expand All @@ -115,16 +117,17 @@ public static function get_featured_stats() {
$dates = $data['days'];

// Organize the data into the planned stats
return self::prepare_featured_stats( $dates );
return self::prepare_featured_stats( $dates, $days );
}

/**
* Prepares the featured stats for VideoPress.
*
* @param array $dates The list of dates returned by the API.
* @param int $total_days The total number of days to consider.
* @return array a list of stats.
*/
public static function prepare_featured_stats( $dates ) {
public static function prepare_featured_stats( $dates, $total_days ) {
/**
* Ensure the sorting of the dates, recent ones first.
* This way, the first 7 positions are from the last 7 days,
Expand All @@ -134,7 +137,8 @@ public static function prepare_featured_stats( $dates ) {

// template for the response
$featured_stats = array(
'label' => __( 'last 7 days', 'jetpack-videopress-pkg' ),
// translators: %d is the number of days
'label' => sprintf( __( 'last %d days', 'jetpack-videopress-pkg' ), floor( $total_days / 2 ) ),
'data' => array(
'views' => array(
'current' => 0,
Expand All @@ -156,7 +160,7 @@ public static function prepare_featured_stats( $dates ) {
foreach ( $dates as $date_info ) {
$date_totals = $date_info['total'];

if ( $counter < 7 ) {
if ( $counter < floor( $total_days / 2 ) ) {

// the first 7 elements are for the current period
$featured_stats['data']['views']['current'] += $date_totals['views'];
Expand Down

0 comments on commit ad6a239

Please sign in to comment.