Taken quizzes dashboard for single users
-
Hello everyone,
if you are interested in creating a dashboard widget for the single users to see their taken quizzes, you can paste the following code to your functions.php:
/* DASHBOARD WIDGET */ /** * Add a widget to the dashboard. * * This function is hooked into the 'wp_dashboard_setup' action below. */ function example_add_dashboard_widgets() { wp_add_dashboard_widget( 'user_page_dashboard_widget', // Widget slug. 'Personal page', // Title. 'user_page_dashboard_widget_function' // Display function. ); } add_action( 'wp_dashboard_setup', 'example_add_dashboard_widgets' ); /** * Create the function to output the contents of our Dashboard Widget. */ function user_page_dashboard_widget_function() { ?> <h2>Hello <span style="font-weight: bold;"><?php $current_user = wp_get_current_user(); echo $current_user->user_login; ?></span> this is your recent activity</h2> <br /> <table style="width:100%"> <tr> <td> <?php global $wpdb; $current_user = wp_get_current_user(); $mail = $current_user->user_email; $mlw_qmn_table_limit = 999; $mlw_qmn_results_count = $wpdb->get_var( "SELECT COUNT(result_id) FROM " . $wpdb->prefix . "mlw_results WHERE deleted='0' AND email=%s",$mail ); if( isset($_GET['mlw_result_page'] ) ) { $mlw_qmn_result_page = $_GET['mlw_result_page'] + 1; $mlw_qmn_result_begin = $mlw_qmn_table_limit * $mlw_qmn_result_page ; } else { $mlw_qmn_result_page = 0; $mlw_qmn_result_begin = 0; } $mlw_qmn_result_left = $mlw_qmn_results_count - ($mlw_qmn_result_page * $mlw_qmn_table_limit); if (isset($_GET["quiz_id"]) && $_GET["quiz_id"] != "") { $mlw_quiz_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "mlw_results WHERE deleted='0' AND email=%s AND quiz_id=%d ORDER BY result_id DESC LIMIT %d, %d",$mail, intval($_GET["quiz_id"]), $mlw_qmn_result_begin, $mlw_qmn_table_limit ) ); } else { $mlw_quiz_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "mlw_results WHERE deleted='0' AND email=%s ORDER BY result_id DESC LIMIT %d, %d",$mail, $mlw_qmn_result_begin, $mlw_qmn_table_limit ) ); } ?> <h3 style="text-align: center;">Quizzes Taken</h3> <?php $quotes_list = ""; $display = ""; $alternate = ""; foreach($mlw_quiz_data as $mlw_quiz_info) { if($alternate) $alternate = ""; else $alternate = " class=\"alternate\""; $quotes_list .= "<tr{$alternate}>"; $quotes_list .= "<td>" . $mlw_quiz_info->quiz_name . "</td>"; if ($mlw_quiz_info->quiz_system == 0) { $quotes_list .= "<td class='post-title column-title'>" . $mlw_quiz_info->correct ." out of ".$mlw_quiz_info->total." or ".$mlw_quiz_info->correct_score."%</td>"; } if ($mlw_quiz_info->quiz_system == 1) { $quotes_list .= "<td>" . $mlw_quiz_info->point_score . " Points</td>"; } if ($mlw_quiz_info->quiz_system == 2) { $quotes_list .= "<td>Not Graded</td>"; } $quotes_list .= "<td>" . $mlw_quiz_info->time_taken ."</td>"; $quotes_list .= "</tr>"; } if( $mlw_qmn_result_page > 0 ) { $mlw_qmn_previous_page = $mlw_qmn_result_page - 2; $display .= "<a id=\"prev_page\" href=\"?page=mlw_quiz_results&&mlw_result_page=$mlw_qmn_previous_page\">Previous $mlw_qmn_table_limit Quizzes</a>"; if( $mlw_qmn_result_left > $mlw_qmn_table_limit ) { $display .= "<a id=\"next_page\" href=\"?page=mlw_quiz_results&&mlw_result_page=$mlw_qmn_result_page\">Next $mlw_qmn_table_limit Quizzes</a>"; } } else if( $mlw_qmn_result_page == 0 ) { if( $mlw_qmn_result_left > $mlw_qmn_table_limit ) { $display .= "<a id=\"next_page\" href=\"?page=mlw_quiz_results&&mlw_result_page=$mlw_qmn_result_page\">Next $mlw_qmn_table_limit Quizzes</a>"; } } else if( $mlw_qmn_result_left < $mlw_qmn_table_limit ) { $mlw_qmn_previous_page = $mlw_qmn_result_page - 2; $display .= "<a id=\"prev_page\" href=\"?page=mlw_quiz_results&&mlw_result_page=$mlw_qmn_previous_page\">Previous $mlw_qmn_table_limit Quizzes</a>"; } $display .= "<table class=\"widefat\">"; $display .= "<thead><tr> <th>Quiz Name</th> <th>Score</th> <th>Time Taken</th> </tr></thead>"; $display .= "<tbody id=\"the-list\">{$quotes_list}</tbody>"; $display .= "</table>"; echo $display; ?> </td> </tr> </table> <?php }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Taken quizzes dashboard for single users’ is closed to new replies.