Created
December 4, 2021 09:28
-
-
Save ibrahim-kardi/eb26e1af40e7f0d941dbfe87e5816370 to your computer and use it in GitHub Desktop.
[own_student_list] , need to use this to show all enrolled students list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tutorenrolled_student_list() { | |
global $wp_query, $wp; | |
$user = wp_get_current_user(); | |
$paged = 1; | |
$url = home_url( $wp->request ); | |
$url_path = parse_url($url, PHP_URL_PATH); | |
$basename = pathinfo($url_path, PATHINFO_BASENAME); | |
if ( isset($_GET['paged']) && is_numeric($_GET['paged']) ) { | |
$paged = $_GET['paged']; | |
} else { | |
is_numeric( $basename ) ? $paged = $basename : ''; | |
} | |
$per_page = 10; | |
$offset = ($per_page * $paged) - $per_page; | |
$course_id = isset( $_GET['course-id'] ) ? $_GET['course-id'] : ''; | |
$date_filter = isset( $_GET['date'] ) && $_GET['date'] != '' ? $_GET['date'] : ''; | |
$orderby = ''; | |
if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'registration_date' ) { | |
$orderby = 'registration_date'; | |
} else if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'course_taken' ) { | |
$orderby = 'course_taken'; | |
} else { | |
$orderby = 'student'; | |
} | |
$order = ( !isset( $_GET['order'] ) || $_GET['order'] !== 'desc' ) ? 'asc' : 'desc'; | |
$sort_order = array('order' => $order == 'asc' ? 'desc' : 'asc'); | |
$student_sort = http_build_query(array_merge($_GET, ( $orderby == 'student' ? $sort_order : array() ), array( 'orderby' => 'student' ))); | |
$registration_date_sort = http_build_query(array_merge($_GET, ( $orderby == 'registration_date' ? $sort_order : array() ), array( 'orderby' => 'registration_date' ))); | |
$course_taken_sort = http_build_query(array_merge($_GET, ( $orderby == 'course_taken' ? $sort_order : array() ), array( 'orderby' => 'course_taken' ))); | |
$student_sort_icon = $orderby == 'student' ? (strtolower( $order ) == 'asc' ? 'up' : 'down') : 'up'; | |
$register_sort_icon = $orderby == 'registration_date' ? (strtolower( $order ) == 'asc' ? 'up' : 'down') : 'up'; | |
$course_taken_sort_icon = $orderby == 'course_taken' ? (strtolower( $order ) == 'asc' ? 'up' : 'down') : 'up'; | |
$search_filter = isset( $_GET['search'] ) ? $_GET['search'] : ''; | |
$students = tutor_utils()->get_students_by_instructor( $user->ID, $offset, $per_page, $search_filter, $course_id, $date_filter, $sort_order, $order); | |
$courses = tutor_utils()->get_courses_by_instructor(); ?> | |
<div class="students-wrapper"> | |
<div class="tutor-table-responsive"> | |
<table class="tutor-table"> | |
<thead> | |
<tr> | |
<th> | |
<div class="inline-flex-center"> | |
<span class="color-text-subsued text-regular-small"> | |
<?php _e( 'Student', 'tutor-pro' ); ?> | |
</span> | |
<a href="?<?php echo $student_sort; ?>"> | |
<img src="<?php echo esc_url( tutor_pro()->url ) ; ?>assets/images/order-<?php echo $student_sort_icon; ?>.svg"/> | |
</a> | |
</div> | |
</th> | |
<th> | |
<div class="inline-flex-center"> | |
<span class="color-text-subsued text-regular-small"> | |
<?php _e( 'Registration Date', 'tutor-pro' ); ?> | |
</span> | |
<a href="?<?php echo $registration_date_sort; ?>"> | |
<img src="<?php echo esc_url( tutor_pro()->url ) ; ?>assets/images/order-<?php echo $register_sort_icon; ?>.svg"/> | |
</a> | |
</div> | |
</th> | |
<th> | |
<div class="inline-flex-center"> | |
<span class="color-text-subsued text-regular-small"> | |
<?php _e( 'Course Taken', 'tutor-pro' ); ?> | |
</span> | |
<a href="?<?php echo $course_taken_sort; ?>"> | |
<img src="<?php echo esc_url( tutor_pro()->url ); ?>assets/images/order-<?php echo $course_taken_sort_icon; ?>.svg"/> | |
</a> | |
</div> | |
</th> | |
<th class="tutor-shrink"></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php if ( count( $students['students'] ) ): ?> | |
<?php foreach( $students['students'] as $student ): ?> | |
<tr> | |
<td> | |
<?php | |
$first_name = get_user_meta( $student->ID, 'first_name', true ); | |
$last_name = get_user_meta( $student->ID, 'last_name', true ); | |
$name = esc_html__( $student->display_name ); | |
if ( '' === $name ) { | |
$name = $first_name.' '.$last_name; | |
} | |
?> | |
<div class="td-avatar"> | |
<?php | |
echo tutor_utils()->get_tutor_avatar( $student->ID ); | |
?> | |
<div> | |
<p class="color-text-primary text-medium-body"> | |
<?php echo $name; ?> | |
</p> | |
<p class="color-text-primary text-medium-body"> | |
<?php esc_html_e( $student->user_email ); ?> | |
</p> | |
</div> | |
</div> | |
</td> | |
<td> | |
<span class="color-text-primary text-regular-caption"> | |
<?php esc_html_e( tutor_get_formated_date( get_option( 'date_format' ), $student->user_registered ) ); ?> | |
</span> | |
</td> | |
<td> | |
<span class="color-text-primary text-regular-caption"> | |
<?php esc_html_e( $student->course_taken ); ?> | |
</span> | |
</td> | |
<td class="td-action-btns"> | |
<a href="<?php echo esc_url( tutor_utils()->tutor_dashboard_url()."analytics/student-details?student_id=$student->ID" ); ?>" class="btn-outline tutor-btn"> | |
<?php _e( 'Details', 'tutor-pro' ); ?> | |
</a> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
<?php else: ?> | |
<tr> | |
<td colspan="4"> | |
<?php _e( 'No record found', 'tutor-pro' ); ?> | |
</td> | |
</tr> | |
<?php endif;?> | |
</tbody> | |
</table>a | |
</div> | |
</div> | |
<?php } add_shortcode('own_student_list', 'tutorenrolled_student_list'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment