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

228 lines 11.5 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 /**
8 * Class TemplateMapper
9 *
10 * Maps template IDs to their corresponding template classes
11 *
12 * @package IvyForms\Services\Template
13 */
14 class TemplateMapper
15 {
16 /**
17 * Template ID to class mapping
18 *
19 * @var array<string, string>
20 */
21 private static array $templateMap = [
22 'contact_form' => ContactFormTemplate::class,
23 'blank_form' => BlankFormTemplate::class,
24 'wedding_rsvp' => WeddingRsvpTemplate::class,
25 'anniversary_dinner_reservation_form' => AnniversaryDinnerReservationFormTemplate::class,
26 'birthday_dinner_reservation_form' => BirthdayDinnerReservationFormTemplate::class,
27 'private_dining_reservation_form' => PrivateDiningReservationFormTemplate::class,
28 'craft_vendor_registration_form' => CraftVendorRegistrationFormTemplate::class,
29 'food_vendor_registration_form' => FoodVendorRegistrationFormTemplate::class,
30 'fitness_class_registration_form' => FitnessClassRegistrationFormTemplate::class,
31 'yoga_class_registration_form' => YogaClassRegistrationFormTemplate::class,
32 'cooking_class_registration_form' => CookingClassRegistrationFormTemplate::class,
33 'conference_room_booking_form' => ConferenceRoomBookingFormTemplate::class,
34 'product_order_form' => ProductOrderFormTemplate::class,
35 'event_registration' => EventRegistrationTemplate::class,
36 'event_tshirt_order_form' => EventTShirtOrderFormTemplate::class,
37 'custom_tshirt_order_form' => CustomTShirtOrderFormTemplate::class,
38 'custom_cake_order_form' => CustomCakeOrderFormTemplate::class,
39 'wedding_cake_order_form' => WeddingCakeOrderFormTemplate::class,
40 'birthday_cake_order_form' => BirthdayCakeOrderFormTemplate::class,
41 'doctor_appointment_booking_form' => DoctorAppointmentBookingFormTemplate::class,
42 'dinner_reservation_form' => DinnerReservationFormTemplate::class,
43 'hair_salon_appointment_form' => HairSalonAppointmentFormTemplate::class,
44 'nail_salon_appointment_form' => NailSalonAppointmentFormTemplate::class,
45 'spa_appointment_booking_form' => SpaAppointmentBookingFormTemplate::class,
46 'consultation_appointment_form' => ConsultationAppointmentFormTemplate::class,
47 'birthday_tshirt_order_form' => BirthdayTShirtOrderFormTemplate::class,
48 'corporate_tshirt_order_form' => CorporateTShirtOrderFormTemplate::class,
49 'residential_construction_change_form' => ResidentialConstructionChangeFormTemplate::class,
50 'festival_waiver_form' => FestivalWaiverFormTemplate::class,
51 'charity_run_waiver_form' => CharityRunWaiverFormTemplate::class,
52 'volunteer_event_waiver_form' => VolunteerEventWaiverFormTemplate::class,
53 'community_event_waiver_form' => CommunityEventWaiverFormTemplate::class,
54 'school_trip_waiver_form' => SchoolTripWaiverFormTemplate::class,
55 'yoga_class_waiver_form' => YogaClassWaiverFormTemplate::class,
56 'dance_class_waiver_form' => DanceClassWaiverFormTemplate::class,
57 'hiking_trip_waiver_form' => HikingTripWaiverFormTemplate::class,
58 'gym_waiver_form' => GymWaiverFormTemplate::class,
59 'sports_event_waiver_form' => SportsEventWaiverFormTemplate::class,
60 'universal_construction_change_form' => UniversalConstructionChangeFormTemplate::class,
61 'maintenance_work_order_form' => MaintenanceWorkOrderFormTemplate::class,
62 'vacation_leave_request_form' => VacationLeaveRequestFormTemplate::class,
63 'sick_leave_request_form' => SickLeaveRequestFormTemplate::class,
64 'annual_leave_request_form' => AnnualLeaveRequestFormTemplate::class,
65 'maternity_leave_request_form' => MaternityLeaveRequestFormTemplate::class,
66 'conference_registration_form' => ConferenceRegistrationFormTemplate::class,
67 'webinar_registration_form' => WebinarRegistrationFormTemplate::class,
68 'corporate_photo_consent_form' => CorporatePhotoConsentFormTemplate::class,
69 'conference_photo_consent_form' => ConferencePhotoConsentFormTemplate::class,
70 'sports_team_photo_consent_form' => SportsTeamPhotoConsentFormTemplate::class,
71 'school_photo_consent_form' => SchoolPhotoConsentFormTemplate::class,
72 'event_photo_consent_form' => EventPhotoConsentFormTemplate::class,
73 'photo_video_consent_form' => PhotoVideoConsentFormTemplate::class,
74 'workshop_registration_form' => WorkshopRegistrationFormTemplate::class,
75 'charity_event_registration_form' => CharityEventRegistrationFormTemplate::class,
76 'baby_shower_cake_order_form' => BabyShowerCakeOrderFormTemplate::class,
77 'general_medical_consent_form' => GeneralMedicalConsentFormTemplate::class,
78 'surgery_informed_consent_form' => SurgeryInformedConsentFormTemplate::class,
79 'general_change_order_form' => GeneralChangeOrderFormTemplate::class,
80 'marketing_conference_registration_form' => MarketingConferenceRegistrationFormTemplate::class,
81 'medical_conference_registration_form' => MedicalConferenceRegistrationFormTemplate::class,
82 'tech_conference_registration_form' => TechConferenceRegistrationFormTemplate::class,
83 'blood_transfusion_consent_form' => BloodTransfusionConsentFormTemplate::class,
84 'vaccination_consent_form' => VaccinationConsentFormTemplate::class,
85 'anesthesia_consent_form' => AnesthesiaConsentFormTemplate::class,
86 'garden_wedding_rsvp_form' => GardenWeddingRSVPFormTemplate::class,
87 'beach_wedding_rsvp_form' => BeachWeddingRSVPFormTemplate::class,
88 'destination_wedding_rsvp_form' => DestinationWeddingRSVPFormTemplate::class,
89 'traditional_wedding_rsvp_form' => TraditionalWeddingRSVPFormTemplate::class,
90 'wedding_registration_form' => WeddingRegistrationFormTemplate::class,
91 'software_purchase_order_form' => SoftwarePurchaseOrderFormTemplate::class,
92 'office_supplies_purchase_order_form' => OfficeSuppliesPurchaseOrderFormTemplate::class,
93 'equipment_purchase_order_form' => EquipmentPurchaseOrderFormTemplate::class,
94 'material_purchase_order_form' => MaterialPurchaseOrderFormTemplate::class,
95 'education_conference_registration_form' => EducationConferenceRegistrationFormTemplate::class,
96 'repair_work_order_form' => RepairWorkOrderFormTemplate::class,
97 'installation_work_order_form' => InstallationWorkOrderFormTemplate::class,
98 'team_tshirt_order_form' => TeamTshirtOrderFormTemplate::class,
99 'kitchen_upgrade_change_form' => KitchenUpgradeChangeFormTemplate::class,
100 'commercial_construction_change_form' => CommercialConstructionChangeFormTemplate::class,
101 'hr_interview_feedback_form' => HRInterviewFeedbackFormTemplate::class,
102 'technical_role_interview_feedback_form' => TechnicalRoleInterviewFeedbackFormTemplate::class,
103 'candidate_evaluation_form' => CandidateEvaluationFormTemplate::class,
104 'technical_interview_feedback_form' => TechnicalInterviewFeedbackFormTemplate::class,
105 'course_content_feedback_form' => CourseContentFeedbackFormTemplate::class,
106 'trainer_feedback_form' => TrainerFeedbackFormTemplate::class,
107 'online_training_feedback_form' => OnlineTrainingFeedbackFormTemplate::class,
108 'employee_training_feedback_form' => EmployeeTrainingFeedbackFormTemplate::class,
109 'client_loyalty_testimonial_readiness_form' => ClientLoyaltyTestimonialReadinessFormTemplate::class,
110 'client_relationship_communication_feedback' => ClientRelationshipCommunicationFeedbackTemplate::class,
111 'general_client_feedback_form' => GeneralClientFeedbackFormTemplate::class,
112 'service_specific_client_feedback_form' => ServiceSpecificClientFeedbackFormTemplate::class,
113 'ongoing_client_feedback_form' => OngoingClientFeedbackFormTemplate::class,
114 'training_event_feedback_form' => TrainingEventFeedbackFormTemplate::class,
115 'networking_event_feedback_form' => NetworkingEventFeedbackFormTemplate::class,
116 'workshop_feedback_form' => WorkshopFeedbackFormTemplate::class,
117 'customer_loyalty_recommendation_form' => CustomerLoyaltyRecommendationFormTemplate::class,
118 'webinar_feedback_form' => WebinarFeedbackFormTemplate::class,
119 'conference_feedback_form' => ConferenceFeedbackFormTemplate::class,
120 'event_feedback_form' => EventFeedbackFormTemplate::class,
121 'post_purchase_feedback_form' => PostPurchaseFeedbackFormTemplate::class,
122 'website_experience_feedback_form' => WebsiteExperienceFeedbackFormTemplate::class,
123 'customer_support_feedback_form' => CustomerSupportFeedbackFormTemplate::class,
124 'product_feedback_form' => ProductFeedbackFormTemplate::class,
125 'project_completion_feedback_form' => ProjectCompletionFeedbackFormTemplate::class,
126 ];
127
128 /**
129 * Get the template map
130 *
131 * @return array<string, string>
132 */
133 public function getTemplateMap(): array
134 {
135 /**
136 * Allows modification of the template mapper.
137 *
138 * @since 0.1.0
139 *
140 * @param array<string, string> $templateMaper The current template mapper.
141 *
142 * @return array<string, string> The modified template mapper.
143 */
144 self::$templateMap = apply_filters(
145 'ivyforms/template/template_mapper',
146 self::$templateMap
147 );
148
149 return self::$templateMap;
150 }
151
152 /**
153 * Get template class by template ID
154 *
155 * @param string $templateId
156 * @return string|null Template class name or null if not found
157 */
158 public static function getTemplateClass(string $templateId): ?string
159 {
160 return (new TemplateMapper())->getTemplateMap()[$templateId] ?? null;
161 }
162
163 /**
164 * Get template data by template ID
165 *
166 * @param string $templateId
167 * @return array<string, mixed>|null Template data or null if not found
168 */
169 public static function getTemplate(string $templateId): ?array
170 {
171 $templateClass = self::getTemplateClass($templateId);
172
173 if (!$templateClass || !class_exists($templateClass)) {
174 return null;
175 }
176
177 return $templateClass::getTemplate();
178 }
179
180 /**
181 * Get all template IDs
182 *
183 * @return array<int, string>
184 */
185 public static function getAllTemplateIds(): array
186 {
187 return array_keys((new TemplateMapper())->getTemplateMap());
188 }
189
190 /**
191 * Check if template ID exists
192 *
193 * @param string $templateId
194 * @return bool
195 */
196 public static function hasTemplate(string $templateId): bool
197 {
198 return self::getTemplateClass($templateId) !== null;
199 }
200
201 /**
202 * Get all templates metadata (without form_data) for listing purposes
203 *
204 * Returns only: id, name, description, category, subcategory, is_pro, screenshot
205 * This avoids loading heavy form_data (fields, settings) for every template
206 * when only metadata is needed for browsing/searching.
207 *
208 * @return array<string, array<string, mixed>>
209 */
210 public static function getAllTemplateMetas(): array
211 {
212 $templates = [];
213
214 foreach ((new TemplateMapper())->getTemplateMap() as $templateId => $templateClass) {
215 // Skip BlankFormTemplate from public template list
216 if ($templateClass === BlankFormTemplate::class) {
217 continue;
218 }
219
220 if (class_exists($templateClass) && method_exists($templateClass, 'getTemplateMeta')) {
221 $templates[$templateId] = $templateClass::getTemplateMeta();
222 }
223 }
224
225 return $templates;
226 }
227 }
228