← All changes
|
inc/TemplateHooks/Admin/AdminListStudentsEnrolled.php
+134
-171
4.4.3
→
4.4.8
View file →
| @@ -2,11 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace LearnPress\TemplateHooks\Admin; |
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | -use LearnPress\Databases\PostDB; | |
| 7 | 6 | use LearnPress\Databases\UserItemsDB; |
| 8 | -use LearnPress\Filters\PostFilter; | |
| 9 | 7 | use LearnPress\Filters\UserItemsFilter; |
| 10 | 8 | use LearnPress\Helpers\Singleton; |
| 11 | 9 | use LearnPress\Helpers\Template; |
| 12 | 10 | use LearnPress\Models\CourseModel; |
| @@ -19,8 +17,9 @@ | ||
| 19 | 17 | use LearnPress\TemplateHooks\UserItem\UserCourseTemplate; |
| 20 | 18 | use LP_Debug; |
| 21 | 19 | use LP_Helper; |
| 22 | 20 | use LP_Page_Controller; |
| 21 | +use LP_Request; | |
| 23 | 22 | use stdClass; |
| 24 | 23 | use Throwable; |
| 25 | 24 | |
| 26 | 25 | /** |
| @@ -29,9 +28,9 @@ | ||
| 29 | 28 | * Displays enrolled students for Admin (all courses) and Instructor (own courses only). |
| 30 | 29 | * Provides WP Admin submenu + Frontend profile tab. |
| 31 | 30 | * |
| 32 | 31 | * @since 4.3.3 |
| 33 | - * @version 1.0.0 | |
| 32 | + * @version 1.0.1 | |
| 34 | 33 | */ |
| 35 | 34 | class AdminListStudentsEnrolled { |
| 36 | 35 | use Singleton; |
| 37 | 36 | |
| @@ -36,12 +35,9 @@ | ||
| 36 | 35 | use Singleton; |
| 37 | 36 | |
| 38 | 37 | const PER_PAGE = 10; |
| 39 | 38 | |
| 40 | - public function init() { | |
| 41 | - | |
| 42 | - // 1. Register render hook for both admin + frontend profile. | |
| 43 | - add_action( 'learn-press/admin/enrolled-students/layout', array( $this, 'enrolled_students_layout' ) ); | |
| 39 | + public function init(): void { | |
| 44 | 40 | // 2. Whitelist AJAX callback. |
| 45 | 41 | add_filter( 'lp/rest/ajax/allow_callback', array( $this, 'allow_callback' ) ); |
| 46 | 42 | // 4. Render a modal toolbar template from PHP (used by JS modal). |
| 47 | 43 | add_action( 'admin_footer', array( $this, 'print_modal_toolbar_template' ) ); |
| @@ -51,14 +47,19 @@ | ||
| 51 | 47 | /** |
| 52 | 48 | * Admin page output callback. |
| 53 | 49 | */ |
| 54 | 50 | public function admin_page_output() { |
| 55 | - $instructor_id = self::resolve_instructor_id_for_request( array() ); | |
| 51 | + ob_start(); | |
| 52 | + $this->enrolled_students_layout(); | |
| 53 | + $content = ob_get_clean(); | |
| 56 | 54 | |
| 57 | - echo '<div class="wrap" id="lp-enrolled-students">'; | |
| 58 | - echo '<h1 class="wp-heading-inline">' . esc_html__( 'Students', 'learnpress' ) . '</h1>'; | |
| 59 | - do_action( 'learn-press/admin/enrolled-students/layout', $instructor_id ); | |
| 60 | - echo '</div>'; | |
| 55 | + echo AdminTemplate::html_on_wp_admin_screen( | |
| 56 | + array( | |
| 57 | + 'content' => $content, | |
| 58 | + 'title' => __( 'Students', 'learnpress' ), | |
| 59 | + 'id' => 'lp-enrolled-students', | |
| 60 | + ) | |
| 61 | + ); | |
| 61 | 62 | } |
| 62 | 63 | |
| 63 | 64 | /** |
| 64 | 65 | * Allow callback for AJAX. |
| @@ -74,12 +75,10 @@ | ||
| 74 | 75 | } |
| 75 | 76 | |
| 76 | 77 | /** |
| 77 | 78 | * Render initial layout with TemplateAJAX::load_content_via_ajax(). |
| 78 | - * | |
| 79 | - * @param int $instructor_id 0 for Admin (all), user ID for Instructor. | |
| 80 | 79 | */ |
| 81 | - public function enrolled_students_layout( $instructor_id = 0 ) { | |
| 80 | + public function enrolled_students_layout() { | |
| 82 | 81 | try { |
| 83 | 82 | $page_current = ''; |
| 84 | 83 | if ( function_exists( 'get_current_screen' ) ) { |
| 85 | 84 | $wp_screen = get_current_screen(); |
| @@ -90,25 +89,16 @@ | ||
| 90 | 89 | } |
| 91 | 90 | } |
| 92 | 91 | } |
| 93 | 92 | |
| 94 | - // Enqueue styles — lp-enrolled-students-table CSS is loaded via admin.css/frontend.css import. | |
| 95 | - // Build toolbar HTML (outside AJAX so it persists across reloads). | |
| 96 | - $instructor_id = self::resolve_instructor_id_for_request( | |
| 97 | - array( | |
| 98 | - 'instructor_id' => $instructor_id, | |
| 99 | - ) | |
| 100 | - ); | |
| 101 | - | |
| 102 | 93 | $args = array( |
| 103 | 94 | 'id_url' => 'lp-enrolled-students', |
| 104 | - 'instructor_id' => (int) $instructor_id, | |
| 105 | - 'course_id' => abs( LP_Helper::sanitize_params_submitted( $_GET['course_id'] ?? 0, 'int' ) ), | |
| 106 | - 'course_name' => LP_Helper::sanitize_params_submitted( $_GET['course_name'] ?? '' ), | |
| 95 | + 'course_id' => LP_Request::get_param( 'course_id', 0 ), | |
| 96 | + 'course_name' => LP_Request::get_param( 'course_name' ), | |
| 107 | 97 | 'paged' => 1, |
| 108 | - 'search' => LP_Helper::sanitize_params_submitted( $_GET['search'] ?? '' ), | |
| 109 | - 'start_date' => self::sanitize_date_filter( $_GET['start_date'] ?? '' ), | |
| 110 | - 'end_date' => self::sanitize_date_filter( $_GET['end_date'] ?? '' ), | |
| 98 | + 'search' => lp_request::get_param( 'search' ), | |
| 99 | + 'start_date' => LP_Request::get_param( 'start_date' ), | |
| 100 | + 'end_date' => LP_Request::get_param( 'end_date' ), | |
| 111 | 101 | 'enableUpdateParamsUrl' => false, |
| 112 | 102 | ); |
| 113 | 103 | |
| 114 | 104 | $call_back = array( |
| @@ -127,9 +117,8 @@ | ||
| 127 | 117 | ]; |
| 128 | 118 | |
| 129 | 119 | echo Template::combine_components( $section ); |
| 130 | 120 | } catch ( Throwable $e ) { |
| 131 | - LP_Debug::error_log( $e ); | |
| 132 | 121 | Template::print_message( $e->getMessage(), 'error' ); |
| 133 | 122 | } |
| 134 | 123 | } |
| 135 | 124 | |
| @@ -148,20 +137,18 @@ | ||
| 148 | 137 | |
| 149 | 138 | try { |
| 150 | 139 | // Check permission |
| 151 | 140 | if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) |
| 152 | - && ! current_user_can( UserModel::ROLE_INSTRUCTOR ) ) { | |
| 141 | + && ! current_user_can( UserModel::ROLE_INSTRUCTOR ) ) { | |
| 153 | 142 | throw new Exception( esc_html__( 'You do not have permission to view enrolled students.', 'learnpress' ) ); |
| 154 | 143 | } |
| 155 | 144 | |
| 156 | - $instructor_id = self::resolve_instructor_id_for_request( $data ); | |
| 157 | - | |
| 158 | 145 | $course_id = abs( LP_Helper::sanitize_params_submitted( $data['course_id'] ?? 0, 'int' ) ); |
| 159 | 146 | $paged = max( 1, abs( LP_Helper::sanitize_params_submitted( $data['paged'] ?? 1, 'int' ) ) ); |
| 160 | 147 | $course_name = LP_Helper::sanitize_params_submitted( $data['course_name'] ?? '' ); |
| 161 | 148 | $search = LP_Helper::sanitize_params_submitted( $data['search'] ?? '' ); |
| 162 | - $start_date = self::sanitize_date_filter( $data['start_date'] ?? '' ); | |
| 163 | - $end_date = self::sanitize_date_filter( $data['end_date'] ?? '' ); | |
| 149 | + $start_date = lp_helper::sanitize_params_submitted( $data['start_date'] ?? '' ); | |
| 150 | + $end_date = lp_helper::sanitize_params_submitted( $data['end_date'] ?? '' ); | |
| 164 | 151 | $per_page = self::PER_PAGE; |
| 165 | 152 | |
| 166 | 153 | // Normalize date range if request is reversed. |
| 167 | 154 | if ( $start_date && $end_date && strtotime( $start_date ) > strtotime( $end_date ) ) { |
| @@ -192,9 +179,10 @@ | ||
| 192 | 179 | ); |
| 193 | 180 | $filter->join[] = "JOIN {$lp_db_user_items->wpdb->posts} p ON ui.item_id = p.ID"; |
| 194 | 181 | $filter->join[] = "JOIN {$lp_db_user_items->wpdb->users} u ON ui.user_id = u.ID"; |
| 195 | 182 | |
| 196 | - if ( $instructor_id > 0 ) { | |
| 183 | + $instructor_id = get_current_user_id(); | |
| 184 | + if ( $instructor_id > 0 && current_user_can( UserModel::ROLE_INSTRUCTOR ) ) { | |
| 197 | 185 | $filter->where[] = $lp_db_user_items->wpdb->prepare( 'AND p.post_author = %d', $instructor_id ); |
| 198 | 186 | } |
| 199 | 187 | |
| 200 | 188 | if ( $course_id > 0 ) { |
| @@ -229,8 +217,12 @@ | ||
| 229 | 217 | $end_date . ' 23:59:59' |
| 230 | 218 | ); |
| 231 | 219 | } |
| 232 | 220 | |
| 221 | + $filter = apply_filters( | |
| 222 | + 'learn-press/filter-enrolled-students', | |
| 223 | + $filter | |
| 224 | + ); | |
| 233 | 225 | $total_rows = 0; |
| 234 | 226 | $rows = $lp_db_user_items->get_user_items( $filter, $total_rows ); |
| 235 | 227 | if ( ! is_array( $rows ) ) { |
| 236 | 228 | $rows = array(); |
| @@ -256,54 +248,8 @@ | ||
| 256 | 248 | return $content; |
| 257 | 249 | } |
| 258 | 250 | |
| 259 | 251 | /** |
| 260 | - * Check whether user can view enrolled students content. | |
| 261 | - * | |
| 262 | - * @param int $user_id | |
| 263 | - * | |
| 264 | - * @return bool | |
| 265 | - */ | |
| 266 | - private static function can_view_enrolled_students( int $user_id = 0 ): bool { | |
| 267 | - if ( $user_id < 1 ) { | |
| 268 | - $user_id = get_current_user_id(); | |
| 269 | - } | |
| 270 | - | |
| 271 | - if ( $user_id < 1 ) { | |
| 272 | - return false; | |
| 273 | - } | |
| 274 | - | |
| 275 | - $user_model = UserModel::find( $user_id, true ); | |
| 276 | - if ( ! $user_model instanceof UserModel ) { | |
| 277 | - return false; | |
| 278 | - } | |
| 279 | - | |
| 280 | - return $user_model->is_instructor(); | |
| 281 | - } | |
| 282 | - | |
| 283 | - /** | |
| 284 | - * Resolve instructor_id from request by permission. | |
| 285 | - * Admin can keep requested instructor_id; instructor is forced to self. | |
| 286 | - * | |
| 287 | - * @param array $data | |
| 288 | - * | |
| 289 | - * @return int | |
| 290 | - */ | |
| 291 | - private static function resolve_instructor_id_for_request( array $data ): int { | |
| 292 | - $current_user_id = get_current_user_id(); | |
| 293 | - if ( ! self::can_view_enrolled_students( $current_user_id ) ) { | |
| 294 | - return 0; | |
| 295 | - } | |
| 296 | - | |
| 297 | - $is_admin = user_can( $current_user_id, UserModel::ROLE_ADMINISTRATOR ); | |
| 298 | - if ( $is_admin ) { | |
| 299 | - return max( 0, abs( LP_Helper::sanitize_params_submitted( $data['instructor_id'] ?? 0, 'int' ) ) ); | |
| 300 | - } | |
| 301 | - | |
| 302 | - return $current_user_id; | |
| 303 | - } | |
| 304 | - | |
| 305 | - /** | |
| 306 | 252 | * HTML builder: toolbar (course filter, search). |
| 307 | 253 | * |
| 308 | 254 | * @return string |
| 309 | 255 | */ |
| @@ -313,51 +259,76 @@ | ||
| 313 | 259 | $data_get = LP_Helper::sanitize_params_submitted( $_GET ); |
| 314 | 260 | $selected_course = abs( LP_Helper::sanitize_params_submitted( $data_get['course_id'] ?? 0, 'int' ) ); |
| 315 | 261 | $search_course = LP_Helper::sanitize_params_submitted( $data_get['course_name'] ?? '' ); |
| 316 | 262 | $search_student = LP_Helper::sanitize_params_submitted( $data_get['search'] ?? '' ); |
| 317 | - $search_start = self::sanitize_date_filter( $data_get['start_date'] ?? '' ); | |
| 318 | - $search_end = self::sanitize_date_filter( $data_get['end_date'] ?? '' ); | |
| 263 | + $search_start = lp_helper::sanitize_params_submitted( $data_get['start_date'] ?? '' ); | |
| 264 | + $search_end = lp_helper::sanitize_params_submitted( $data_get['end_date'] ?? '' ); | |
| 319 | 265 | |
| 320 | - $section = array( | |
| 321 | - 'wrap' => '<form class="lp-enrolled-students-table-toolbar lp-enrolled-students-form" onsubmit="return false;">', | |
| 322 | - 'filter-row-open' => '<div class="lp-enrolled-students-table-toolbar__row lp-enrolled-students-table-toolbar__row--filters">', | |
| 323 | - 'course-field-open' => '<div class="lp-enrolled-students-table-toolbar__field">', | |
| 324 | - 'course-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-enrolled-filter-course-name">' . esc_html__( 'Course Filter', 'learnpress' ) . '</label>', | |
| 325 | - 'course-input' => '<input id="lp-enrolled-filter-course-name" class="lp-enrolled-filter-course-name lp-enrolled-students-table-toolbar__input" type="text" name="course_name" list="lp-enrolled-course-list" value="' . esc_attr( $search_course ) . '" placeholder="' . esc_attr__( 'Search course...', 'learnpress' ) . '">', | |
| 326 | - 'course-field-close' => '</div>', | |
| 327 | - 'student-field-open' => '<div class="lp-enrolled-students-table-toolbar__field lp-enrolled-students-table-toolbar__field--student">', | |
| 328 | - 'student-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-enrolled-search-input">' . esc_html__( 'Student', 'learnpress' ) . '</label>', | |
| 329 | - 'student-input' => '<input id="lp-enrolled-search-input" class="lp-enrolled-search-input lp-enrolled-students-table-toolbar__input" type="text" name="search" value="' . esc_attr( $search_student ) . '" placeholder="' . esc_attr__( 'Enter student name or email', 'learnpress' ) . '">', | |
| 330 | - 'student-field-close' => '</div>', | |
| 331 | - 'start-field-open' => '<div class="lp-enrolled-students-table-toolbar__field lp-enrolled-students-table-toolbar__field--date">', | |
| 332 | - 'start-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-enrolled-filter-start-date">' . esc_html__( 'Start Date', 'learnpress' ) . '</label>', | |
| 333 | - 'start-input' => '<input id="lp-enrolled-filter-start-date" class="lp-enrolled-filter-start-date lp-enrolled-students-table-toolbar__input" type="date" name="start_date" value="' . esc_attr( $search_start ) . '" placeholder="mm/dd/yyyy">', | |
| 334 | - 'start-field-close' => '</div>', | |
| 335 | - 'end-field-open' => '<div class="lp-enrolled-students-table-toolbar__field lp-enrolled-students-table-toolbar__field--date">', | |
| 336 | - 'end-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-enrolled-filter-end-date">' . esc_html__( 'End date', 'learnpress' ) . '</label>', | |
| 337 | - 'end-input' => '<input id="lp-enrolled-filter-end-date" class="lp-enrolled-filter-end-date lp-enrolled-students-table-toolbar__input" type="date" name="end_date" value="' . esc_attr( $search_end ) . '" placeholder="mm/dd/yyyy">', | |
| 338 | - 'end-field-close' => '</div>', | |
| 339 | - 'filter-row-close' => '</div>', | |
| 340 | - 'actions-open' => '<div class="lp-enrolled-students-table-toolbar__actions">', | |
| 341 | - 'search-btn' => sprintf( | |
| 342 | - '<button type="button" class="lp-button lp-enrolled-btn-search">%s</button>', | |
| 343 | - esc_html__( 'Search', 'learnpress' ) | |
| 344 | - ), | |
| 345 | - 'clear-btn' => sprintf( | |
| 346 | - '<button type="button" class="lp-button lp-enrolled-btn-clear">%s</button>', | |
| 347 | - esc_html__( 'Clear Filter', 'learnpress' ) | |
| 348 | - ), | |
| 349 | - 'actions-close' => '</div>', | |
| 350 | - 'wrap-end' => '</form>', | |
| 266 | + $html_fields = sprintf( | |
| 267 | + '<div class="filter-field"> | |
| 268 | + <label for="lp-enrolled-filter-course-name">%s</label> | |
| 269 | + <input id="lp-enrolled-filter-course-name" | |
| 270 | + class="lp-enrolled-filter-course-name" | |
| 271 | + type="text" | |
| 272 | + name="course_name" | |
| 273 | + list="lp-enrolled-course-list" | |
| 274 | + value="%s" | |
| 275 | + placeholder="%s"> | |
| 276 | + </div> | |
| 277 | + <div class="filter-field"> | |
| 278 | + <label for="lp-enrolled-search-input">%s</label> | |
| 279 | + <input id="lp-enrolled-search-input" | |
| 280 | + class="lp-enrolled-search-input" | |
| 281 | + type="text" | |
| 282 | + name="search" value="%s" placeholder="%s"> | |
| 283 | + </div> | |
| 284 | + <div class="filter-field"> | |
| 285 | + <label for="lp-enrolled-filter-start-date">%s</label> | |
| 286 | + <input id="lp-enrolled-filter-start-date" | |
| 287 | + class="lp-enrolled-filter-start-date" | |
| 288 | + type="date" name="start_date" | |
| 289 | + value="%s" | |
| 290 | + placeholder="mm/dd/yyyy"> | |
| 291 | + </div> | |
| 292 | + <div class="filter-field"> | |
| 293 | + <label for="lp-enrolled-filter-end-date">%s</label> | |
| 294 | + <input id="lp-enrolled-filter-end-date" class="lp-enrolled-filter-end-date" type="date" name="end_date" value="%s" placeholder="mm/dd/yyyy"> | |
| 295 | + </div> | |
| 296 | + <datalist id="lp-enrolled-course-list">%s</datalist>', | |
| 297 | + esc_html__( 'Course Filter', 'learnpress' ), | |
| 298 | + esc_attr( $search_course ), | |
| 299 | + esc_attr__( 'Search course...', 'learnpress' ), | |
| 300 | + esc_html__( 'Student', 'learnpress' ), | |
| 301 | + esc_attr( $search_student ), | |
| 302 | + esc_attr__( 'Enter student name or email', 'learnpress' ), | |
| 303 | + esc_html__( 'Start Date', 'learnpress' ), | |
| 304 | + esc_attr( $search_start ), | |
| 305 | + esc_html__( 'End date', 'learnpress' ), | |
| 306 | + esc_attr( $search_end ), | |
| 307 | + '' | |
| 351 | 308 | ); |
| 352 | - $section = apply_filters( | |
| 309 | + | |
| 310 | + $html_btn_actions = sprintf( | |
| 311 | + '<button type="button" class="lp-button lp-enrolled-btn-search">%s</button> | |
| 312 | + <button type="button" class="lp-button lp-enrolled-btn-clear">%s</button>', | |
| 313 | + esc_html__( 'Search', 'learnpress' ), | |
| 314 | + esc_html__( 'Clear Filter', 'learnpress' ) | |
| 315 | + ); | |
| 316 | + | |
| 317 | + $html_toolbar = AdminTemplate::html_form_filter( | |
| 318 | + array( | |
| 319 | + 'form_classes' => 'lp-enrolled-students-form', | |
| 320 | + 'fields' => $html_fields, | |
| 321 | + 'btn_actions' => $html_btn_actions, | |
| 322 | + ) | |
| 323 | + ); | |
| 324 | + | |
| 325 | + return apply_filters( | |
| 353 | 326 | 'learn-press/admin/enrolled-students/toolbar/section', |
| 354 | - $section, | |
| 327 | + $html_toolbar, | |
| 355 | 328 | $courses, |
| 356 | - $selected_course, | |
| 329 | + $selected_course | |
| 357 | 330 | ); |
| 358 | - | |
| 359 | - return Template::combine_components( $section ); | |
| 360 | 331 | } |
| 361 | 332 | |
| 362 | 333 | /** |
| 363 | 334 | * Render toolbar used inside View Students modal. |
| @@ -364,39 +335,48 @@ | ||
| 364 | 335 | * |
| 365 | 336 | * @return string |
| 366 | 337 | */ |
| 367 | 338 | public function html_toolbar_modal(): string { |
| 339 | + $html_fields = sprintf( | |
| 340 | + '<div class="filter-field"> | |
| 341 | + <label for="lp-modal-enrolled-search-input">%s</label> | |
| 342 | + <input id="lp-modal-enrolled-search-input" | |
| 343 | + class="lp-enrolled-search-input" | |
| 344 | + type="text" name="search" placeholder="%s"> | |
| 345 | + </div> | |
| 346 | + <div class="filter-field"> | |
| 347 | + <label for="lp-modal-enrolled-filter-start-date">%s</label> | |
| 348 | + <input id="lp-modal-enrolled-filter-start-date" | |
| 349 | + class="lp-enrolled-filter-start-date" | |
| 350 | + type="date" name="start_date" placeholder="mm/dd/yyyy"> | |
| 351 | + </div> | |
| 352 | + <div class="filter-field"> | |
| 353 | + <label for="lp-modal-enrolled-filter-end-date">%s</label> | |
| 354 | + <input id="lp-modal-enrolled-filter-end-date" | |
| 355 | + class="lp-enrolled-filter-end-date" | |
| 356 | + type="date" name="end_date" placeholder="mm/dd/yyyy"> | |
| 357 | + </div>', | |
| 358 | + esc_html__( 'Student', 'learnpress' ), | |
| 359 | + esc_attr__( 'Enter student name or email', 'learnpress' ), | |
| 360 | + esc_html__( 'Start Date', 'learnpress' ), | |
| 361 | + esc_html__( 'End Date', 'learnpress' ) | |
| 362 | + ); | |
| 368 | 363 | |
| 369 | - $section = array( | |
| 370 | - 'wrap' => '<form class="lp-enrolled-students-table-toolbar lp-enrolled-students-table-toolbar--modal lp-enrolled-students-form lp-enrolled-students-form--modal" id="lp-modal-enrolled-form" onsubmit="return false;">', | |
| 371 | - 'filter-row-open' => '<div class="lp-enrolled-students-table-toolbar__row lp-enrolled-students-table-toolbar__row--filters">', | |
| 372 | - 'student-field-open' => '<div class="lp-enrolled-students-table-toolbar__field lp-enrolled-students-table-toolbar__field--student">', | |
| 373 | - 'student-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-modal-enrolled-search-input">' . esc_html__( 'Student', 'learnpress' ) . '</label>', | |
| 374 | - 'student-input' => '<input id="lp-modal-enrolled-search-input" class="lp-enrolled-search-input lp-enrolled-students-table-toolbar__input" type="text" name="search" placeholder="' . esc_attr__( 'Enter student name or email', 'learnpress' ) . '">', | |
| 375 | - 'student-field-close' => '</div>', | |
| 376 | - 'start-field-open' => '<div class="lp-enrolled-students-table-toolbar__field lp-enrolled-students-table-toolbar__field--date">', | |
| 377 | - 'start-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-modal-enrolled-filter-start-date">' . esc_html__( 'Start Date', 'learnpress' ) . '</label>', | |
| 378 | - 'start-input' => '<input id="lp-modal-enrolled-filter-start-date" class="lp-enrolled-filter-start-date lp-enrolled-students-table-toolbar__input" type="date" name="start_date" placeholder="mm/dd/yyyy">', | |
| 379 | - 'start-field-close' => '</div>', | |
| 380 | - 'end-field-open' => '<div class="lp-enrolled-students-table-toolbar__field lp-enrolled-students-table-toolbar__field--date">', | |
| 381 | - 'end-label' => '<label class="lp-enrolled-students-table-toolbar__label" for="lp-modal-enrolled-filter-end-date">' . esc_html__( 'End Date', 'learnpress' ) . '</label>', | |
| 382 | - 'end-input' => '<input id="lp-modal-enrolled-filter-end-date" class="lp-enrolled-filter-end-date lp-enrolled-students-table-toolbar__input" type="date" name="end_date" placeholder="mm/dd/yyyy">', | |
| 383 | - 'end-field-close' => '</div>', | |
| 384 | - 'filter-row-close' => '</div>', | |
| 385 | - 'actions-open' => '<div class="lp-enrolled-students-table-toolbar__actions">', | |
| 386 | - 'search-btn' => sprintf( | |
| 387 | - '<button type="button" class="lp-button lp-enrolled-btn-search-modal">%s</button>', | |
| 388 | - esc_html__( 'Search', 'learnpress' ) | |
| 389 | - ), | |
| 390 | - 'clear-btn' => sprintf( | |
| 391 | - '<button type="button" class="lp-button lp-enrolled-btn-clear-modal">%s</button>', | |
| 392 | - esc_html__( 'Clear Filter', 'learnpress' ) | |
| 393 | - ), | |
| 394 | - 'actions-close' => '</div>', | |
| 395 | - 'wrap-end' => '</form>', | |
| 364 | + $html_btn_actions = sprintf( | |
| 365 | + '<button type="button" class="lp-button lp-enrolled-btn-search-modal">%s</button> | |
| 366 | + <button type="button" class="lp-button lp-enrolled-btn-clear-modal">%s</button>', | |
| 367 | + esc_html__( 'Search', 'learnpress' ), | |
| 368 | + esc_html__( 'Clear Filter', 'learnpress' ) | |
| 396 | 369 | ); |
| 397 | 370 | |
| 398 | - return Template::combine_components( $section ); | |
| 371 | + return AdminTemplate::html_form_filter( | |
| 372 | + array( | |
| 373 | + 'id' => 'lp-modal-enrolled-form', | |
| 374 | + 'form_classes' => 'lp-enrolled-students-form lp-enrolled-students-form--modal lp-enrolled-students-table-toolbar--modal', | |
| 375 | + 'fields' => $html_fields, | |
| 376 | + 'btn_actions' => $html_btn_actions, | |
| 377 | + ) | |
| 378 | + ); | |
| 399 | 379 | } |
| 400 | 380 | |
| 401 | 381 | /** |
| 402 | 382 | * Render lp-target layout used in View Students modal. |
| @@ -473,9 +453,12 @@ | ||
| 473 | 453 | private function html_table( array $rows, array $meta ): string { |
| 474 | 454 | if ( empty( $rows ) ) { |
| 475 | 455 | $section_empty = array( |
| 476 | 456 | 'wrap' => '<div class="lp-enrolled-students-table-wrap">', |
| 477 | - 'empty' => '<div class="lp-enrolled-empty"><p>' . esc_html__( 'No students found.', 'learnpress' ) . '</p></div>', | |
| 457 | + 'empty' => sprintf( | |
| 458 | + '<div class="lp-enrolled-empty"><p>%s</p></div>', | |
| 459 | + esc_html__( 'No students found.', 'learnpress' ) | |
| 460 | + ), | |
| 478 | 461 | 'wrap-end' => '</div>', |
| 479 | 462 | ); |
| 480 | 463 | $section_empty = apply_filters( |
| 481 | 464 | 'learn-press/admin/enrolled-students/table/empty/section', |
| @@ -622,9 +605,9 @@ | ||
| 622 | 605 | } |
| 623 | 606 | |
| 624 | 607 | $section = array( |
| 625 | 608 | 'row' => '<tr>', |
| 626 | - 'student-cell-open' => '<td class="lp-cell-student">', | |
| 609 | + 'student-cell-open' => '<td><div class="lp-cell-student">', | |
| 627 | 610 | 'avatar' => SingleInstructorTemplate::instance()->html_avatar( $userModel ), |
| 628 | 611 | 'meta-open' => '<div class="lp-meta">', |
| 629 | 612 | 'name' => sprintf( |
| 630 | 613 | '<span class="lp-name">%s</span>', |
| @@ -634,9 +617,9 @@ | ||
| 634 | 617 | '<span class="lp-email">%s</span>', |
| 635 | 618 | esc_html( $userModel->get_email() ) |
| 636 | 619 | ), |
| 637 | 620 | 'meta-close' => '</div>', |
| 638 | - 'student-cell-close' => '</td>', | |
| 621 | + 'student-cell-close' => '</div></td>', | |
| 639 | 622 | 'course-cell' => sprintf( |
| 640 | 623 | '<td class="lp-cell-course"><a href="%s">%s</a></td>', |
| 641 | 624 | esc_url_raw( $courseModel->get_permalink() ), |
| 642 | 625 | $courseModel->get_title() |
| @@ -724,26 +707,6 @@ | ||
| 724 | 707 | $total_pages |
| 725 | 708 | ); |
| 726 | 709 | |
| 727 | 710 | return Template::combine_components( $section ); |
| 728 | - } | |
| 729 | - | |
| 730 | - /** | |
| 731 | - * Sanitize date filter value in Y-m-d format. | |
| 732 | - * | |
| 733 | - * @param string $date | |
| 734 | - * | |
| 735 | - * @return string | |
| 736 | - */ | |
| 737 | - private static function sanitize_date_filter( $date ): string { | |
| 738 | - if ( ! is_scalar( $date ) ) { | |
| 739 | - return ''; | |
| 740 | - } | |
| 741 | - | |
| 742 | - $date = LP_Helper::sanitize_params_submitted( (string) $date ); | |
| 743 | - if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date ) ) { | |
| 744 | - return $date; | |
| 745 | - } | |
| 746 | - | |
| 747 | - return ''; | |
| 748 | 711 | } |
| 749 | 712 | } |