upskill-event-manager/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-dashboard.php
bengizmo cdef12ee80 feat(events): Implement fallback logic and UI for Create/Modify Event page
- Refactored fallback submission logic in `class-event-handler.php` to remove `wp_die`/`exit` calls and use redirects for error handling, enabling proper unit testing.
- Implemented meta-data saving (dates, venue, organizer) in the fallback logic using `update_post_meta`.
- Updated unit tests (`test-event-management.php`) to remove `markTestIncomplete` calls related to handler errors and uncommented meta assertions. Unit tests for fallback logic now pass.
- Added Instructions section and Return to Dashboard button to the event form shortcode (`display_event_form_shortcode`).
- Applied basic theme styling classes (`ast-container`, `notice`, `ast-button`) to the event form.
- Updated `docs/implementation_plan.md` to reflect completion of tasks 4.1-4.5 and set focus to Task 5.

Refs: Task 4.1, 4.2, 4.3, 4.4, 4.5
2025-04-01 11:46:24 -03:00

210 lines
No EOL
7.8 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.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// --- Security Check & 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 & Navigation -->
<div class="hvac-dashboard-header">
<h1 class="entry-title">Trainer Dashboard</h1> <!-- Standard WP title class -->
<div class="hvac-dashboard-nav">
<!-- TODO: Confirm these URLs once pages exist -->
<a href="<?php echo esc_url( home_url( '/submit-event/' ) ); ?>" class="ast-button ast-button-primary">Create Event</a> <!-- Use Astra button class -->
<a href="<?php echo esc_url( home_url( '/trainer-profile/' ) ); ?>" class="ast-button ast-button-secondary">View Profile</a>
<a href="<?php echo esc_url( wp_logout_url( home_url( '/community-login/' ) ) ); ?>" class="ast-button ast-button-secondary">Logout</a>
</div>
</div>
<!-- Statistics Section -->
<section class="hvac-dashboard-stats">
<h2>Your Stats</h2>
<div class="ast-row"> <!-- Use Astra grid row -->
<!-- Stat Card: Total Events -->
<div class="ast-col-md-6 ast-col-lg-4"> <!-- Adjust columns as needed -->
<div class="hvac-stat-card">
<h3>Total Events</h3>
<p><?php echo esc_html( $total_events ); ?></p>
</div>
</div>
<!-- Stat Card: Upcoming Events -->
<div class="ast-col-md-6 ast-col-lg-4">
<div class="hvac-stat-card">
<h3>Upcoming Events</h3>
<p><?php echo esc_html( $upcoming_events ); ?></p>
</div>
</div>
<!-- Stat Card: Past Events -->
<div class="ast-col-md-6 ast-col-lg-4">
<div class="hvac-stat-card">
<h3>Past Events</h3>
<p><?php echo esc_html( $past_events ); ?></p>
</div>
</div>
<!-- Stat Card: Total Tickets Sold -->
<div class="ast-col-md-6 ast-col-lg-4">
<div class="hvac-stat-card">
<h3>Tickets Sold</h3>
<p><?php echo esc_html( $total_sold ); ?></p>
</div>
</div>
<!-- Stat Card: Total Revenue -->
<div class="ast-col-md-6 ast-col-lg-4">
<div class="hvac-stat-card">
<h3>Total Revenue</h3>
<p>$<?php echo esc_html( number_format( $total_revenue, 2 ) ); ?></p>
<?php if ( $revenue_target ) : ?>
<small>Target: $<?php echo esc_html( number_format( $revenue_target, 2 ) ); ?></small>
<?php endif; ?>
</div>
</div>
</div> <!-- /.ast-row -->
</section>
<!-- Events Table Section -->
<section class="hvac-dashboard-events">
<h2>Your Events</h2>
<!-- Tab Filters -->
<?php
$dashboard_url = get_permalink(); // Get the current page URL
$current_filter = isset( $_GET['event_status'] ) ? sanitize_key( $_GET['event_status'] ) : 'all';
$filter_statuses = ['all', 'publish', 'draft', 'pending', 'private']; // Added private based on requirements/query
?>
<div class="hvac-event-filters">
<span>Filter: </span>
<?php foreach ($filter_statuses as $status) :
$url = add_query_arg( 'event_status', $status, $dashboard_url );
$class = 'ast-button ast-button-secondary';
if ($status === $current_filter) {
// Add a class or style for the active filter
// Using primary button style for active state as an example
$class = 'ast-button ast-button-primary';
}
// Special case for 'all' filter link
if ($status === 'all') {
$url = remove_query_arg( 'event_status', $dashboard_url );
}
?>
<a href="<?php echo esc_url( $url ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( ucfirst( $status ) ); ?></a>
<?php endforeach; ?>
</div>
<!-- Events Table -->
<?php
// $current_filter is already defined above
$events = $dashboard_data->get_events_table_data( $current_filter );
?>
<div class="hvac-events-table-wrapper">
<table class="wp-list-table widefat fixed striped events-table">
<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
// Assuming $event['id'] contains the event post ID
$edit_url = add_query_arg( ['action' => 'edit', 'event_id' => $event['id']], home_url( '/submit-event/' ) );
$summary_url = add_query_arg( ['event_id' => $event['id']], home_url( '/event-summary/' ) ); // TODO: Confirm summary page slug
?>
<a href="<?php echo esc_url( $edit_url ); ?>">Edit</a> |
<a href="<?php echo esc_url( $summary_url ); ?>">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
?>