upskill-event-manager/templates/page-find-trainer.php
bengizmo 2446997385 feat: Complete MapGeo trainer correlation system with certification colors
• Resolved critical MapGeo marker correlation issue where all clicks showed "William Ramsey"
• Replaced complex 600+ line console interception with streamlined 150-line solution
• Implemented simplified MapGeo custom action system using direct profile ID correlation
• Added Champions detection to prevent modal popups for measureQuick Champions
• Implemented certification_color field with automatic hex color assignment:
  - Certified measureQuick Champion: #f19a42
  - Certified measureQuick Trainer: #5077bb
  - Others/Default: #f0f7e8
• Added automatic color migration for existing trainer profiles
• Enhanced AJAX handler to return both certification_type and certification_color
• Deployed complete solution to staging with 295 markers detected
• System now shows correct trainer modals with perfect correlation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Ben Reed <ben@tealmaker.com>
2025-08-05 06:23:05 -03:00

415 lines
No EOL
18 KiB
PHP

<?php
/**
* Template Name: Find a Trainer
* Template for displaying the Find a Trainer page
*
* @package HVAC_Plugin
* @since 1.0.0
*/
// Define constant to identify we're in a page template
define('HVAC_IN_PAGE_TEMPLATE', true);
// Get header
get_header();
// Initialize required classes
if (class_exists('HVAC_Find_Trainer_Page')) {
$find_trainer = HVAC_Find_Trainer_Page::get_instance();
}
if (class_exists('HVAC_Trainer_Directory_Query')) {
$directory_query = HVAC_Trainer_Directory_Query::get_instance();
}
// Get trainers for initial display with user status filtering
$trainers = [];
$total_pages = 1;
// Get approved user IDs first
$user_query = new WP_User_Query([
'meta_query' => [
[
'key' => 'account_status',
'value' => ['approved', 'active', 'inactive'],
'compare' => 'IN'
]
],
'fields' => 'ID'
]);
$approved_user_ids = $user_query->get_results();
if (!empty($approved_user_ids)) {
// Query trainer profiles for approved users only
$args = [
'post_type' => 'trainer_profile',
'posts_per_page' => 12,
'post_status' => 'publish',
'meta_query' => [
'relation' => 'AND',
[
'key' => 'is_public_profile',
'value' => '1',
'compare' => '='
],
[
'key' => 'user_id',
'value' => $approved_user_ids,
'compare' => 'IN'
]
]
];
$query = new WP_Query($args);
$total_pages = $query->max_num_pages;
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$profile_id = get_the_ID();
$user_id = get_post_meta($profile_id, 'user_id', true);
// Get real event count for this trainer
$event_count = 0;
if ($user_id && function_exists('tribe_get_events')) {
$events = tribe_get_events([
'author' => $user_id,
'eventDisplay' => 'all',
'posts_per_page' => -1,
'fields' => 'ids'
]);
$event_count = count($events);
}
$trainers[] = [
'profile_id' => $profile_id,
'user_id' => $user_id,
'name' => get_post_meta($profile_id, 'trainer_display_name', true),
'city' => get_post_meta($profile_id, 'trainer_city', true),
'state' => get_post_meta($profile_id, 'trainer_state', true),
'certification' => get_post_meta($profile_id, 'certification_type', true),
'profile_image' => get_post_meta($profile_id, 'profile_image_url', true),
'event_count' => $event_count
];
}
}
wp_reset_postdata();
// Sort trainers: Certified measureQuick Trainers first, Champions last
usort($trainers, function($a, $b) {
$a_cert = $a['certification'];
$b_cert = $b['certification'];
// Define sort order: Trainers = 1, Champions = 2, Others = 3
$a_priority = 3; // Default for others
$b_priority = 3; // Default for others
if ($a_cert === 'Certified measureQuick Trainer') {
$a_priority = 1;
} elseif ($a_cert === 'Certified measureQuick Champion') {
$a_priority = 2;
}
if ($b_cert === 'Certified measureQuick Trainer') {
$b_priority = 1;
} elseif ($b_cert === 'Certified measureQuick Champion') {
$b_priority = 2;
}
// Primary sort by certification priority
if ($a_priority !== $b_priority) {
return $a_priority - $b_priority;
}
// Secondary sort by name (alphabetical)
return strcasecmp($a['name'], $b['name']);
});
}
// Enqueue required scripts and styles
wp_enqueue_style('hvac-find-trainer', HVAC_PLUGIN_URL . 'assets/css/find-trainer.css', [], HVAC_VERSION);
wp_enqueue_script('hvac-find-trainer', HVAC_PLUGIN_URL . 'assets/js/find-trainer.js', ['jquery'], HVAC_VERSION, true);
wp_enqueue_style('dashicons');
// Localize script with necessary data
wp_localize_script('hvac-find-trainer', 'hvac_find_trainer', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('hvac_find_trainer'),
'map_id' => '5872',
'messages' => [
'loading' => __('Loading...', 'hvac'),
'error' => __('An error occurred. Please try again.', 'hvac'),
'no_results' => __('No trainers found matching your criteria.', 'hvac'),
'form_error' => __('Please check the form and try again.', 'hvac'),
'form_success' => __('Your message has been sent! Check your inbox for more details.', 'hvac')
]
]);
?>
<div class="hvac-find-trainer-page">
<div class="ast-container">
<!-- Page Title -->
<h1 class="hvac-page-title">Find a Trainer</h1>
<!-- Container 1: Summary -->
<div class="hvac-summary-container">
<p>Find certified HVAC trainers in your area. Use the interactive map and filters below to discover trainers who match your specific needs. Click on any trainer to view their profile and contact them directly.</p>
</div>
<!-- Container 2: Map & Filters -->
<div class="hvac-map-filters-container">
<!-- Container 3: Map (2/3 width) -->
<div class="hvac-map-section">
<?php
// Display MapGeo map
if (shortcode_exists('display-map')) {
echo do_shortcode('[display-map id="5872"]');
} else {
// Fallback if MapGeo is not installed
?>
<div class="hvac-map-placeholder" style="height: 450px; background: #f5f5f5; display: flex; align-items: center; justify-content: center; color: #666;">
<p>Map plugin not installed</p>
</div>
<?php
}
?>
</div>
<!-- Container 4: Filters (1/3 width) -->
<div class="hvac-filters-section">
<!-- Search Box -->
<div class="hvac-search-box">
<input type="text" id="hvac-trainer-search" placeholder="Search..." aria-label="Search trainers">
<span class="dashicons dashicons-search"></span>
</div>
<!-- Filter Label with Clear Button -->
<div class="hvac-filters-header">
<span class="hvac-filters-label">Filters:</span>
<button class="hvac-clear-filters" type="button" style="display: none;">
Clear All
</button>
</div>
<!-- Filter Buttons -->
<button class="hvac-filter-btn" data-filter="state" type="button">
State / Province
<span class="dashicons dashicons-arrow-down-alt2"></span>
</button>
<button class="hvac-filter-btn" data-filter="business_type" type="button">
Business Type
<span class="dashicons dashicons-arrow-down-alt2"></span>
</button>
<button class="hvac-filter-btn" data-filter="training_format" type="button">
Training Format
<span class="dashicons dashicons-arrow-down-alt2"></span>
</button>
<button class="hvac-filter-btn" data-filter="training_resources" type="button">
Training Resources
<span class="dashicons dashicons-arrow-down-alt2"></span>
</button>
<!-- Active Filters Display -->
<div class="hvac-active-filters"></div>
</div>
</div>
<!-- Container 5: Trainer Directory -->
<div class="hvac-trainer-directory-container">
<div class="hvac-trainer-grid">
<?php if (!empty($trainers)) : ?>
<?php foreach ($trainers as $trainer) :
// Get featured image or use default avatar
$featured_image = !empty($trainer['profile_image']) ? $trainer['profile_image'] : false;
?>
<div class="hvac-trainer-card<?php
if ($trainer['certification'] === 'Certified measureQuick Champion') {
echo ' hvac-champion-card';
} elseif ($trainer['certification'] === 'Certified measureQuick Trainer') {
echo ' hvac-trainer-card-certified';
}
?>" data-profile-id="<?php echo esc_attr($trainer['profile_id']); ?>" data-event-count="<?php echo esc_attr($trainer['event_count']); ?>">
<div class="hvac-trainer-card-content">
<!-- Featured Image -->
<div class="hvac-trainer-image">
<?php if ($featured_image) : ?>
<img src="<?php echo esc_url($featured_image); ?>" alt="<?php echo esc_attr($trainer['name']); ?>">
<?php else : ?>
<div class="hvac-trainer-avatar">
<span class="dashicons dashicons-businessperson"></span>
</div>
<?php endif; ?>
<!-- mQ Certified Trainer Badge Overlay -->
<?php if ($trainer['certification'] === 'Certified measureQuick Trainer') : ?>
<div class="hvac-mq-badge-overlay">
<img src="/wp-content/uploads/2025/08/mQ-Certified-trainer.png" alt="measureQuick Certified Trainer" class="hvac-mq-badge">
</div>
<?php endif; ?>
</div>
<!-- Trainer Info -->
<div class="hvac-trainer-details">
<!-- Name (conditional clickable) -->
<h3 class="hvac-trainer-name">
<?php if ($trainer['certification'] === 'Certified measureQuick Champion') : ?>
<!-- Champions are not clickable -->
<span class="hvac-champion-name"><?php echo esc_html($trainer['name']); ?></span>
<?php else : ?>
<!-- Trainers are clickable -->
<a href="#" class="hvac-open-profile" data-profile-id="<?php echo esc_attr($trainer['profile_id']); ?>">
<?php echo esc_html($trainer['name']); ?>
</a>
<?php endif; ?>
</h3>
<!-- Location -->
<p class="hvac-trainer-location">
<?php echo esc_html($trainer['city']); ?>, <?php echo esc_html($trainer['state']); ?>
</p>
<!-- Certification -->
<p class="hvac-trainer-certification">
<?php echo esc_html($trainer['certification'] ?: 'HVAC Trainer'); ?>
</p>
<!-- See Events (hidden for v1) -->
<!--
<a href="#" class="hvac-see-events" data-trainer-id="<?php echo esc_attr($trainer['user_id']); ?>">
<span class="dashicons dashicons-calendar-alt"></span> See Events
</a>
-->
</div>
</div>
</div>
<?php endforeach; ?>
<?php else : ?>
<div class="hvac-no-trainers">
<p>No trainers found. Please try adjusting your search or filters.</p>
</div>
<?php endif; ?>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1) : ?>
<div class="hvac-pagination">
<?php
echo paginate_links([
'total' => $total_pages,
'current' => 1,
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
'type' => 'plain'
]);
?>
</div>
<?php endif; ?>
</div>
<!-- Container 6: CTA Section -->
<div class="hvac-cta-container">
<p class="hvac-cta-text">Are you an HVAC Trainer that wants to be listed in our directory?</p>
<a href="/trainer-registration/" class="hvac-cta-button">Become A Trainer</a>
</div>
</div>
</div>
<!-- Filter Modal Template -->
<div id="hvac-filter-modal" class="hvac-filter-modal" style="display: none;">
<div class="hvac-filter-modal-content">
<h3 class="hvac-filter-modal-title"></h3>
<div class="hvac-filter-options"></div>
<button class="hvac-filter-apply">Apply</button>
</div>
</div>
<!-- Trainer Profile Modal Template -->
<div id="hvac-trainer-modal" class="hvac-trainer-modal" style="display: none;">
<div class="hvac-trainer-modal-content">
<!-- Close Button -->
<button class="hvac-modal-close" aria-label="Close">
<span class="dashicons dashicons-no"></span>
</button>
<!-- Modal Title -->
<h2 class="hvac-modal-title">[Trainer Name]</h2>
<!-- Container 1: Profile Info -->
<div class="hvac-modal-profile">
<div class="hvac-modal-image">
<img src="" alt="">
</div>
<div class="hvac-modal-info">
<p class="hvac-modal-location">[trainer_city], [trainer_state]</p>
<p class="hvac-modal-certification">[certification_type]</p>
<p class="hvac-modal-business">[business_type]</p>
<p class="hvac-modal-events">Total Training Events: <span>[#]</span></p>
</div>
</div>
<!-- Container 2: Training Details -->
<div class="hvac-modal-training">
<div class="hvac-training-row">
<strong>Training Formats:</strong> <span class="hvac-training-formats">[training_formats]</span>
</div>
<div class="hvac-training-row">
<strong>Training Locations:</strong> <span class="hvac-training-locations">[training_locations]</span>
</div>
<div class="hvac-training-events">
<strong>Upcoming Events:</strong>
<ul class="hvac-events-list">
<!-- Events populated via JS -->
</ul>
</div>
</div>
<!-- Container 3: Contact Form -->
<div class="hvac-modal-contact">
<h3>Contact</h3>
<form id="hvac-contact-form" class="hvac-contact-form">
<div class="hvac-form-row">
<input type="text" name="first_name" placeholder="First Name" required>
<input type="text" name="last_name" placeholder="Last Name" required>
</div>
<div class="hvac-form-row">
<input type="email" name="email" placeholder="Email" required>
<input type="tel" name="phone" placeholder="Phone Number">
</div>
<div class="hvac-form-row">
<input type="text" name="city" placeholder="City">
<input type="text" name="state_province" placeholder="State/Province">
</div>
<div class="hvac-form-full">
<input type="text" name="company" placeholder="Company">
</div>
<div class="hvac-form-full">
<textarea name="message" placeholder="Message" rows="4"></textarea>
</div>
<input type="hidden" name="trainer_id" value="">
<input type="hidden" name="trainer_profile_id" value="">
<button type="submit" class="hvac-form-submit">Submit</button>
</form>
<!-- Success/Error Messages -->
<div class="hvac-form-message hvac-form-success" style="display: none;">
Your message has been sent! Check your inbox for more details.
</div>
<div class="hvac-form-message hvac-form-error" style="display: none;">
There was an error sending your message. Please try again.
</div>
</div>
</div>
</div>
<?php
// Get footer
get_footer();
?>