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

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