upskill-event-manager/hvac-community-events/templates/template-hvac-dashboard.php

220 lines
No EOL
8.6 KiB
PHP

<?php
/**
* Template Name: HVAC Trainer Dashboard
*
* This template handles the display of the HVAC Trainer Dashboard.
* It checks for user login and role, then displays stats and events.
*
* @package HVAC Community Events
* @subpackage Templates
* @author Roo
* @version 1.0.1
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// --- Security Check &amp; Data Loading ---
// Ensure user is logged in and has the correct role
if ( ! is_user_logged_in() || ! current_user_can( 'view_hvac_dashboard' ) ) {
// Redirect to login page or show an error message
wp_safe_redirect( home_url( '/community-login/' ) ); // Redirect to the custom login page
exit;
}
// Get the current user ID
$user_id = get_current_user_id();
// Include and instantiate the dashboard data class
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-dashboard-data.php';
$dashboard_data = new HVAC_Dashboard_Data( $user_id );
// Fetch data
$total_events = $dashboard_data->get_total_events_count();
$upcoming_events = $dashboard_data->get_upcoming_events_count();
$past_events = $dashboard_data->get_past_events_count();
$total_sold = $dashboard_data->get_total_tickets_sold();
$total_revenue = $dashboard_data->get_total_revenue();
$revenue_target = $dashboard_data->get_annual_revenue_target();
// --- Template Start ---
get_header(); // Use theme's header
?>
<div id="primary" class="content-area primary ast-container"> <!-- Use Astra container -->
<main id="main" class="site-main">
<!-- Dashboard Header &amp; Navigation -->
<div class="hvac-dashboard-header ast-flex ast-justify-content-space-between ast-align-items-center">
<h1 class="entry-title">Trainer Dashboard</h1> <!-- Standard WP title class -->
<div class="hvac-dashboard-nav">
<?php // TODO: Add icons to buttons via CSS ?>
<a href="<?php echo esc_url( home_url( '/trainer-profile/' ) ); ?>" class="ast-button ast-button-primary">Edit Profile</a> <?php // TODO: Implement trainer profile page ?>
<a href="<?php echo esc_url( home_url( '/manage-event/' ) ); ?>" class="ast-button ast-button-primary">Create Event</a>
<a href="<?php echo esc_url( wp_logout_url( home_url( '/community-login/' ) ) ); ?>" class="ast-button ast-button-primary">Logout</a>
</div>
</div>
<!-- Statistics Section -->
<section class="hvac-dashboard-stats">
<h2 class="section-title">Your Stats</h2>
<div class="ast-row hvac-stats-grid"> <!-- Use Astra grid row - Add custom class for 5 columns -->
<!-- Stat Card: Total Events -->
<div class="ast-col"> <!-- Use default col for flex/custom grid -->
<div class="hvac-stat-card">
<?php // TODO: Add icon via CSS ?>
<span class="stat-value"><?php echo esc_html( $total_events ); ?></span>
<span class="stat-label">Total Events</span>
</div>
</div>
<!-- Stat Card: Upcoming Events -->
<div class="ast-col">
<div class="hvac-stat-card">
<?php // TODO: Add icon via CSS ?>
<span class="stat-value"><?php echo esc_html( $upcoming_events ); ?></span>
<span class="stat-label">Upcoming Events</span>
</div>
</div>
<!-- Stat Card: Past Events -->
<div class="ast-col">
<div class="hvac-stat-card">
<?php // TODO: Add icon via CSS ?>
<span class="stat-value"><?php echo esc_html( $past_events ); ?></span>
<span class="stat-label">Past Events</span>
</div>
</div>
<!-- Stat Card: Total Tickets Sold -->
<div class="ast-col">
<div class="hvac-stat-card">
<?php // TODO: Add icon via CSS ?>
<span class="stat-value"><?php echo esc_html( $total_sold ); ?></span>
<span class="stat-label">Tickets Sold</span>
</div>
</div>
<!-- Stat Card: Total Revenue -->
<div class="ast-col">
<div class="hvac-stat-card">
<?php // TODO: Add icon via CSS ?>
<span class="stat-value">$<?php echo esc_html( number_format( $total_revenue, 2 ) ); ?></span>
<span class="stat-label">Total Revenue</span>
<?php // Note: Target revenue not shown in desired design ?>
</div>
</div>
</div> <!-- /.ast-row -->
</section>
<!-- Events Table Section -->
<section class="hvac-dashboard-events">
<h2 class="section-title">Your Events</h2>
<!-- Tab Filters -->
<?php
// --- Event Filters (Tabs) ---
$dashboard_url = get_permalink(); // Get the current page URL
$current_filter = isset( $_GET['event_time'] ) ? sanitize_key( $_GET['event_time'] ) : 'all'; // Change query param
$filter_tabs = [ // Change filter options
'all' => 'All Events',
'upcoming' => 'Upcoming',
'past' => 'Past'
];
?>
<div class="hvac-event-tabs">
<ul class="hvac-tabs-nav">
<?php foreach ($filter_tabs as $key => $label) :
$url = add_query_arg( 'event_time', $key, $dashboard_url );
$class = 'hvac-tab-link';
if ($key === $current_filter) {
$class .= ' active'; // Add active class
}
// Special case for 'all' filter link
if ($key === 'all') {
$url = remove_query_arg( 'event_time', $dashboard_url );
}
?>
<li><a href="<?php echo esc_url( $url ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( $label ); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<!-- Events Table -->
<?php
// Fetch events based on the new time filter ('all', 'upcoming', 'past')
// Note: get_events_table_data likely needs modification to handle time filtering instead of status
$events = $dashboard_data->get_events_table_data( $current_filter ); // TODO: Update HVAC_Dashboard_Data::get_events_table_data to accept 'all', 'upcoming', 'past'
?>
<div class="hvac-events-table-wrapper">
<table class="wp-list-table widefat fixed striped events-table hvac-events-table"> <!-- Add custom class for styling -->
<thead>
<tr>
<th scope="col" class="manage-column column-status">Status</th>
<th scope="col" class="manage-column column-title">Event Name</th>
<th scope="col" class="manage-column column-date">Date</th>
<th scope="col" class="manage-column column-organizer">Organizer</th>
<th scope="col" class="manage-column column-capacity">Capacity</th>
<th scope="col" class="manage-column column-sold">Sold</th>
<th scope="col" class="manage-column column-revenue">Revenue</th>
<th scope="col" class="manage-column column-actions">Actions</th> <!-- Added Actions Column -->
</tr>
</thead>
<tbody id="the-list">
<?php if ( ! empty( $events ) ) : ?>
<?php foreach ( $events as $event ) : ?>
<tr>
<td class="column-status"><?php echo esc_html( ucfirst( $event['status'] ) ); ?></td>
<td class="column-title">
<strong><a href="<?php echo esc_url( $event['link'] ); ?>" target="_blank"><?php echo esc_html( $event['name'] ); ?></a></strong>
<!-- Add Edit/View links below title if needed -->
</td>
<td class="column-date"><?php echo esc_html( date( 'Y-m-d H:i', $event['start_date_ts'] ) ); ?></td>
<td class="column-organizer"><?php
// Check if tribe_get_organizer function exists before calling
if ( function_exists( 'tribe_get_organizer' ) ) {
echo esc_html( tribe_get_organizer( $event['organizer_id'] ) );
} else {
echo 'Organizer ID: ' . esc_html( $event['organizer_id'] ); // Fallback
}
?></td>
<td class="column-capacity"><?php echo esc_html( $event['capacity'] ); ?></td>
<td class="column-sold"><?php echo esc_html( $event['sold'] ); ?></td>
<td class="column-revenue">$<?php echo esc_html( number_format( $event['revenue'], 2 ) ); ?></td>
<td class="column-actions">
<?php
// Link to the page containing the TEC CE submission form shortcode
$edit_url = add_query_arg( 'event_id', $event['id'], home_url( '/manage-event/' ) );
// Link to the custom event summary page
$summary_url = get_permalink( $event['id'] ); // Assumes custom template is loaded for event post type
?>
<?php // TODO: Add icons via CSS ?>
<a href="<?php echo esc_url( $edit_url ); ?>" class="ast-button ast-button-primary button-small">Edit</a>
<a href="<?php echo esc_url( $summary_url ); ?>" class="ast-button ast-button-primary button-small">View Summary</a>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="8">No events found.</td> <!-- Updated colspan -->
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</section>
</main> <!-- #main -->
</div> <!-- #primary -->
<?php
get_footer(); // Use theme's footer
?>