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

181 lines 7.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 'product_order_form' => ProductOrderFormTemplate::class,
31 'event_registration' => EventRegistrationTemplate::class,
32 'event_tshirt_order_form' => EventTShirtOrderFormTemplate::class,
33 'custom_tshirt_order_form' => CustomTShirtOrderFormTemplate::class,
34 'custom_cake_order_form' => CustomCakeOrderFormTemplate::class,
35 'wedding_cake_order_form' => WeddingCakeOrderFormTemplate::class,
36 'birthday_cake_order_form' => BirthdayCakeOrderFormTemplate::class,
37 'doctor_appointment_booking_form' => DoctorAppointmentBookingFormTemplate::class,
38 'dinner_reservation_form' => DinnerReservationFormTemplate::class,
39 'hair_salon_appointment_form' => HairSalonAppointmentFormTemplate::class,
40 'nail_salon_appointment_form' => NailSalonAppointmentFormTemplate::class,
41 'spa_appointment_booking_form' => SpaAppointmentBookingFormTemplate::class,
42 'consultation_appointment_form' => ConsultationAppointmentFormTemplate::class,
43 'birthday_tshirt_order_form' => BirthdayTShirtOrderFormTemplate::class,
44 'corporate_tshirt_order_form' => CorporateTShirtOrderFormTemplate::class,
45 'residential_construction_change_form' => ResidentialConstructionChangeFormTemplate::class,
46 'festival_waiver_form' => FestivalWaiverFormTemplate::class,
47 'charity_run_waiver_form' => CharityRunWaiverFormTemplate::class,
48 'volunteer_event_waiver_form' => VolunteerEventWaiverFormTemplate::class,
49 'community_event_waiver_form' => CommunityEventWaiverFormTemplate::class,
50 'school_trip_waiver_form' => SchoolTripWaiverFormTemplate::class,
51 'yoga_class_waiver_form' => YogaClassWaiverFormTemplate::class,
52 'dance_class_waiver_form' => DanceClassWaiverFormTemplate::class,
53 'hiking_trip_waiver_form' => HikingTripWaiverFormTemplate::class,
54 'gym_waiver_form' => GymWaiverFormTemplate::class,
55 'sports_event_waiver_form' => SportsEventWaiverFormTemplate::class,
56 'universal_construction_change_form' => UniversalConstructionChangeFormTemplate::class,
57 'maintenance_work_order_form' => MaintenanceWorkOrderFormTemplate::class,
58 'vacation_leave_request_form' => VacationLeaveRequestFormTemplate::class,
59 'sick_leave_request_form' => SickLeaveRequestFormTemplate::class,
60 'annual_leave_request_form' => AnnualLeaveRequestFormTemplate::class,
61 'maternity_leave_request_form' => MaternityLeaveRequestFormTemplate::class,
62 'conference_registration_form' => ConferenceRegistrationFormTemplate::class,
63 'webinar_registration_form' => WebinarRegistrationFormTemplate::class,
64 'corporate_photo_consent_form' => CorporatePhotoConsentFormTemplate::class,
65 'conference_photo_consent_form' => ConferencePhotoConsentFormTemplate::class,
66 'sports_team_photo_consent_form' => SportsTeamPhotoConsentFormTemplate::class,
67 'school_photo_consent_form' => SchoolPhotoConsentFormTemplate::class,
68 'event_photo_consent_form' => EventPhotoConsentFormTemplate::class,
69 'photo_video_consent_form' => PhotoVideoConsentFormTemplate::class,
70 'workshop_registration_form' => WorkshopRegistrationFormTemplate::class,
71 'charity_event_registration_form' => CharityEventRegistrationFormTemplate::class,
72 'baby_shower_cake_order_form' => BabyShowerCakeOrderFormTemplate::class,
73 'general_medical_consent_form' => GeneralMedicalConsentFormTemplate::class,
74 'surgery_informed_consent_form' => SurgeryInformedConsentFormTemplate::class,
75 'general_change_order_form' => GeneralChangeOrderFormTemplate::class,
76 'marketing_conference_registration_form' => MarketingConferenceRegistrationFormTemplate::class,
77 'medical_conference_registration_form' => MedicalConferenceRegistrationFormTemplate::class,
78 'tech_conference_registration_form' => TechConferenceRegistrationFormTemplate::class,
79 'blood_transfusion_consent_form' => BloodTransfusionConsentFormTemplate::class,
80 'vaccination_consent_form' => VaccinationConsentFormTemplate::class,
81 'anesthesia_consent_form' => AnesthesiaConsentFormTemplate::class,
82 ];
83
84 /**
85 * Get the template map
86 *
87 * @return array<string, string>
88 */
89 public function getTemplateMap(): array
90 {
91 /**
92 * Allows modification of the template mapper.
93 *
94 * @since 0.1.0
95 *
96 * @param array<string, string> $templateMaper The current template mapper.
97 *
98 * @return array<string, string> The modified template mapper.
99 */
100 self::$templateMap = apply_filters(
101 'ivyforms/template/template_mapper',
102 self::$templateMap
103 );
104
105 return self::$templateMap;
106 }
107
108 /**
109 * Get template class by template ID
110 *
111 * @param string $templateId
112 * @return string|null Template class name or null if not found
113 */
114 public static function getTemplateClass(string $templateId): ?string
115 {
116 return (new TemplateMapper())->getTemplateMap()[$templateId] ?? null;
117 }
118
119 /**
120 * Get template data by template ID
121 *
122 * @param string $templateId
123 * @return array<string, mixed>|null Template data or null if not found
124 */
125 public static function getTemplate(string $templateId): ?array
126 {
127 $templateClass = self::getTemplateClass($templateId);
128
129 if (!$templateClass || !class_exists($templateClass)) {
130 return null;
131 }
132
133 return $templateClass::getTemplate();
134 }
135
136 /**
137 * Get all template IDs
138 *
139 * @return array<int, string>
140 */
141 public static function getAllTemplateIds(): array
142 {
143 return array_keys((new TemplateMapper())->getTemplateMap());
144 }
145
146 /**
147 * Check if template ID exists
148 *
149 * @param string $templateId
150 * @return bool
151 */
152 public static function hasTemplate(string $templateId): bool
153 {
154 return self::getTemplateClass($templateId) !== null;
155 }
156
157 /**
158 * Get all templates as associative array
159 *
160 * @return array<string, array<string, mixed>>
161 */
162 public static function getAllTemplates(): array
163 {
164 $templates = [];
165
166 foreach ((new TemplateMapper())->getTemplateMap() as $templateId => $templateClass) {
167 // Skip BlankFormTemplate from public template list
168 if ($templateClass === BlankFormTemplate::class) {
169 continue;
170 }
171
172 if (class_exists($templateClass)) {
173 $templateData = $templateClass::getTemplate();
174 $templates[$templateId] = $templateData;
175 }
176 }
177
178 return $templates;
179 }
180 }
181