PluginProbe
The Innovative Form Builder – IvyForms / 0.8.2
The Innovative Form Builder – IvyForms v0.8.2
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Template / TemplateMapper.php

TemplateMapper.php in The Innovative Form Builder – IvyForms 0.8.2, at backend/src/Services/Template/TemplateMapper.php

205 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace IvyForms\Services\Template;
6
7 // phpcs:disable PSR1.Files.SideEffects
8 if (!defined('ABSPATH')) {
9 exit; // Exit if accessed directly
10 }
11
12 /**
13 * Class TemplateMapper
14 *
15 * Maps template IDs to their corresponding template classes
16 *
17 * @package IvyForms\Services\Template
18 */
19 class TemplateMapper
20 {
21 /**
22 * Template ID to class mapping
23 *
24 * @var array<string, string>
25 */
26 private static array $templateMap = [
27 'contact_form' => ContactFormTemplate::class,
28 'blank_form' => BlankFormTemplate::class,
29 'wedding_rsvp' => WeddingRsvpTemplate::class,
30 'anniversary_dinner_reservation_form' => AnniversaryDinnerReservationFormTemplate::class,
31 'birthday_dinner_reservation_form' => BirthdayDinnerReservationFormTemplate::class,
32 'private_dining_reservation_form' => PrivateDiningReservationFormTemplate::class,
33 'craft_vendor_registration_form' => CraftVendorRegistrationFormTemplate::class,
34 'food_vendor_registration_form' => FoodVendorRegistrationFormTemplate::class,
35 'fitness_class_registration_form' => FitnessClassRegistrationFormTemplate::class,
36 'yoga_class_registration_form' => YogaClassRegistrationFormTemplate::class,
37 'cooking_class_registration_form' => CookingClassRegistrationFormTemplate::class,
38 'conference_room_booking_form' => ConferenceRoomBookingFormTemplate::class,
39 'product_order_form' => ProductOrderFormTemplate::class,
40 'event_registration' => EventRegistrationTemplate::class,
41 'event_tshirt_order_form' => EventTShirtOrderFormTemplate::class,
42 'custom_tshirt_order_form' => CustomTShirtOrderFormTemplate::class,
43 'custom_cake_order_form' => CustomCakeOrderFormTemplate::class,
44 'wedding_cake_order_form' => WeddingCakeOrderFormTemplate::class,
45 'birthday_cake_order_form' => BirthdayCakeOrderFormTemplate::class,
46 'doctor_appointment_booking_form' => DoctorAppointmentBookingFormTemplate::class,
47 'dinner_reservation_form' => DinnerReservationFormTemplate::class,
48 'hair_salon_appointment_form' => HairSalonAppointmentFormTemplate::class,
49 'nail_salon_appointment_form' => NailSalonAppointmentFormTemplate::class,
50 'spa_appointment_booking_form' => SpaAppointmentBookingFormTemplate::class,
51 'consultation_appointment_form' => ConsultationAppointmentFormTemplate::class,
52 'birthday_tshirt_order_form' => BirthdayTShirtOrderFormTemplate::class,
53 'corporate_tshirt_order_form' => CorporateTShirtOrderFormTemplate::class,
54 'residential_construction_change_form' => ResidentialConstructionChangeFormTemplate::class,
55 'festival_waiver_form' => FestivalWaiverFormTemplate::class,
56 'charity_run_waiver_form' => CharityRunWaiverFormTemplate::class,
57 'volunteer_event_waiver_form' => VolunteerEventWaiverFormTemplate::class,
58 'community_event_waiver_form' => CommunityEventWaiverFormTemplate::class,
59 'school_trip_waiver_form' => SchoolTripWaiverFormTemplate::class,
60 'yoga_class_waiver_form' => YogaClassWaiverFormTemplate::class,
61 'dance_class_waiver_form' => DanceClassWaiverFormTemplate::class,
62 'hiking_trip_waiver_form' => HikingTripWaiverFormTemplate::class,
63 'gym_waiver_form' => GymWaiverFormTemplate::class,
64 'sports_event_waiver_form' => SportsEventWaiverFormTemplate::class,
65 'universal_construction_change_form' => UniversalConstructionChangeFormTemplate::class,
66 'maintenance_work_order_form' => MaintenanceWorkOrderFormTemplate::class,
67 'vacation_leave_request_form' => VacationLeaveRequestFormTemplate::class,
68 'sick_leave_request_form' => SickLeaveRequestFormTemplate::class,
69 'annual_leave_request_form' => AnnualLeaveRequestFormTemplate::class,
70 'maternity_leave_request_form' => MaternityLeaveRequestFormTemplate::class,
71 'conference_registration_form' => ConferenceRegistrationFormTemplate::class,
72 'webinar_registration_form' => WebinarRegistrationFormTemplate::class,
73 'corporate_photo_consent_form' => CorporatePhotoConsentFormTemplate::class,
74 'conference_photo_consent_form' => ConferencePhotoConsentFormTemplate::class,
75 'sports_team_photo_consent_form' => SportsTeamPhotoConsentFormTemplate::class,
76 'school_photo_consent_form' => SchoolPhotoConsentFormTemplate::class,
77 'event_photo_consent_form' => EventPhotoConsentFormTemplate::class,
78 'photo_video_consent_form' => PhotoVideoConsentFormTemplate::class,
79 'workshop_registration_form' => WorkshopRegistrationFormTemplate::class,
80 'charity_event_registration_form' => CharityEventRegistrationFormTemplate::class,
81 'baby_shower_cake_order_form' => BabyShowerCakeOrderFormTemplate::class,
82 'general_medical_consent_form' => GeneralMedicalConsentFormTemplate::class,
83 'surgery_informed_consent_form' => SurgeryInformedConsentFormTemplate::class,
84 'general_change_order_form' => GeneralChangeOrderFormTemplate::class,
85 'marketing_conference_registration_form' => MarketingConferenceRegistrationFormTemplate::class,
86 'medical_conference_registration_form' => MedicalConferenceRegistrationFormTemplate::class,
87 'tech_conference_registration_form' => TechConferenceRegistrationFormTemplate::class,
88 'blood_transfusion_consent_form' => BloodTransfusionConsentFormTemplate::class,
89 'vaccination_consent_form' => VaccinationConsentFormTemplate::class,
90 'anesthesia_consent_form' => AnesthesiaConsentFormTemplate::class,
91 'garden_wedding_rsvp_form' => GardenWeddingRSVPFormTemplate::class,
92 'beach_wedding_rsvp_form' => BeachWeddingRSVPFormTemplate::class,
93 'destination_wedding_rsvp_form' => DestinationWeddingRSVPFormTemplate::class,
94 'traditional_wedding_rsvp_form' => TraditionalWeddingRSVPFormTemplate::class,
95 'wedding_registration_form' => WeddingRegistrationFormTemplate::class,
96 'software_purchase_order_form' => SoftwarePurchaseOrderFormTemplate::class,
97 'office_supplies_purchase_order_form' => OfficeSuppliesPurchaseOrderFormTemplate::class,
98 'equipment_purchase_order_form' => EquipmentPurchaseOrderFormTemplate::class,
99 'material_purchase_order_form' => MaterialPurchaseOrderFormTemplate::class,
100 'education_conference_registration_form' => EducationConferenceRegistrationFormTemplate::class,
101 'repair_work_order_form' => RepairWorkOrderFormTemplate::class,
102 'installation_work_order_form' => InstallationWorkOrderFormTemplate::class,
103 'team_tshirt_order_form' => TeamTshirtOrderFormTemplate::class,
104 'kitchen_upgrade_change_form' => KitchenUpgradeChangeFormTemplate::class,
105 'commercial_construction_change_form' => CommercialConstructionChangeFormTemplate::class,
106 ];
107
108 /**
109 * Get the template map
110 *
111 * @return array<string, string>
112 */
113 public function getTemplateMap(): array
114 {
115 /**
116 * Allows modification of the template mapper.
117 *
118 * @since 0.1.0
119 *
120 * @param array<string, string> $templateMaper The current template mapper.
121 *
122 * @return array<string, string> The modified template mapper.
123 */
124 self::$templateMap = apply_filters(
125 'ivyforms/template/template_mapper',
126 self::$templateMap
127 );
128
129 return self::$templateMap;
130 }
131
132 /**
133 * Get template class by template ID
134 *
135 * @param string $templateId
136 * @return string|null Template class name or null if not found
137 */
138 public static function getTemplateClass(string $templateId): ?string
139 {
140 return (new TemplateMapper())->getTemplateMap()[$templateId] ?? null;
141 }
142
143 /**
144 * Get template data by template ID
145 *
146 * @param string $templateId
147 * @return array<string, mixed>|null Template data or null if not found
148 */
149 public static function getTemplate(string $templateId): ?array
150 {
151 $templateClass = self::getTemplateClass($templateId);
152
153 if (!$templateClass || !class_exists($templateClass)) {
154 return null;
155 }
156
157 return $templateClass::getTemplate();
158 }
159
160 /**
161 * Get all template IDs
162 *
163 * @return array<int, string>
164 */
165 public static function getAllTemplateIds(): array
166 {
167 return array_keys((new TemplateMapper())->getTemplateMap());
168 }
169
170 /**
171 * Check if template ID exists
172 *
173 * @param string $templateId
174 * @return bool
175 */
176 public static function hasTemplate(string $templateId): bool
177 {
178 return self::getTemplateClass($templateId) !== null;
179 }
180
181 /**
182 * Get all templates as associative array
183 *
184 * @return array<string, array<string, mixed>>
185 */
186 public static function getAllTemplates(): array
187 {
188 $templates = [];
189
190 foreach ((new TemplateMapper())->getTemplateMap() as $templateId => $templateClass) {
191 // Skip BlankFormTemplate from public template list
192 if ($templateClass === BlankFormTemplate::class) {
193 continue;
194 }
195
196 if (class_exists($templateClass)) {
197 $templateData = $templateClass::getTemplate();
198 $templates[$templateId] = $templateData;
199 }
200 }
201
202 return $templates;
203 }
204 }
205