PluginProbe
Tutor LMS – eLearning and online course solution / trunk
Tutor LMS – eLearning and online course solution vtrunk
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
tutor / templates / dashboard / components / header.php
header.php
273 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Tutor dashboard header.
4 * Reusable component for displaying the dashboard header.
5 *
6 * @package Tutor\Templates
7 * @author Themeum <support@themeum.com>
8 * @link https://themeum.com
9 * @since 4.0.0
10 */
11
12 defined( 'ABSPATH' ) || exit;
13
14 use Tutor\Components\Avatar;
15 use Tutor\Components\Button;
16 use Tutor\Components\Constants\Size;
17 use Tutor\Components\Constants\Variant;
18 use TUTOR\Dashboard;
19 use Tutor\Components\SvgIcon;
20 use Tutor\Components\Constants\Color;
21 use TUTOR\Icon;
22 use TUTOR\Instructors_List;
23 use TUTOR\User;
24 use Tutor\Models\CourseModel;
25
26 $menu_items = Dashboard::get_account_pages();
27 $menu_items['logout'] = array(
28 'title' => esc_html__( 'Logout', 'tutor' ),
29 'icon' => Icon::LOGOUT,
30 'url' => wp_logout_url( tutor_utils()->tutor_dashboard_url() ),
31 );
32
33 $active_nav = '';
34 $user_id = get_current_user_id();
35 $display_name = tutor_utils()->display_name( $user_id );
36 $edit_profile_url = Dashboard::get_account_page_url( 'settings' ) . '?tab=account';
37 $is_become_instructor_enabled = tutor_utils()->get_option( 'enable_become_instructor_btn' );
38
39 $is_instructor_view = User::is_instructor_view();
40 ?>
41
42 <div x-data="tutorHeader()" class="tutor-dashboard-header">
43 <div class="tutor-dashboard-header-inner">
44 <div class="tutor-dashboard-header-left">
45 <div class="tutor-h5 tutor-text-primary tutor-text-medium">
46 <span class="tutor-text-subdued">
47 <?php echo esc_html_x( 'Hi,', 'greetings', 'tutor' ); ?>
48 </span>
49 <?php echo esc_html( $display_name . ' 👋' ); ?>
50 </div>
51 <?php
52 if ( $is_instructor_view ) :
53 $course_post_type = apply_filters( 'tutor_dashboard_course_list_post_type', array( tutor()->course_post_type ) );
54 $active_course_count = CourseModel::get_courses_by_instructor( $user_id, CourseModel::STATUS_PUBLISH, 0, 0, true, $course_post_type, '' );
55 $enrolled_student_count = (int) tutor_utils()->get_total_students_by_instructor( $user_id );
56 ?>
57 <div class="tutor-flex tutor-items-center tutor-gap-2 tutor-tiny">
58 <?php
59 echo wp_kses(
60 sprintf(
61 /* translators: %s is the formatted active course count. */
62 _n(
63 '<span class="tutor-font-medium">%s</span> active course',
64 '<span class="tutor-font-medium">%s</span> active courses',
65 $active_course_count,
66 'tutor'
67 ),
68 esc_html( number_format_i18n( $active_course_count ) )
69 ),
70 array(
71 'span' => array(
72 'class' => true,
73 ),
74 )
75 );
76 ?>
77 <span class="tutor-text-subdued">&bull;</span>
78 <?php
79 echo wp_kses(
80 sprintf(
81 /* translators: %s is the formatted enrolled student count. */
82 _n(
83 '<span class="tutor-font-medium">%s</span> student enrolled',
84 '<span class="tutor-font-medium">%s</span> students enrolled',
85 $enrolled_student_count,
86 'tutor'
87 ),
88 esc_html( number_format_i18n( $enrolled_student_count ) )
89 ),
90 array(
91 'span' => array(
92 'class' => true,
93 ),
94 )
95 );
96 ?>
97 </div>
98 <?php endif; ?>
99 </div>
100 <div class="tutor-dashboard-header-right">
101 <div>
102 <?php
103 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
104 do_action( 'tutor_dashboard/before_header_button' );
105 ?>
106 </div>
107 <div
108 x-data="tutorPopover({
109 placement: 'bottom-end',
110 offset: 4,
111 })"
112 class="tutor-dashboard-header-user"
113 >
114 <button
115 class="tutor-dashboard-header-user-avatar"
116 x-ref="trigger"
117 @click="toggle()"
118 :class="{ 'active': open }"
119 x-init="$watch('open', value => { if (window.innerWidth <= 768) { document.body.style.overflow = value ? 'hidden' : ''; } })"
120 @resize.window="
121 if (window.innerWidth <= 768 && open) { document.body.style.overflow = open ? 'hidden' : ''; }
122 else if (window.innerWidth >= 768 && open) { document.body.style.overflow = '' }
123 "
124 aria-label="<?php esc_attr_e( 'Open user menu', 'tutor' ); ?>"
125 >
126 <?php Avatar::make()->user( $user_id )->size( Size::SIZE_32 )->render(); ?>
127 <?php
128 SvgIcon::make()
129 ->name( Icon::USER_CIRCLE )
130 ->size( Size::SIZE_20 )
131 ->attr( 'class', 'tutor-hidden tutor-sm-inline-block' )
132 ->render();
133 ?>
134 </button>
135
136 <div
137 x-ref="content"
138 x-show="open"
139 x-cloak
140 @click.outside="handleClickOutside()"
141 x-transition.origin.top.right
142 class="tutor-popover tutor-dashboard-header-user-popover"
143 >
144 <div class="tutor-dashboard-header-user-popover-profile">
145
146 <div class="tutor-profile-header-top tutor-hidden tutor-sm-flex tutor-items-center tutor-px-6 tutor-py-5">
147 <?php
148 Button::make()
149 ->label( __( 'Back', 'tutor' ) )
150 ->variant( Variant::GHOST )
151 ->size( Size::X_SMALL )
152 ->icon( Icon::LEFT, 'left', 20 )
153 ->icon_only()
154 ->flip_rtl()
155 ->attr( '@click', 'hide()' )
156 ->render();
157 ?>
158 <h4 class="tutor-profile-header-title tutor-text-h4 tutor-font-semibold tutor-my-none">
159 <?php esc_html_e( 'Account', 'tutor' ); ?>
160 </h4>
161 <?php
162 Button::make()
163 ->variant( Variant::GHOST )
164 ->size( Size::X_SMALL )
165 ->icon( Icon::SETTING, 'left', 20 )
166 ->tag( 'a' )
167 ->icon_only()
168 ->attr( 'href', esc_url( Dashboard::get_account_page_url( 'settings' ) ) )
169 ->render();
170 ?>
171 </div>
172
173 <div class="tutor-user-profile-info">
174 <?php Avatar::make()->user( $user_id )->size( Size::SIZE_48 )->bordered()->render(); ?>
175 <div class="tutor-user-profile-meta tutor-flex tutor-flex-column tutor-items-center tutor-gap-1">
176 <div class="tutor-text-medium tutor-text-primary tutor-font-semibold">
177 <?php echo esc_html( wp_get_current_user()->display_name ); ?>
178 </div>
179 <div class="tutor-text-tiny tutor-text-secondary">
180 <?php echo esc_html( wp_get_current_user()->user_email ); ?>
181 </div>
182 </div>
183 <a href="<?php echo esc_url( $edit_profile_url ); ?>" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon tutor-ml-auto tutor-force-hidden tutor-force-sm-flex">
184 <?php SvgIcon::make()->name( Icon::EDIT_2 )->size( Size::SIZE_20 )->render(); ?>
185 </a>
186 </div>
187
188 <?php
189 if ( ! User::is_instructor( $user_id ) && ! User::is_admin( $user_id ) ) {
190 $instructor_status = tutor_utils()->instructor_status( 0, false );
191 $instructor_status = is_string( $instructor_status ) ? strtolower( $instructor_status ) : '';
192
193 if ( Instructors_List::STATUS_PENDING === $instructor_status ) {
194 $applied_on = get_user_meta( $user_id, '_is_tutor_instructor', true );
195 $applied_on = tutor_i18n_get_formated_date( $applied_on, get_option( 'date_format' ) );
196 ?>
197 <div class="tutor-w-full tutor-sm-px-6">
198 <div class="tutor-flex tutor-items-center tutor-gap-3 tutor-py-2 tutor-px-4 tutor-surface-warning-hover-2 tutor-rounded-sm">
199 <span class="tutor-flex-center">
200 <?php SvgIcon::make()->name( Icon::INFO_OCTAGON )->size( 12 )->color( Color::WARNING )->render(); ?>
201 </span>
202 <span class="tutor-p3 tutor-text-warning ">
203 <?php esc_html_e( 'Application Under Review', 'tutor' ); ?>
204 </span>
205 </div>
206 </div>
207 <?php
208 } elseif ( Instructors_List::STATUS_BLOCKED !== $instructor_status && $is_become_instructor_enabled ) {
209 ?>
210 <div class="tutor-w-full tutor-sm-px-6">
211 <a href="<?php echo esc_url( tutor_utils()->instructor_register_url() ); ?>" class="tutor-btn tutor-btn-primary-soft tutor-btn-x-small tutor-btn-block tutor-profile-switch-button">
212 <?php SvgIcon::make()->name( Icon::INSTRUCTOR )->render(); ?>
213 <?php esc_html_e( 'Become an Instructor', 'tutor' ); ?>
214 </a>
215 </div>
216 <?php
217 }
218 }
219 if ( User::can_switch_mode( $user_id ) ) {
220 $current_mode = User::get_current_view_mode();
221 $button_label = User::VIEW_AS_INSTRUCTOR === $current_mode ? esc_html__( 'Switch to Learner', 'tutor' ) : esc_html__( 'Switch to Instructor', 'tutor' );
222 ?>
223 <div class="tutor-w-full tutor-sm-px-6">
224 <?php
225 Button::make()
226 ->label( $button_label )
227 ->size( Size::X_SMALL )
228 ->variant( Variant::PRIMARY_SOFT )
229 ->icon( Icon::RELOAD_2 )
230 ->block()
231 ->attr( ':disabled', 'profileSwitchMutation?.isPending' )
232 ->attr( ':class', "{ 'tutor-btn-loading': profileSwitchMutation?.isPending }" )
233 ->attr( 'class', 'tutor-profile-switch-button' )
234 ->attr( '@click', "profileSwitchMutation.mutate('{$current_mode}')" )
235 ->render();
236 ?>
237 </div>
238 <?php } ?>
239 </div>
240 <div class="tutor-dashboard-header-user-popover-menu-wrapper">
241 <ul class="tutor-dashboard-header-user-popover-menu">
242 <?php
243 foreach ( $menu_items as $key => $item ) {
244 $icon = ( $key === $active_nav && isset( $item['icon_active'] ) ) ? $item['icon_active'] : $item['icon'];
245 ?>
246 <li>
247 <a href="<?php echo esc_url( $item['url'] ?? '#' ); ?>" class="<?php echo ( $key === $active_nav ) ? 'active' : ''; ?> tutor-small">
248 <?php SvgIcon::make()->name( $icon )->size( 20 )->flip_rtl( 'logout' === $key ? true : false )->render(); ?>
249 <span><?php echo esc_html( $item['title'] ); ?></span>
250 </a>
251 </li>
252 <?php
253 }
254 ?>
255 </ul>
256 <div class="tutor-mobile-logout-wrapper tutor-text-center tutor-px-6 tutor-pb-7 tutor-hidden tutor-sm-block">
257 <?php
258 $logout_btn = $menu_items['logout'] ?? '';
259 if ( ! empty( $logout_btn ) ) :
260 ?>
261 <a href="<?php echo esc_url( $logout_btn['url'] ?? '#' ); ?>" class="tutor-btn tutor-small">
262 <?php SvgIcon::make()->name( $icon )->size( 20 )->render(); ?>
263 <span><?php echo esc_html( $logout_btn['title'] ); ?></span>
264 </a>
265 <?php endif; ?>
266 </div>
267 </div>
268 </div>
269 </div>
270 </div>
271 </div>
272 </div>
273