PluginProbe
The Innovative Form Builder – IvyForms / 0.9.1
The Innovative Form Builder – IvyForms v0.9.1
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.9.1, at backend/src/Services/Template/TemplateMapper.php

230 lines 11.3 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 'hr_interview_feedback_form' => HRInterviewFeedbackFormTemplate::class,
107 'technical_role_interview_feedback_form' => TechnicalRoleInterviewFeedbackFormTemplate::class,
108 'candidate_evaluation_form' => CandidateEvaluationFormTemplate::class,
109 'technical_interview_feedback_form' => TechnicalInterviewFeedbackFormTemplate::class,
110 'course_content_feedback_form' => CourseContentFeedbackFormTemplate::class,
111 'trainer_feedback_form' => TrainerFeedbackFormTemplate::class,
112 'online_training_feedback_form' => OnlineTrainingFeedbackFormTemplate::class,
113 'employee_training_feedback_form' => EmployeeTrainingFeedbackFormTemplate::class,
114 'client_loyalty_testimonial_readiness_form' => ClientLoyaltyTestimonialReadinessFormTemplate::class,
115 'client_relationship_communication_feedback' => ClientRelationshipCommunicationFeedbackTemplate::class,
116 'general_client_feedback_form' => GeneralClientFeedbackFormTemplate::class,
117 'service_specific_client_feedback_form' => ServiceSpecificClientFeedbackFormTemplate::class,
118 'ongoing_client_feedback_form' => OngoingClientFeedbackFormTemplate::class,
119 'training_event_feedback_form' => TrainingEventFeedbackFormTemplate::class,
120 'networking_event_feedback_form' => NetworkingEventFeedbackFormTemplate::class,
121 'workshop_feedback_form' => WorkshopFeedbackFormTemplate::class,
122 'customer_loyalty_recommendation_form' => CustomerLoyaltyRecommendationFormTemplate::class,
123 'webinar_feedback_form' => WebinarFeedbackFormTemplate::class,
124 'conference_feedback_form' => ConferenceFeedbackFormTemplate::class,
125 'event_feedback_form' => EventFeedbackFormTemplate::class,
126 'post_purchase_feedback_form' => PostPurchaseFeedbackFormTemplate::class,
127 'website_experience_feedback_form' => WebsiteExperienceFeedbackFormTemplate::class,
128 'customer_support_feedback_form' => CustomerSupportFeedbackFormTemplate::class,
129 'product_feedback_form' => ProductFeedbackFormTemplate::class,
130 'project_completion_feedback_form' => ProjectCompletionFeedbackFormTemplate::class,
131 ];
132
133 /**
134 * Get the template map
135 *
136 * @return array<string, string>
137 */
138 public function getTemplateMap(): array
139 {
140 /**
141 * Allows modification of the template mapper.
142 *
143 * @since 0.1.0
144 *
145 * @param array<string, string> $templateMaper The current template mapper.
146 *
147 * @return array<string, string> The modified template mapper.
148 */
149 self::$templateMap = apply_filters(
150 'ivyforms/template/template_mapper',
151 self::$templateMap
152 );
153
154 return self::$templateMap;
155 }
156
157 /**
158 * Get template class by template ID
159 *
160 * @param string $templateId
161 * @return string|null Template class name or null if not found
162 */
163 public static function getTemplateClass(string $templateId): ?string
164 {
165 return (new TemplateMapper())->getTemplateMap()[$templateId] ?? null;
166 }
167
168 /**
169 * Get template data by template ID
170 *
171 * @param string $templateId
172 * @return array<string, mixed>|null Template data or null if not found
173 */
174 public static function getTemplate(string $templateId): ?array
175 {
176 $templateClass = self::getTemplateClass($templateId);
177
178 if (!$templateClass || !class_exists($templateClass)) {
179 return null;
180 }
181
182 return $templateClass::getTemplate();
183 }
184
185 /**
186 * Get all template IDs
187 *
188 * @return array<int, string>
189 */
190 public static function getAllTemplateIds(): array
191 {
192 return array_keys((new TemplateMapper())->getTemplateMap());
193 }
194
195 /**
196 * Check if template ID exists
197 *
198 * @param string $templateId
199 * @return bool
200 */
201 public static function hasTemplate(string $templateId): bool
202 {
203 return self::getTemplateClass($templateId) !== null;
204 }
205
206 /**
207 * Get all templates as associative array
208 *
209 * @return array<string, array<string, mixed>>
210 */
211 public static function getAllTemplates(): array
212 {
213 $templates = [];
214
215 foreach ((new TemplateMapper())->getTemplateMap() as $templateId => $templateClass) {
216 // Skip BlankFormTemplate from public template list
217 if ($templateClass === BlankFormTemplate::class) {
218 continue;
219 }
220
221 if (class_exists($templateClass)) {
222 $templateData = $templateClass::getTemplate();
223 $templates[$templateId] = $templateData;
224 }
225 }
226
227 return $templates;
228 }
229 }
230