@@ -423,107 +423,6 @@ public function update_instructor_meta( int $user_id ) {
423423 do_action ( 'tutor_new_instructor_after ' , $ user_id );
424424 }
425425
426- /**
427- * Generate a comparison subtitle for a stat card.
428- * If no date range is provided, the subtitle defaults to "this month".
429- *
430- * @since 4.0.0
431- *
432- * @param string $start_date Selected start date (Y-m-d).
433- * @param string $end_date Selected end date (Y-m-d).
434- * @param float $current_data Current period value.
435- * @param float $previous_data Previous period value.
436- * @param bool $price Whether to format the difference as a price.
437- *
438- * @return string Comparison subtitle string.
439- */
440- public static function get_stat_card_comparison_subtitle (
441- string $ start_date ,
442- string $ end_date ,
443- float $ current_data ,
444- float $ previous_data ,
445- bool $ price = true
446- ): string {
447-
448- $ diff = ! empty ( $ start_date ) && ! empty ( $ end_date ) ? $ current_data - $ previous_data : $ previous_data ;
449- $ symbol = $ diff < 0 ? '- ' : ( $ diff > 0 ? '+ ' : '' );
450- $ diff = $ price ? tutor_utils ()->tutor_price ( abs ( $ diff ) ) : abs ( $ diff );
451-
452- $ start = new DateTime ( $ start_date );
453- $ end = new DateTime ( $ end_date );
454- $ days = (int ) $ start ->diff ( $ end )->days ;
455-
456- $ time_span = empty ( $ start_date ) && empty ( $ end_date )
457- ? __ ( 'this month ' , 'tutor ' )
458- : self ::get_comparison_period_label ( $ start_date , $ end_date , $ days );
459-
460- return "{$ symbol }{$ diff } {$ time_span }" ;
461- }
462-
463- /**
464- * Get a human-readable label for a comparison date range.
465- *
466- * @since 4.0.0
467- *
468- * @param string $start_date Start date (Y-m-d).
469- * @param string $end_date End date (Y-m-d).
470- * @param int $days Number of days between start and end dates.
471- *
472- * @return string Comparison period label.
473- */
474- public static function get_comparison_period_label ( string $ start_date , string $ end_date , int $ days ): string {
475-
476- $ time_zone = wp_timezone ();
477- $ format = DateTimeHelper::FORMAT_DATE ;
478- $ now = DateTimeHelper::now ()->set_timezone ( $ time_zone );
479- $ today = $ now ->format ( $ format );
480-
481- $ this_month_start = $ now ->create ( 'first day of this month ' )->format ( $ format );
482- $ this_month_end = $ now ->create ( 'last day of this month ' )->format ( $ format );
483-
484- $ last_month_start = $ now ->create ( 'first day of last month ' )->format ( $ format );
485- $ last_month_end = $ now ->create ( 'last day of last month ' )->format ( $ format );
486-
487- $ last_year_start = $ now ->create ( 'first day of January last year ' )->format ( $ format );
488- $ last_year_end = $ now ->create ( 'last day of December last year ' )->format ( $ format );
489-
490- if ( $ start_date === $ today && $ end_date === $ today ) {
491- return __ ( 'today ' , 'tutor ' );
492- }
493-
494- switch ( true ) {
495-
496- case ( 0 === $ days && $ today !== $ start_date ):
497- return __ ( 'from yesterday ' , 'tutor ' );
498-
499- case ( 6 === $ days ):
500- return __ ( 'from last 7 days ' , 'tutor ' );
501-
502- case ( 13 === $ days ):
503- return __ ( 'from last 14 days ' , 'tutor ' );
504-
505- case ( 29 === $ days ):
506- return __ ( 'from last 30 days ' , 'tutor ' );
507-
508- case ( $ start_date === $ this_month_start && $ end_date === $ this_month_end ):
509- return __ ( 'from this month ' , 'tutor ' );
510-
511- case ( $ start_date === $ last_month_start && $ end_date === $ last_month_end ):
512- return __ ( 'from last month ' , 'tutor ' );
513-
514- case ( $ start_date === $ last_year_start && $ end_date === $ last_year_end ):
515- return __ ( 'from last year ' , 'tutor ' );
516-
517- default :
518- return sprintf (
519- /* translators: 1: formatted start date, 2: formatted end date */
520- __ ( 'from %1$s–%2$s ' , 'tutor ' ),
521- wp_date ( 'M j ' , strtotime ( $ start_date ), $ time_zone ),
522- wp_date ( 'M j ' , strtotime ( $ end_date ), $ time_zone )
523- );
524- }
525- }
526-
527426 /**
528427 * Calculate the previous comparison date range based on a selected date range.
529428 *
@@ -728,8 +627,8 @@ public static function get_top_performing_courses_by_instructor( $instructor_id,
728627
729628 $ complete_status = tutor_utils ()->get_earnings_completed_statuses ();
730629
731- $ amount_type = current_user_can ( ' administrator ' ) ? 'earnings.admin_amount ' : 'earnings.instructor_amount ' ;
732- $ amount_rate = current_user_can ( ' administrator ' ) ? 'earnings.admin_rate ' : 'earnings.instructor_rate ' ;
630+ $ amount_type = is_admin ( ) ? 'earnings.admin_amount ' : 'earnings.instructor_amount ' ;
631+ $ amount_rate = is_admin ( ) ? 'earnings.admin_rate ' : 'earnings.instructor_rate ' ;
733632
734633 $ amount_condition = "CASE
735634 WHEN orders.tax_type = 'inclusive' AND earnings.course_price_grand_total > 0
@@ -943,4 +842,27 @@ function ( $review ) {
943842 $ reviews
944843 );
945844 }
845+
846+ public static function get_stat_card_details ( float $ current_data , float $ previous_data ) {
847+
848+ if ( empty ( $ previous_data ) && empty ( $ current_data ) ) {
849+ return '- ' ;
850+ }
851+
852+ if ( empty ( $ previous_data ) ) {
853+ $ percentage = $ current_data > 0 ? 100 : 0 ;
854+ } else {
855+ $ percentage = ( ( $ current_data - $ previous_data ) / $ previous_data ) * 100 ;
856+ }
857+
858+ $ is_negative = $ percentage < 0 ;
859+ $ icon = empty ( $ percentage ) ? Icon::MINUS : ( $ is_negative ? Icon::ARROW_DOWN : Icon::ARROW_UP );
860+ $ class = empty ( $ percentage ) ? '' : ( $ is_negative ? 'tutor-p2 tutor-actions-critical-primary ' : 'tutor-p2 tutor-actions-success-primary ' );
861+
862+ return array (
863+ 'percentage ' => abs ( $ percentage ) . '% ' ,
864+ 'icon ' => $ icon ,
865+ 'class ' => $ class ,
866+ );
867+ }
946868}
0 commit comments