-
-
Save onwp/c2bb3b4fc39a661c341e5857a1a04b10 to your computer and use it in GitHub Desktop.
Custom results table
This file contains 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
/*------------------Group leader frontpage table------------------------*/ | |
function group_leader_data() { | |
ob_start(); | |
$user = wp_get_current_user(); | |
if ( in_array( 'group_leader', (array) $user->roles ) || in_array( 'administrator', (array) $user->roles )) { | |
$group_leader_id = $user->ID; | |
$user_group_ids = learndash_get_administrators_group_ids( $group_leader_id, true ); | |
if(!empty($user_group_ids)){ | |
$students = get_post_meta($user_group_ids[0], 'learndash_group_users_'.$user_group_ids[0], true); | |
$group_course_ids = learndash_group_enrolled_courses( $user_group_ids[0] ); | |
$beginningofyear = date('d-m-Y', strtotime('first day of january this year')); | |
$currentdate = date("d-m-Y"); | |
$group_leader_id = $user->ID; | |
$user_group_id = learndash_get_users_group_ids( $group_leader_id, true ); | |
$welcome_text_background = get_field('welcome_text_background', $user_group_id[0]); | |
$welcome_text = get_field('welcome_text', $user_group_id[0]); | |
?> | |
<style type="text/css"> | |
.custom-group-leader-data .table tbody tr:first-child{background:<?php echo $welcome_text_background; ?> !important; color:<?php echo $welcome_text; ?> !important;} | |
.yearbasefilter input[type="submit"], a.export, .uo-row.uo-groups-actions button{border: 2px solid <?php echo $welcome_text_background; ?> !important;color: <?php echo $welcome_text_background; ?> !important;} | |
.result-table-header .result-table-group span{color: <?php echo $welcome_text_background; ?> !important;} | |
</style> | |
<div class="table-responsive custom-group-leader-data"> | |
<div class="result-table-header"> | |
<div class="table-container"> | |
<div class="result-table-group"> | |
<h1>Resultatentabel</h1> | |
Groep: <span class="group-name"><?php echo get_the_title($user_group_ids[0]); ?></span> | |
</div> | |
<div class="calender-form"> | |
<!--<form name="yearfilter" method="get" action="" class="yearbasefilter"> | |
<label for="to">Begin datum</label> | |
<input type="text" id="startdate" class="date_picker" name="startdate" value="<?php //if($_GET['startdate']){ echo $_GET['startdate']; }else{echo $beginningofyear; } ?>"> | |
<label for="from">Eind datum</label> | |
<input type="text" id="enddate" class="date_picker" name="enddate" value="<?php //if($_GET['enddate']){ echo $_GET['enddate']; }else{echo $currentdate; } ?>"> | |
<input type="submit" name="submit" value="Zoeken"> | |
<p id="error-date"></p> | |
</form>--> | |
</div> | |
</div> | |
</div> | |
<div class="table-container"> | |
<div class="search-filter"> | |
<!--<form name="userfilter" method="get" action="" class="userfilter"> | |
<input type="text" name="search" placeholder="Gebruiker zoeken..." value="" required><input type="submit" class="finduser" name="finduser" value="Search"> | |
</form>--> | |
<form name="yearfilter" method="get" action="" class="yearbasefilter userfilter"> | |
<input type="text" name="search" placeholder="Gebruiker zoeken..." value=""> | |
<label for="to">Begin datum</label> | |
<input type="text" id="startdate" class="date_picker" name="startdate" value="<?php if($_GET['startdate']){ echo $_GET['startdate']; }else{echo $beginningofyear; } ?>"> | |
<label for="from">Eind datum</label> | |
<input type="text" id="enddate" class="date_picker" name="enddate" value="<?php if($_GET['enddate']){ echo $_GET['enddate']; }else{echo $currentdate; } ?>"> | |
<input type="submit" name="submit" value="Zoeken"> | |
<p id="error-date"></p> | |
</form> | |
</div> | |
<div id="dvData"> | |
<?php | |
/*-----------------------------search course base on date and user first name or last name---------------------------*/ | |
if(isset($_GET['submit'])){ | |
$startdate = date('Y-m-d', strtotime($_GET['startdate'])); | |
$enddate = date('Y-m-d', strtotime($_GET['enddate'])); | |
?> | |
<table class="table"> | |
<tr> | |
<th>Gebruikers</th> | |
<?php | |
$coursename = array(); | |
foreach ($group_course_ids as $group_course_id){ | |
$coursename[] = get_the_title($group_course_id); | |
} | |
sort($coursename); | |
foreach ($coursename as $singlename) { | |
?> | |
<th><?php echo $singlename; ?></th> | |
<?php | |
} | |
?> | |
</tr> | |
<?php | |
foreach($students as $student){ | |
$user_info = get_userdata($student); | |
global $wpdb; | |
$ld_activity_table = $wpdb->prefix . 'learndash_user_activity'; | |
$group_course_ids_string = implode(',', $group_course_ids); | |
$course_completions_query = "SELECT activity_completed, activity_status, course_id FROM $ld_activity_table WHERE activity_type = 'course' AND course_id IN ($group_course_ids_string) AND user_id = $user_info->ID AND activity_status = 1"; | |
$course_completions = $wpdb->get_results( $course_completions_query ); | |
$courseCompletedList = array(); | |
$key = 0; | |
foreach ($course_completions as $groupIds){ | |
$courseCompletedList[$key]['activity_completed'] = $groupIds->activity_completed; | |
$courseCompletedList[$key]['activity_status'] = $groupIds->activity_status; | |
$courseCompletedList[$key]['course_id'] = $groupIds->course_id; | |
$key++; | |
} | |
if( isset($_GET['startdate']) && isset($_GET['enddate']) && empty($_GET['search']) ){ | |
?> | |
<tr> | |
<td><?php | |
echo $user_info->first_name . " " . $user_info->last_name; | |
/*if($user_info->first_name == "" || $user_info->last_name == ""){ | |
echo $user_info->user_login; | |
}*/ | |
?></td> | |
<?php | |
$status = 0 ; | |
$groupCourseIds = $group_course_ids; | |
foreach ($groupCourseIds as $groupKey => $groupId){ | |
$status = 0 ; | |
if (!empty($course_completions)){ | |
foreach($courseCompletedList as $coursesKey => $courses){ | |
$activitycompleted = date('Y-m-d', $courses['activity_completed']); | |
//echo $activitycompleted; | |
if ( (($activitycompleted >= $startdate) && ($activitycompleted <= $enddate)) && empty($_GET['search'])): | |
$completedcoursedate = date('d-m-Y', $courses['activity_completed']); | |
if ($groupId == $courses['course_id']){ | |
?> | |
<td class="activity_status_completed" title="<?php echo $completedcoursedate; ?>"><?php echo $courses['activity_status']; ?></td> | |
<?php | |
$status = 1; | |
unset($groupCourseIds[$coursesKey]); | |
unset($courseCompletedList[$coursesKey]); | |
} | |
endif; | |
} | |
} | |
if ($status == 0){ | |
?> | |
<td></td> | |
<?php | |
} | |
} | |
?> | |
</tr> | |
<?php | |
} else if( (strtolower($user_info->first_name) == strtolower($_GET['search'])) || (strtolower($user_info->last_name) == strtolower($_GET['search'])) && (isset($_GET['startdate']) && isset($_GET['enddate']))){ | |
?> | |
<tr> | |
<td><?php | |
echo $user_info->first_name . " " . $user_info->last_name; | |
//echo $user_info->user_login; | |
?></td> | |
<?php | |
$status = 0 ; | |
$groupCourseIds = $group_course_ids; | |
foreach ($groupCourseIds as $groupKey => $groupId){ | |
$status = 0 ; | |
if (!empty($course_completions)){ | |
foreach($courseCompletedList as $coursesKey => $courses){ | |
$activitycompleted = date('Y-m-d', $courses['activity_completed']); | |
//echo $activitycompleted; | |
if ( (($activitycompleted >= $startdate) && ($activitycompleted <= $enddate)) && isset($_GET['search'])): | |
$completedcoursedate = date('d-m-Y', $courses['activity_completed']); | |
if ($groupId == $courses['course_id']){ | |
?> | |
<td class="activity_status_completed" title="<?php echo $completedcoursedate; ?>"><?php echo $courses['activity_status']; ?></td> | |
<?php | |
$status = 1; | |
unset($groupCourseIds[$coursesKey]); | |
unset($courseCompletedList[$coursesKey]); | |
} | |
endif; | |
} | |
} | |
if ($status == 0){ | |
?> | |
<td></td> | |
<?php | |
} | |
} | |
?> | |
</tr> | |
<?php | |
} | |
} | |
?> | |
</table> | |
<?php | |
/*-----------------------------end search course base on date and user first name or last name---------------------------*/ | |
} else { | |
$beginningofyear = date('Y-m-d', strtotime('first day of january this year')); | |
$currentdate = date("Y-m-d"); | |
?> | |
<table class="table"> | |
<tr> | |
<th>Gebruikers</th> | |
<?php | |
$coursename = array(); | |
foreach ($group_course_ids as $group_course_id){ | |
$coursename[] = get_the_title($group_course_id); | |
} | |
//sort($coursename); | |
foreach ($coursename as $singlename) { | |
?> | |
<th><?php echo $singlename; ?></th> | |
<?php | |
} | |
?> | |
</tr> | |
<?php | |
foreach($students as $student){ | |
$user_info = get_userdata($student); | |
global $wpdb; | |
$ld_activity_table = $wpdb->prefix . 'learndash_user_activity'; | |
$group_course_ids_string = implode(',', $group_course_ids); | |
$course_completions_query = "SELECT activity_completed, activity_status, course_id FROM $ld_activity_table WHERE activity_type = 'course' AND course_id IN ($group_course_ids_string) AND user_id = $user_info->ID AND activity_status = 1"; | |
$course_completions = $wpdb->get_results( $course_completions_query ); | |
$courseCompletedList = array(); | |
$key = 0; | |
foreach ($course_completions as $groupIds){ | |
$courseCompletedList[$key]['activity_completed'] = $groupIds->activity_completed; | |
$courseCompletedList[$key]['activity_status'] = $groupIds->activity_status; | |
$courseCompletedList[$key]['course_id'] = $groupIds->course_id; | |
$key++; | |
} | |
?> | |
<tr> | |
<td><?php echo $user_info->last_name . " " . $user_info->first_name; | |
//echo $user_info->user_login; ?></td> | |
<?php | |
$status = 0 ; | |
$groupCourseIds = $group_course_ids; | |
foreach ($groupCourseIds as $groupKey => $groupId){ | |
$status = 0 ; | |
if (!empty($course_completions)){ | |
foreach($courseCompletedList as $coursesKey => $courses){ | |
$activitycompleted = date('Y-m-d', $courses['activity_completed']); | |
if (($activitycompleted >= $beginningofyear) && ($activitycompleted <= $currentdate)): | |
$completedcoursedate = date('d-m-Y', $courses['activity_completed']); | |
if ($groupId == $courses['course_id']){ | |
?> | |
<td class="activity_status_completed" title="<?php echo $completedcoursedate; ?>"><?php echo $courses['activity_status']; ?></td> | |
<?php | |
$status = 1; | |
unset($groupCourseIds[$coursesKey]); | |
unset($courseCompletedList[$coursesKey]); | |
} | |
endif; | |
} | |
} | |
if ($status == 0){ | |
?> | |
<td></td> | |
<?php | |
} | |
} | |
?> | |
</tr> | |
<?php | |
} | |
?> | |
</table> | |
<?php } ?> | |
</div> | |
<a href="javascript:void(0);" class="export">Exporteer CSV</a> | |
</div> | |
<?php | |
} | |
} | |
else | |
{ | |
echo "<p>You don't have permission to access this page</p>"; | |
} | |
?> | |
</div> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode( 'groupleadertable', 'group_leader_data' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment