132 lines
No EOL
6.6 KiB
PHP
132 lines
No EOL
6.6 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: View Results
|
|
*
|
|
* This template is used for the page where Quiz Managers can view assessment results.
|
|
*
|
|
* @package Quiztech
|
|
*/
|
|
|
|
// Ensure the user is logged in and has the appropriate capability.
|
|
// Capability required to view results (tied to managing jobs).
|
|
$required_capability = 'edit_jobs'; // Or a more specific 'view_results' capability if created
|
|
|
|
if ( ! is_user_logged_in() || ! current_user_can( $required_capability ) ) {
|
|
// Redirect to login page or show an error message.
|
|
wp_safe_redirect( wp_login_url( get_permalink() ) );
|
|
exit;
|
|
// Alternatively, display an error message:
|
|
// wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'quiztech' ), 403 );
|
|
}
|
|
|
|
// Get Job ID from query parameter
|
|
$job_id = isset( $_GET['job_id'] ) ? absint( $_GET['job_id'] ) : 0;
|
|
$job_post = null;
|
|
$error_message = '';
|
|
|
|
if ( ! $job_id ) {
|
|
$error_message = __( 'No Job ID specified.', 'quiztech' );
|
|
} else {
|
|
$job_post = get_post( $job_id );
|
|
if ( ! $job_post || $job_post->post_type !== 'job' ) {
|
|
$error_message = __( 'Invalid Job ID specified.', 'quiztech' );
|
|
$job_post = null; // Ensure job_post is null if invalid
|
|
}
|
|
// Optional: Check if the current user owns the job or has higher privileges
|
|
// if ( $job_post && $job_post->post_author != get_current_user_id() && ! current_user_can('edit_others_jobs') ) {
|
|
// $error_message = __( 'You do not have permission to view results for this job.', 'quiztech' );
|
|
// $job_post = null;
|
|
// }
|
|
}
|
|
|
|
get_header(); ?>
|
|
|
|
<div id="primary" class="content-area">
|
|
<main id="main" class="site-main">
|
|
|
|
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
|
<header class="entry-header">
|
|
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
|
|
</header><!-- .entry-header -->
|
|
|
|
<div class="entry-content">
|
|
|
|
<?php if ( $error_message ) : ?>
|
|
<div class="notice notice-error"><p><?php echo esc_html( $error_message ); ?></p></div>
|
|
<p><a href="<?php echo esc_url( get_post_type_archive_link('job') ?: home_url('/manage-jobs/') ); ?>"><?php esc_html_e('« Back to Jobs', 'quiztech'); ?></a></p> <?php // Link back to job list ?>
|
|
<?php elseif ( $job_post ) : ?>
|
|
<h2><?php printf( esc_html__( 'Results for Job: %s', 'quiztech' ), esc_html( get_the_title( $job_post ) ) ); ?></h2>
|
|
|
|
<?php
|
|
$args = array(
|
|
'post_type' => 'user_evaluation',
|
|
'post_status' => 'any', // Show completed, in-progress, etc.
|
|
'posts_per_page' => -1, // Show all for this job
|
|
'meta_query' => array(
|
|
array(
|
|
'key' => '_quiztech_job_id', // Make sure this meta key is correct
|
|
'value' => $job_id,
|
|
'compare' => '=',
|
|
'type' => 'NUMERIC',
|
|
),
|
|
),
|
|
'orderby' => 'date', // Order by submission date
|
|
'order' => 'DESC',
|
|
);
|
|
$evaluations_query = new WP_Query( $args );
|
|
?>
|
|
|
|
<?php if ( $evaluations_query->have_posts() ) : ?>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th><?php esc_html_e( 'Applicant Email', 'quiztech' ); ?></th>
|
|
<th><?php esc_html_e( 'Status', 'quiztech' ); ?></th>
|
|
<th><?php esc_html_e( 'Score', 'quiztech' ); ?></th>
|
|
<th><?php esc_html_e( 'Submitted', 'quiztech' ); ?></th>
|
|
<th><?php esc_html_e( 'Actions', 'quiztech' ); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php while ( $evaluations_query->have_posts() ) : $evaluations_query->the_post(); ?>
|
|
<?php
|
|
$evaluation_id = get_the_ID();
|
|
$applicant_email = get_post_meta( $evaluation_id, '_quiztech_applicant_email', true ); // Make sure meta key is correct
|
|
$score = get_post_meta( $evaluation_id, '_quiztech_score', true ); // Make sure meta key is correct
|
|
$status = get_post_status_object( get_post_status( $evaluation_id ) );
|
|
$status_label = $status ? $status->label : get_post_status( $evaluation_id );
|
|
$edit_link = get_edit_post_link( $evaluation_id );
|
|
?>
|
|
<tr>
|
|
<td><?php echo esc_html( $applicant_email ?: __( 'N/A', 'quiztech' ) ); ?></td>
|
|
<td><?php echo esc_html( $status_label ); ?></td>
|
|
<td><?php echo esc_html( $score ?: __( 'N/A', 'quiztech' ) ); ?></td>
|
|
<td><?php echo esc_html( get_the_date() ); ?></td>
|
|
<td>
|
|
<?php if ( $edit_link ) : ?>
|
|
<a href="<?php echo esc_url( $edit_link ); ?>" target="_blank"><?php esc_html_e( 'View Details', 'quiztech' ); ?></a>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endwhile; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php wp_reset_postdata(); // Restore original Post Data ?>
|
|
<?php else : ?>
|
|
<p><?php esc_html_e( 'No results found for this job yet.', 'quiztech' ); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<?php else : ?>
|
|
<?php // This case should be caught by $error_message check above, but as a fallback: ?>
|
|
<p><?php esc_html_e( 'Could not load job details.', 'quiztech' ); ?></p>
|
|
<?php endif; ?>
|
|
|
|
</div><!-- .entry-content -->
|
|
|
|
</article><!-- #post-<?php the_ID(); ?> -->
|
|
|
|
</main><!-- #main -->
|
|
</div><!-- #primary -->
|
|
|
|
<?php
|
|
get_footer();
|