Skip to content

Commit f210ac7

Browse files
committed
Instructor home state card
1 parent aa69d91 commit f210ac7

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

classes/Instructor.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,18 +846,22 @@ function ( $review ) {
846846
public static function get_stat_card_details( float $current_data, float $previous_data ) {
847847

848848
if ( empty( $previous_data ) && empty( $current_data ) ) {
849-
return '-';
849+
return array(
850+
'percentage' => '',
851+
'icon' => Icon::MINUS,
852+
'class' => 'tutor-text-primary',
853+
);
850854
}
851855

852856
if ( empty( $previous_data ) ) {
853-
$percentage = $current_data > 0 ? 100 : 0;
857+
$percentage = 100;
854858
} else {
855859
$percentage = ( ( $current_data - $previous_data ) / $previous_data ) * 100;
856860
}
857861

858862
$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' );
863+
$icon = $is_negative ? Icon::ARROW_DOWN : Icon::ARROW_UP;
864+
$class = $is_negative ? 'tutor-p2 tutor-actions-critical-primary' : 'tutor-p2 tutor-actions-success-primary';
861865

862866
return array(
863867
'percentage' => abs( $percentage ) . '%',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Stat Card Hover Content
4+
*
5+
* @package Tutor\Templates
6+
* @since 4.0.0
7+
*/
8+
9+
defined( 'ABSPATH' ) || exit;
10+
11+
$hover_period_current = $hover_period_current ?? 'Jan-Dec 2025';
12+
$hover_period_prev = $hover_period_prev ?? 'Jan-Dec 2024';
13+
$hover_amount = $hover_amount ?? '$740.00';
14+
$hover_percent = $hover_percent ?? '48%';
15+
$hover_direction = $hover_direction ?? 'up';
16+
17+
$arrow_icon = 'up' === $hover_direction ? TUTOR\Icon::ARROW_UP : TUTOR\Icon::ARROW_DOWN;
18+
$arrow_class = 'up' === $hover_direction ? 'tutor-text-success' : 'tutor-text-danger';
19+
?>
20+
21+
<div class="tutor-stat-card-hover-contents tutor-flex tutor-flex-column tutor-gap-2">
22+
<div class="tutor-flex tutor-items-center tutor-gap-2 tutor-text-tiny tutor-text-secondary">
23+
<span><?php echo esc_html( $hover_period_current ); ?></span>
24+
<span><?php esc_html_e( 'vs', 'tutor' ); ?></span>
25+
<span><?php echo esc_html( $hover_period_prev ); ?></span>
26+
</div>
27+
<div class="tutor-flex tutor-items-center tutor-justify-between">
28+
<span class="tutor-text-base tutor-font-bold tutor-text-primary">
29+
<?php echo esc_html( $hover_amount ); ?>
30+
</span>
31+
<span class="tutor-flex tutor-items-center tutor-gap-1 tutor-text-base tutor-font-bold <?php echo esc_attr( $arrow_class ); ?>">
32+
<?php echo esc_html( $hover_percent ); ?>
33+
<?php tutor_utils()->render_svg_icon( $arrow_icon, 16, 16 ); ?>
34+
</span>
35+
</div>
36+
</div>

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* @since 4.0.0
1010
*/
1111

12+
use TUTOR_REPORT\Analytics;
13+
1214
defined( 'ABSPATH' ) || exit;
1315

1416
// Default values.
@@ -29,6 +31,11 @@
2931
return;
3032
}
3133

34+
if ( $change_display_on_hover) {
35+
$template_path = tutor()->path . 'templates/dashboard/instructor/analytics/stat-card-hover.php';
36+
$hover_template = Analytics::get_template_output($template_path, array());
37+
}
38+
3239
?>
3340
<div class="tutor-card tutor-stat-card tutor-stat-card-<?php echo esc_attr( $icon ); ?>">
3441
<div class="tutor-stat-card-header">
@@ -43,18 +50,18 @@
4350
<div class="tutor-stat-card-value">
4451
<?php echo esc_html( $value ); ?>
4552
</div>
46-
<?php if ( ! empty( $change_display ) ) : ?>
47-
<p class="<?php echo esc_attr( $change_class ); ?>">
48-
<?php echo esc_html( $change_display ); ?>
49-
</p>
50-
<?php if ( ! empty( $change_icon ) ) : ?>
51-
<?php tutor_utils()->render_svg_icon( $change_icon ); ?>
52-
<?php endif; ?>
53+
54+
<p class="<?php echo esc_attr( $change_class ); ?>">
55+
<?php echo esc_html( $change_display ); ?>
56+
</p>
57+
<?php if ( ! empty( $change_icon ) ) : ?>
58+
<?php tutor_utils()->render_svg_icon( $change_icon ); ?>
5359
<?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>
60+
61+
<?php if ( $change_display_on_hover ) : ?>
62+
63+
<?php
64+
//echo $hover_template; ?>
5865
<?php endif; ?>
5966
</div>
6067
<?php if ( $show_graph ) : ?>

templates/dashboard/instructor/home.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ class="tutor-flex tutor-gap-5"
361361
'change' => $card['change'] ?? '',
362362
'data' => $card['data'] ?? array( 0, 0, 0 ),
363363
'change_class' => $card['change_class'] ?? '',
364-
'class_icon' => $card['change_icon'] ?? '',
364+
'change_icon' => $card['change_icon'] ?? '',
365+
'change_display_on_hover' => true,
365366
)
366367
);
367368
?>

0 commit comments

Comments
 (0)