|
20 | 20 | use Tutor\Components\InputField; |
21 | 21 | use Tutor\Components\Constants\InputType; |
22 | 22 |
|
23 | | -$saved_order = get_user_meta( get_current_user_id(), '_tutor_instructor_home_sections_order', true ); |
24 | | -$saved_visibility = get_user_meta( get_current_user_id(), '_tutor_instructor_home_sections_visibility', true ); |
25 | | - |
26 | | -$sortable_sections = array( |
27 | | - array( |
28 | | - 'id' => 'current_stats', |
29 | | - 'label' => esc_html__( 'Current Stats', 'tutor' ), |
30 | | - 'is_active' => $saved_visibility['current_stats'] ?? true, |
31 | | - 'order' => $saved_order['current_stats'] ?? 0, |
32 | | - ), |
33 | | - array( |
34 | | - 'id' => 'overview_chart', |
35 | | - 'label' => esc_html__( 'Earning Over Time', 'tutor' ), |
36 | | - 'is_active' => $saved_visibility['overview_chart'] ?? true, |
37 | | - 'order' => $saved_order['overview_chart'] ?? 1, |
38 | | - ), |
39 | | - array( |
40 | | - 'id' => 'course_completion_and_leader', |
41 | | - 'label' => esc_html__( 'Course Completion and Leader', 'tutor' ), |
42 | | - 'is_active' => $saved_visibility['course_completion_and_leader'] ?? true, |
43 | | - 'order' => $saved_order['course_completion_and_leader'] ?? 2, |
44 | | - ), |
45 | | - array( |
46 | | - 'id' => 'top_performing_courses', |
47 | | - 'label' => esc_html__( 'Top Performing Courses', 'tutor' ), |
48 | | - 'is_active' => $saved_visibility['top_performing_courses'] ?? true, |
49 | | - 'order' => $saved_order['top_performing_courses'] ?? 3, |
50 | | - ), |
51 | | - array( |
52 | | - 'id' => 'upcoming_tasks_and_activity', |
53 | | - 'label' => esc_html__( 'Upcoming Tasks and Recent Activity', 'tutor' ), |
54 | | - 'is_active' => $saved_visibility['upcoming_tasks_and_activity'] ?? true, |
55 | | - 'order' => $saved_order['upcoming_tasks_and_activity'] ?? 4, |
56 | | - ), |
57 | | - array( |
58 | | - 'id' => 'recent_reviews', |
59 | | - 'label' => esc_html__( 'Recent Student Reviews', 'tutor' ), |
60 | | - 'is_active' => $saved_visibility['recent_reviews'] ?? true, |
61 | | - 'order' => $saved_order['recent_reviews'] ?? 5, |
62 | | - ), |
63 | | -); |
64 | | - |
65 | | -usort( |
66 | | - $sortable_sections, |
67 | | - function ( $a, $b ) { |
68 | | - return $a['order'] <=> $b['order']; |
69 | | - } |
70 | | -); |
71 | | - |
72 | | -$sortable_sections_defaults = array_reduce( |
73 | | - $sortable_sections, |
74 | | - function ( $carry, $section ) { |
75 | | - $carry[ $section['id'] ] = $section['is_active'] ?? false; |
76 | | - return $carry; |
77 | | - }, |
78 | | - array() |
79 | | -); |
80 | | - |
81 | | -$sortable_sections_ids = array_reduce( |
82 | | - $sortable_sections, |
83 | | - function ( $carry, $section ) { |
84 | | - $carry[ $section['order'] ] = $section['id']; |
85 | | - return $carry; |
86 | | - }, |
87 | | - array() |
88 | | -); |
89 | | - |
90 | 23 | $upcoming_tasks = array(); |
91 | 24 | $get_upcoming_live_tasks = array(); |
92 | 25 | $overview_chart_data = array(); |
93 | 26 | $recent_reviews = array(); |
94 | 27 | $course_completion_data = array(); |
| 28 | +$sortable_sections = array(); |
95 | 29 |
|
96 | 30 | $user = wp_get_current_user(); |
97 | 31 | $instructor_course_ids = CourseModel::get_courses_by_args( |
@@ -294,6 +228,90 @@ function ( $carry, $section ) { |
294 | 228 | } |
295 | 229 | $reviews = tutor_utils()->get_reviews_by_instructor( $user->ID, 0, 3, '', '', $review_args ); |
296 | 230 | $recent_reviews = Instructor::format_instructor_recent_reviews( $reviews->results ); |
| 231 | + |
| 232 | + |
| 233 | +/** |
| 234 | + * ------------------------------------ |
| 235 | + * Sortable sections data preparation |
| 236 | + * ------------------------------------ |
| 237 | + */ |
| 238 | +$saved_order = get_user_meta( get_current_user_id(), '_tutor_instructor_home_sections_order', true ); |
| 239 | +$saved_visibility = get_user_meta( get_current_user_id(), '_tutor_instructor_home_sections_visibility', true ); |
| 240 | + |
| 241 | +$sortable_sections = array( |
| 242 | + array( |
| 243 | + 'id' => 'current_stats', |
| 244 | + 'label' => esc_html__( 'Current Stats', 'tutor' ), |
| 245 | + 'is_active' => $saved_visibility['current_stats'] ?? true, |
| 246 | + 'order' => $saved_order['current_stats'] ?? 0, |
| 247 | + 'data' => true |
| 248 | + ), |
| 249 | + array( |
| 250 | + 'id' => 'overview_chart', |
| 251 | + 'label' => esc_html__( 'Earning Over Time', 'tutor' ), |
| 252 | + 'is_active' => $saved_visibility['overview_chart'] ?? true, |
| 253 | + 'order' => $saved_order['overview_chart'] ?? 1, |
| 254 | + 'data' => ! empty( $overview_chart_data ), |
| 255 | + ), |
| 256 | + array( |
| 257 | + 'id' => 'course_completion_and_leader', |
| 258 | + 'label' => esc_html__( 'Course Completion and Leader', 'tutor' ), |
| 259 | + 'is_active' => $saved_visibility['course_completion_and_leader'] ?? true, |
| 260 | + 'order' => $saved_order['course_completion_and_leader'] ?? 2, |
| 261 | + 'data' => ! empty( $course_completion_data ), |
| 262 | + ), |
| 263 | + array( |
| 264 | + 'id' => 'top_performing_courses', |
| 265 | + 'label' => esc_html__( 'Top Performing Courses', 'tutor' ), |
| 266 | + 'is_active' => $saved_visibility['top_performing_courses'] ?? true, |
| 267 | + 'order' => $saved_order['top_performing_courses'] ?? 3, |
| 268 | + 'data' => ! empty( $top_performing_courses ), |
| 269 | + ), |
| 270 | + array( |
| 271 | + 'id' => 'upcoming_tasks_and_activity', |
| 272 | + 'label' => esc_html__( 'Upcoming Tasks and Recent Activity', 'tutor' ), |
| 273 | + 'is_active' => $saved_visibility['upcoming_tasks_and_activity'] ?? true, |
| 274 | + 'order' => $saved_order['upcoming_tasks_and_activity'] ?? 4, |
| 275 | + 'data' => ! empty( $upcoming_tasks ), |
| 276 | + ), |
| 277 | + array( |
| 278 | + 'id' => 'recent_reviews', |
| 279 | + 'label' => esc_html__( 'Recent Student Reviews', 'tutor' ), |
| 280 | + 'is_active' => $saved_visibility['recent_reviews'] ?? true, |
| 281 | + 'order' => $saved_order['recent_reviews'] ?? 5, |
| 282 | + 'data' => ! empty( $recent_reviews ), |
| 283 | + ), |
| 284 | +); |
| 285 | + |
| 286 | +$sortable_sections = array_filter( |
| 287 | + $sortable_sections, |
| 288 | + fn($section) => $section['data'] |
| 289 | +); |
| 290 | + |
| 291 | +usort( |
| 292 | + $sortable_sections, |
| 293 | + function ( $a, $b ) { |
| 294 | + return $a['order'] <=> $b['order']; |
| 295 | + } |
| 296 | +); |
| 297 | + |
| 298 | +$sortable_sections_defaults = array_reduce( |
| 299 | + $sortable_sections, |
| 300 | + function ( $carry, $section ) { |
| 301 | + $carry[ $section['id'] ] = $section['is_active'] ?? false; |
| 302 | + return $carry; |
| 303 | + }, |
| 304 | + array() |
| 305 | +); |
| 306 | + |
| 307 | +$sortable_sections_ids = array_reduce( |
| 308 | + $sortable_sections, |
| 309 | + function ( $carry, $section ) { |
| 310 | + $carry[ $section['order'] ] = $section['id']; |
| 311 | + return $carry; |
| 312 | + }, |
| 313 | + array() |
| 314 | +); |
297 | 315 | ?> |
298 | 316 |
|
299 | 317 | <form x-data='tutorForm({ |
@@ -328,7 +346,6 @@ class="tutor-popover tutor-popover-bottom" |
328 | 346 | > |
329 | 347 | <div |
330 | 348 | class="tutor-popover-menu" |
331 | | - style="width: 288px;" |
332 | 349 | x-data='tutorSortableSections( |
333 | 350 | <?php echo wp_json_encode( $sortable_sections_ids ); ?> |
334 | 351 | )' |
@@ -397,7 +414,7 @@ class="tutor-flex tutor-flex-wrap tutor-gap-5 tutor-z-positive" |
397 | 414 | endif; |
398 | 415 | ?> |
399 | 416 |
|
400 | | - <?php if ( 'course_completion_and_leader' === $section['id'] ) : ?> |
| 417 | + <?php if ( 'course_completion_and_leader' === $section['id'] && ! empty( $course_completion_data ) ) : ?> |
401 | 418 | <div |
402 | 419 | data-section-id="course_completion_and_leader" |
403 | 420 | class="tutor-flex tutor-gap-6" |
|
0 commit comments