Skip to content

Commit aa69d91

Browse files
committed
new state card design for instructor home
1 parent a1d4be3 commit aa69d91

File tree

7 files changed

+94
-149
lines changed

7 files changed

+94
-149
lines changed

assets/icons/arrow-down.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/icons/arrow-up.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/src/js/v3/shared/icons/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ export const icons = [
1414
'announcement',
1515
'archive',
1616
'archive2',
17+
'arrowDown',
1718
'arrowLeft',
1819
'arrowLeft2',
1920
'arrowLeftAlt',
2021
'arrowRight2',
22+
'arrowUp',
2123
'arrowsIn',
2224
'arrowsOut',
2325
'assignment',
@@ -79,6 +81,7 @@ export const icons = [
7981
'colorOption',
8082
'command',
8183
'comments',
84+
'commission',
8285
'completed',
8386
'completedCircle',
8487
'completedColorize',
@@ -146,6 +149,7 @@ export const icons = [
146149
'eyeOff',
147150
'facebook',
148151
'feather',
152+
'fees',
149153
'file',
150154
'fileAttachement',
151155
'filter',
@@ -296,6 +300,7 @@ export const icons = [
296300
'resources',
297301
'rotate',
298302
'rtf',
303+
'sale',
299304
'saleType',
300305
'save',
301306
'search',

classes/Icon.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ final class Icon {
3232
const ARCHIVE_2 = 'archive-2';
3333
const ARROWS_IN = 'arrows-in';
3434
const ARROWS_OUT = 'arrows-out';
35+
const ARROW_DOWN = 'arrow-down';
3536
const ARROW_LEFT = 'arrow-left';
3637
const ARROW_LEFT_2 = 'arrow-left-2';
3738
const ARROW_LEFT_ALT = 'arrow-left-alt';
3839
const ARROW_RIGHT_2 = 'arrow-right-2';
40+
const ARROW_UP = 'arrow-up';
3941
const ASSIGNMENT = 'assignment';
4042
const ATTACH = 'attach';
4143
const ATTACHMENT_LINE = 'attachment-line';
@@ -93,9 +95,9 @@ final class Icon {
9395
const CODING = 'coding';
9496
const COLLAPSED = 'collapsed';
9597
const COLOR_OPTION = 'color-option';
96-
const COMMISSION = 'commission';
9798
const COMMAND = 'command';
9899
const COMMENTS = 'comments';
100+
const COMMISSION = 'commission';
99101
const COMPLETED = 'completed';
100102
const COMPLETED_CIRCLE = 'completed-circle';
101103
const COMPLETED_COLORIZE = 'completed-colorize';
@@ -162,8 +164,8 @@ final class Icon {
162164
const EYE_LINE = 'eye-line';
163165
const EYE_OFF = 'eye-off';
164166
const FACEBOOK = 'facebook';
165-
const FEES = 'fees';
166167
const FEATHER = 'feather';
168+
const FEES = 'fees';
167169
const FILE = 'file';
168170
const FILE_ATTACHEMENT = 'file-attachement';
169171
const FILTER = 'filter';

classes/Instructor.php

Lines changed: 25 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

templates/dashboard/instructor/analytics/stat-card.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
defined( 'ABSPATH' ) || exit;
1313

1414
// Default values.
15-
$icon_size = $icon_size ?? 24;
16-
$value = isset( $value ) ? $value : 0;
17-
$change = isset( $change ) ? $change : '';
18-
$show_graph = isset( $show_graph ) ? $show_graph : false;
19-
$data = isset( $data ) ? $data : array( 0, 0, 0 );
15+
$icon_size = $icon_size ?? 24;
16+
$value = $value ?? 0;
17+
$change_display = $change ?? '';
18+
$show_graph = $show_graph ?? false;
19+
$data = $data ?? array( 0, 0, 0 );
20+
$change_class = $change_class ?? 'tutor-stat-card-change ';
21+
$change_icon = $change_icon ?? '';
22+
$change_display_on_hover = $change_display_on_hover ?? false;
2023

2124
// Required fields validation.
2225
if ( ! isset( $card_title ) || empty( $card_title ) ) {
@@ -26,8 +29,6 @@
2629
return;
2730
}
2831

29-
$change_display = ! empty( $change ) ? $change : '';
30-
3132
?>
3233
<div class="tutor-card tutor-stat-card tutor-stat-card-<?php echo esc_attr( $icon ); ?>">
3334
<div class="tutor-stat-card-header">
@@ -43,9 +44,17 @@
4344
<?php echo esc_html( $value ); ?>
4445
</div>
4546
<?php if ( ! empty( $change_display ) ) : ?>
46-
<p class="tutor-stat-card-change">
47+
<p class="<?php echo esc_attr( $change_class ); ?>">
4748
<?php echo esc_html( $change_display ); ?>
4849
</p>
50+
<?php if ( ! empty( $change_icon ) ) : ?>
51+
<?php tutor_utils()->render_svg_icon( $change_icon ); ?>
52+
<?php endif; ?>
53+
<?php endif; ?>
54+
<?php if ( ! empty( $change_display_on_hover ) ) : ?>
55+
<p class="tutor-stat-card-hover-content">
56+
<?php echo esc_html( $change_display_on_hover ); ?>
57+
</p>
4958
<?php endif; ?>
5059
</div>
5160
<?php if ( $show_graph ) : ?>

0 commit comments

Comments
 (0)