# HVAC Trainer System Documentation This document provides comprehensive documentation for all functionality related to the HVAC Trainer custom post type and Find A Trainer page in the HVAC Community Events plugin. ## Table of Contents 1. [System Overview](#system-overview) 2. [Trainer Profile Custom Post Type](#trainer-profile-custom-post-type) 3. [Find A Trainer Page](#find-a-trainer-page) 4. [MapGeo Integration](#mapgeo-integration) 5. [User Roles & Permissions](#user-roles--permissions) 6. [API Reference](#api-reference) 7. [Frontend Components](#frontend-components) 8. [Database Schema](#database-schema) 9. [Performance Optimizations](#performance-optimizations) 10. [Troubleshooting](#troubleshooting) ## System Overview The HVAC Trainer System is a comprehensive solution for managing trainer profiles and providing a public directory with interactive map functionality. The system consists of: - **Custom Post Type**: `trainer_profile` for storing trainer information - **Find A Trainer Page**: Public-facing directory with search and filtering - **MapGeo Integration**: Interactive map with trainer markers and modals - **Profile Management**: Complete CRUD operations for trainer profiles - **Taxonomy System**: Categorization for business types, training formats, etc. ### Architecture Diagram ``` WordPress Users (hvac_trainer/hvac_master_trainer) ↓ Trainer Profile Custom Post Type (trainer_profile) ↓ Find A Trainer Page ← MapGeo Integration → Interactive Map ↓ Search/Filter System → AJAX Handlers → Database Queries ``` ## Trainer Profile Custom Post Type ### Overview The `trainer_profile` custom post type stores comprehensive information about HVAC trainers, including personal details, certifications, business information, and location data. ### Core Files - **Main Handler**: `includes/class-hvac-trainer-profile-manager.php` - **Settings**: `includes/class-hvac-trainer-profile-settings.php` - **Status Management**: `includes/class-hvac-trainer-status.php` ### Custom Fields Reference #### Personal Information | Field Name | Type | Description | Example | |------------|------|-------------|---------| | `trainer_first_name` | string | First name | "John" | | `trainer_last_name` | string | Last name | "Smith" | | `trainer_display_name` | string | Public display name | "John Smith" | | `trainer_city` | string | City location | "Chicago" | | `trainer_state` | string | State/Province | "Illinois" | | `trainer_country` | string | Country | "USA" | | `profile_image_url` | string | Profile photo URL | "https://..." | | `linkedin_profile_url` | string | LinkedIn profile | "https://linkedin..." | #### Certification Details | Field Name | Type | Description | Values | |------------|------|-------------|--------| | `certification_type` | string | Certification level | "Certified measureQuick Trainer", "Certified measureQuick Champion" | | `certification_status` | string | Current status | "Active", "Expired", "Pending", "Disabled" | | `certification_color` | string | Hex color for MapGeo | "#5077bb", "#f19a42", "#f0f7e8" | | `date_certified` | string | Certification date | "2024-01-15" | | `personal_accreditation` | string | Additional certifications | Free text | #### Business Information | Field Name | Type | Description | |------------|------|-------------| | `annual_revenue_target` | string | Revenue goals | | `application_details` | string | Registration application details | #### System Fields | Field Name | Type | Description | |------------|------|-------------| | `user_id` | integer | WordPress user ID | | `is_public_profile` | string | Visibility flag ("1" or "0") | | `_last_geocode_attempt` | string | Last geocoding timestamp | | `geocoded_lat` | string | Latitude coordinate | | `geocoded_lng` | string | Longitude coordinate | ### Taxonomies #### Business Type (`business_type`) - Manufacturer - Distributor - Contractor - Consultant - Educator - Government - Other #### Training Audience (`training_audience`) - Anyone (open to the public) - Industry professionals - Internal staff in my company - Registered students/members of my org/institution #### Training Formats (`training_formats`) - In-person - Virtual - Hybrid - On-demand #### Training Locations (`training_locations`) - Online - Local - Regional Travel - National Travel - International Travel #### Training Resources (`training_resources`) - Classroom - Training Lab - Ducted Furnace(s) - Ducted Air Handler(s) - Ducted Air Conditioner(s) - Ducted Heat Pump(s) - Ductless Heat Pump(s) - Training Manuals - Presentation Slides - LMS Platform / SCORM Files - Custom Curriculum - Other ### Profile Creation Workflow 1. **User Registration**: User completes registration form 2. **Role Assignment**: User assigned `hvac_trainer` or `hvac_master_trainer` role 3. **Profile Creation**: System automatically creates `trainer_profile` post 4. **Data Population**: Registration data mapped to profile fields 5. **Geocoding**: System attempts to geocode trainer location 6. **Approval Process**: Admin reviews and approves profile for public display ### Profile Management #### Creating Profiles Programmatically ```php $profile_manager = HVAC_Trainer_Profile_Manager::get_instance(); $profile_data = [ 'trainer_first_name' => 'John', 'trainer_last_name' => 'Smith', 'trainer_city' => 'Chicago', 'trainer_state' => 'Illinois', 'certification_type' => 'Certified measureQuick Trainer', 'user_id' => 123, 'is_public_profile' => '1' ]; $profile_id = $profile_manager->create_profile($profile_data); ``` #### Updating Profiles ```php $profile_manager->update_profile($profile_id, $updated_data); ``` #### Retrieving Profiles ```php // Get single profile $profile = $profile_manager->get_profile($profile_id); // Get all public profiles $public_profiles = $profile_manager->get_public_profiles(); // Get profiles by criteria $filtered_profiles = $profile_manager->get_profiles_by_criteria([ 'state' => 'Illinois', 'certification_type' => 'Certified measureQuick Trainer' ]); ``` ## Find A Trainer Page ### Overview The Find A Trainer page (`/find-a-trainer/`) provides a public directory of approved trainer profiles with interactive search, filtering, and map functionality. ### Core Files - **Page Handler**: `includes/find-trainer/class-hvac-find-trainer-page.php` - **Directory Query**: `includes/find-trainer/class-hvac-trainer-directory-query.php` - **Contact Handler**: `includes/find-trainer/class-hvac-contact-form-handler.php` - **Template**: `templates/page-find-trainer.php` ### Features #### Search Functionality - **Text Search**: Search by trainer name, city, or state - **Real-time Results**: AJAX-powered instant search results - **Autocomplete**: Suggestions as user types #### Filtering System - **State/Province Filter**: Location-based filtering - **Business Type Filter**: Filter by trainer business type - **Training Format Filter**: Filter by available training formats - **Training Resources Filter**: Filter by available resources - **Multiple Filters**: Combine multiple filter criteria #### Directory Display - **Card Layout**: Clean trainer cards with essential information - **Pagination**: Performance-optimized pagination system - **Sorting**: Certified Trainers first, then Champions, then alphabetical - **Champion Distinction**: Special styling for measureQuick Champions #### Contact Integration - **Contact Forms**: Direct contact forms for each trainer - **Email Integration**: Automated email delivery to trainers - **Lead Tracking**: Track contact form submissions ### AJAX Endpoints | Endpoint | Purpose | Parameters | |----------|---------|------------| | `hvac_filter_trainers` | Filter trainers | `filters`, `page`, `per_page` | | `hvac_search_trainers` | Search trainers | `search`, `page`, `per_page` | | `hvac_get_filter_options` | Get filter options | None | | `hvac_submit_contact_form` | Submit contact form | `trainer_id`, `name`, `email`, `message` | ### Frontend Implementation #### JavaScript Integration ```javascript // Initialize Find A Trainer functionality jQuery(document).ready(function($) { HVAC_FindTrainer.init({ ajax_url: hvac_find_trainer.ajax_url, nonce: hvac_find_trainer.nonce, filters: { state: [], business_type: [], training_format: [] } }); }); ``` #### CSS Classes | Class | Purpose | |-------|---------| | `.hvac-trainer-card` | Individual trainer card container | | `.hvac-trainer-card-certified` | Certified trainer styling | | `.hvac-champion-card` | Champion trainer styling | | `.hvac-trainer-filters` | Filter panel container | | `.hvac-search-box` | Search input container | | `.hvac-trainer-modal` | Trainer profile modal | ## MapGeo Integration ### Overview The MapGeo integration provides an interactive map showing trainer locations with clickable markers that open detailed trainer modals. ### Core Files - **Integration Handler**: `includes/find-trainer/class-hvac-mapgeo-integration.php` - **Map Configuration**: Integrated in Find A Trainer page template ### Features #### Interactive Map - **Map ID**: 5872 (configured in MapGeo plugin) - **Marker Display**: Trainers with geocoded coordinates appear as markers - **Color Coding**: Different colors based on certification type - **Click Handlers**: Custom click actions for trainer markers #### Performance Optimizations - **Request Deduplication**: Prevents duplicate AJAX calls - **Caching System**: Caches trainer data for instant subsequent access - **Click Throttling**: Prevents rapid-fire clicking issues - **Fallback Handling**: Graceful degradation when data unavailable #### Modal System - **Trainer Profiles**: Complete trainer information in popup modals - **Champion Filtering**: Champions don't show modals (directory-only display) - **Contact Integration**: Direct contact forms within modals - **Responsive Design**: Mobile-optimized modal display ### Technical Implementation #### MapGeo Marker Configuration ```php public function modify_map_layout($meta, $map_id = null) { // Only process for our specific map (5872) if ($map_id && $map_id != $this->map_id) { return $meta; } // Configure markers with trainer profile data foreach ($meta['markers'] as &$marker) { $trainer_profile_id = $this->find_trainer_profile_by_name($marker['title']); if ($trainer_profile_id) { $marker['action'] = 'hvac_show_trainer_modal'; $marker['hvac_profile_id'] = $trainer_profile_id; $marker['id'] = 'trainer_' . $trainer_profile_id; } } return $meta; } ``` #### JavaScript Modal Handler ```javascript window.hvac_show_trainer_modal = function(markerData) { var profileId = markerData.hvac_profile_id; // Check cache first for immediate response if (window.hvacTrainerDataCache[profileId]) { var cachedData = window.hvacTrainerDataCache[profileId]; if (typeof window.showTrainerModal === 'function') { window.showTrainerModal(cachedData); } return; } // Fetch profile data via AJAX if not cached // Implementation handles caching, error handling, and modal display }; ``` ### Certification Color Coding | Certification Type | Color | Usage | |--------------------|-------|-------| | Certified measureQuick Trainer | `#5077bb` | Primary trainer markers | | Certified measureQuick Champion | `#f19a42` | Champion markers (no modals) | | Default/Other | `#f0f7e8` | Fallback color | ## User Roles & Permissions ### HVAC Trainer (`hvac_trainer`) #### Core Capabilities - `read` - Basic WordPress read access - `upload_files` - File upload capability - `edit_hvac_profile` - Edit own trainer profile - `view_hvac_dashboard` - Access trainer dashboard - `manage_hvac_events` - Manage own events - `manage_attendees` - Manage event attendees - `email_attendees` - Send emails to attendees #### Events Calendar Integration - `publish_tribe_events` - Create and publish events - `edit_tribe_events` - Edit events - `delete_tribe_events` - Delete events - `edit_published_tribe_events` - Edit published events - `delete_published_tribe_events` - Delete published events - `read_private_tribe_events` - View private events ### HVAC Master Trainer (`hvac_master_trainer`) #### Extended Capabilities - All trainer capabilities - Access to master dashboard with analytics - View aggregate trainer statistics - Enhanced reporting capabilities ### Permission Checks ```php // Check if user can edit trainer profiles if (current_user_can('edit_hvac_profile')) { // Allow profile editing } // Check for master trainer capabilities if (current_user_can('hvac_master_trainer')) { // Show master trainer features } ``` ## API Reference ### AJAX Handlers #### Get Trainer Profile **Endpoint**: `hvac_get_trainer_profile` **Method**: POST **Parameters**: - `profile_id` (integer) - Trainer profile ID - `nonce` (string) - Security nonce **Response**: ```json { "success": true, "data": { "profile_id": 5840, "user_id": "31", "name": "Jeremy Begley", "city": "Knoxville", "state": "Tennessee", "certification_type": "Certified measureQuick Trainer", "profile_image": "https://...", "business_type": "Independent Contractor", "event_count": 5, "training_formats": "In-Person, Virtual", "training_locations": "On-site, Remote", "upcoming_events": [] } } ``` #### Filter Trainers **Endpoint**: `hvac_filter_trainers` **Method**: POST **Parameters**: - `filters` (array) - Filter criteria - `page` (integer) - Page number - `per_page` (integer) - Results per page - `nonce` (string) - Security nonce **Response**: ```json { "success": true, "data": { "html": "