← All changes
|
backend/src/Services/Template/MaintenanceWorkOrderFormTemplate.php
+528
-0
0.6.1
→
1.5.1
View file →
| @@ -1,0 +1,528 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace IvyForms\Services\Template; | |
| 4 | + | |
| 5 | +use IvyForms\Services\Translations\BackendStrings; | |
| 6 | + | |
| 7 | +class MaintenanceWorkOrderFormTemplate | |
| 8 | +{ | |
| 9 | + /** | |
| 10 | + * Get template metadata (without form_data) | |
| 11 | + * | |
| 12 | + * @return array<string, mixed> | |
| 13 | + */ | |
| 14 | + public static function getTemplateMeta(): array | |
| 15 | + { | |
| 16 | + return [ | |
| 17 | + 'id' => 'maintenance_work_order_form', | |
| 18 | + 'name' => BackendStrings::getTemplateStrings()['maintenance_work_order_form'], | |
| 19 | + 'description' => BackendStrings::getTemplateStrings()['maintenance_work_order_form_desc'], | |
| 20 | + 'category' => 'order-forms', | |
| 21 | + 'subcategory' => 'work-order-forms', | |
| 22 | + 'is_pro' => false, | |
| 23 | + 'screenshot' => IVYFORMS_TEMPLATES_IMAGES_URL . 'maintenance-work-order-form.svg' | |
| 24 | + ]; | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Get the full template including form data | |
| 29 | + * | |
| 30 | + * @return array<string, mixed> | |
| 31 | + */ | |
| 32 | + public static function getTemplate(): array | |
| 33 | + { | |
| 34 | + return array_merge( | |
| 35 | + self::getTemplateMeta(), | |
| 36 | + [ | |
| 37 | + 'form_data' => [ | |
| 38 | + 'name' => BackendStrings::getTemplateStrings()['maintenance_work_order_form'], | |
| 39 | + 'published' => 1, | |
| 40 | + 'showTitle' => 1, | |
| 41 | + 'storeEntries' => 1, | |
| 42 | + 'integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings(), | |
| 43 | + 'fields' => array_merge( | |
| 44 | + self::getRequesterInformationFields(), | |
| 45 | + self::getLocationFacilityFields(), | |
| 46 | + self::getMaintenanceRequestFields(), | |
| 47 | + self::getSubmissionApprovalFields() | |
| 48 | + ), | |
| 49 | + 'settings' => [] | |
| 50 | + ] | |
| 51 | + ] | |
| 52 | + ); | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Get requester information fields | |
| 57 | + * | |
| 58 | + * @return array<int, array<string, mixed>> | |
| 59 | + */ | |
| 60 | + private static function getRequesterInformationFields(): array | |
| 61 | + { | |
| 62 | + return [ | |
| 63 | + // Name Field - Parent | |
| 64 | + [ | |
| 65 | + 'id' => 1, | |
| 66 | + 'fieldIndex' => 1, | |
| 67 | + 'type' => 'name', | |
| 68 | + 'label' => BackendStrings::getTemplateStrings()['full_name'], | |
| 69 | + 'parentId' => null, | |
| 70 | + 'defaultValue' => '', | |
| 71 | + 'placeholder' => '', | |
| 72 | + 'required' => true, | |
| 73 | + 'readonly' => false, | |
| 74 | + 'position' => 1, | |
| 75 | + ], | |
| 76 | + // First Name - Child of Name Field | |
| 77 | + [ | |
| 78 | + 'id' => 2, | |
| 79 | + 'type' => 'text', | |
| 80 | + 'label' => BackendStrings::getNewFormStrings()['first_name'], | |
| 81 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_first_name'], | |
| 82 | + 'required' => true, | |
| 83 | + 'parentId' => 1, | |
| 84 | + 'fieldIndex' => 1, | |
| 85 | + 'defaultValue' => '', | |
| 86 | + 'position' => 1, | |
| 87 | + 'optionHide' => false, | |
| 88 | + 'description' => '', | |
| 89 | + 'settings' => json_encode(['nameFieldType' => 'nameField1']), | |
| 90 | + ], | |
| 91 | + // Last Name - Child of Name Field | |
| 92 | + [ | |
| 93 | + 'id' => 3, | |
| 94 | + 'type' => 'text', | |
| 95 | + 'label' => BackendStrings::getNewFormStrings()['last_name'], | |
| 96 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_last_name'], | |
| 97 | + 'required' => true, | |
| 98 | + 'parentId' => 1, | |
| 99 | + 'fieldIndex' => 1, | |
| 100 | + 'defaultValue' => '', | |
| 101 | + 'position' => 2, | |
| 102 | + 'optionHide' => false, | |
| 103 | + 'description' => '', | |
| 104 | + 'settings' => json_encode(['nameFieldType' => 'nameField2']), | |
| 105 | + ], | |
| 106 | + // Email Address | |
| 107 | + [ | |
| 108 | + 'id' => 4, | |
| 109 | + 'fieldIndex' => 2, | |
| 110 | + 'type' => 'email', | |
| 111 | + 'label' => BackendStrings::getTemplateStrings()['email_address'], | |
| 112 | + 'placeholder' => '[email protected]', | |
| 113 | + 'required' => true, | |
| 114 | + 'parentId' => null, | |
| 115 | + 'defaultValue' => '', | |
| 116 | + 'position' => 2, | |
| 117 | + ], | |
| 118 | + // Phone Number | |
| 119 | + [ | |
| 120 | + 'id' => 5, | |
| 121 | + 'fieldIndex' => 3, | |
| 122 | + 'type' => 'phone', | |
| 123 | + 'label' => BackendStrings::getTemplateStrings()['phone_number'], | |
| 124 | + 'placeholder' => '+1 (_) _-_', | |
| 125 | + 'required' => true, | |
| 126 | + 'parentId' => null, | |
| 127 | + 'defaultValue' => '', | |
| 128 | + 'position' => 3, | |
| 129 | + 'phoneAutoDetect' => true, | |
| 130 | + ], | |
| 131 | + ]; | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Get location/facility details fields | |
| 136 | + * | |
| 137 | + * @return array<int, array<string, mixed>> | |
| 138 | + */ | |
| 139 | + private static function getLocationFacilityFields(): array | |
| 140 | + { | |
| 141 | + return array_merge( | |
| 142 | + self::getLocationFields(), | |
| 143 | + self::getFacilityAddressFields() | |
| 144 | + ); | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Building / department / room fields | |
| 149 | + * | |
| 150 | + * @return array<int, array<string, mixed>> | |
| 151 | + */ | |
| 152 | + private static function getLocationFields(): array | |
| 153 | + { | |
| 154 | + return [ | |
| 155 | + // Building / Department / Room | |
| 156 | + [ | |
| 157 | + 'id' => 6, | |
| 158 | + 'fieldIndex' => 4, | |
| 159 | + 'type' => 'text', | |
| 160 | + 'label' => BackendStrings::getTemplateStrings()['building_department_room'], | |
| 161 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_building_department_room'], | |
| 162 | + 'required' => true, | |
| 163 | + 'parentId' => null, | |
| 164 | + 'defaultValue' => '', | |
| 165 | + 'position' => 4, | |
| 166 | + ], | |
| 167 | + ]; | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * Facility address fields | |
| 172 | + * | |
| 173 | + * @return array<int, array<string, mixed>> | |
| 174 | + */ | |
| 175 | + private static function getFacilityAddressFields(): array | |
| 176 | + { | |
| 177 | + return [ | |
| 178 | + // Address Field - Parent | |
| 179 | + [ | |
| 180 | + 'id' => 7, | |
| 181 | + 'fieldIndex' => 5, | |
| 182 | + 'type' => 'address', | |
| 183 | + 'label' => BackendStrings::getTemplateStrings()['address_site_location'], | |
| 184 | + 'parentId' => null, | |
| 185 | + 'defaultValue' => '', | |
| 186 | + 'placeholder' => '', | |
| 187 | + 'readonly' => false, | |
| 188 | + 'position' => 5, | |
| 189 | + 'required' => false, | |
| 190 | + ], | |
| 191 | + // Address Line 1 - Child of Address Field | |
| 192 | + [ | |
| 193 | + 'id' => 9, | |
| 194 | + 'type' => 'text', | |
| 195 | + 'label' => BackendStrings::getTemplateStrings()['address_line_1'], | |
| 196 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_address_line_1'], | |
| 197 | + 'required' => false, | |
| 198 | + 'parentId' => 5, | |
| 199 | + 'fieldIndex' => 5, | |
| 200 | + 'defaultValue' => '', | |
| 201 | + 'position' => 1, | |
| 202 | + 'hideLabel' => false, | |
| 203 | + 'description' => '', | |
| 204 | + 'addressType' => 'streetAddress', | |
| 205 | + 'settings' => json_encode( | |
| 206 | + [ | |
| 207 | + 'type' => 'streetAddress', | |
| 208 | + 'hideLabel' => false, | |
| 209 | + 'description' => '', | |
| 210 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_address_line_1'], | |
| 211 | + 'requiredMessage' => '', | |
| 212 | + 'visible' => true | |
| 213 | + ] | |
| 214 | + ), | |
| 215 | + ], | |
| 216 | + // Address Line 2 - Child of Address Field | |
| 217 | + [ | |
| 218 | + 'id' => 11, | |
| 219 | + 'type' => 'text', | |
| 220 | + 'label' => BackendStrings::getTemplateStrings()['address_line_2'], | |
| 221 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_address_line_2'], | |
| 222 | + 'required' => false, | |
| 223 | + 'parentId' => 5, | |
| 224 | + 'fieldIndex' => 5, | |
| 225 | + 'defaultValue' => '', | |
| 226 | + 'position' => 2, | |
| 227 | + 'hideLabel' => false, | |
| 228 | + 'description' => '', | |
| 229 | + 'addressType' => 'addressLine2', | |
| 230 | + 'settings' => json_encode( | |
| 231 | + [ | |
| 232 | + 'type' => 'addressLine2', | |
| 233 | + 'hideLabel' => false, | |
| 234 | + 'description' => '', | |
| 235 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_address_line_2'], | |
| 236 | + 'requiredMessage' => '', | |
| 237 | + 'visible' => true | |
| 238 | + ] | |
| 239 | + ), | |
| 240 | + ], | |
| 241 | + // City - Child of Address Field | |
| 242 | + [ | |
| 243 | + 'id' => 13, | |
| 244 | + 'type' => 'text', | |
| 245 | + 'label' => BackendStrings::getTemplateStrings()['city'], | |
| 246 | + 'placeholder' => BackendStrings::getTemplateStrings()['city'], | |
| 247 | + 'required' => false, | |
| 248 | + 'parentId' => 5, | |
| 249 | + 'fieldIndex' => 5, | |
| 250 | + 'defaultValue' => '', | |
| 251 | + 'position' => 3, | |
| 252 | + 'hideLabel' => false, | |
| 253 | + 'description' => '', | |
| 254 | + 'addressType' => 'city', | |
| 255 | + 'settings' => json_encode( | |
| 256 | + [ | |
| 257 | + 'type' => 'city', | |
| 258 | + 'hideLabel' => false, | |
| 259 | + 'description' => '', | |
| 260 | + 'placeholder' => BackendStrings::getTemplateStrings()['city'], | |
| 261 | + 'requiredMessage' => '', | |
| 262 | + 'visible' => true | |
| 263 | + ] | |
| 264 | + ), | |
| 265 | + ], | |
| 266 | + // State / Province - Child of Address Field | |
| 267 | + [ | |
| 268 | + 'id' => 15, | |
| 269 | + 'type' => 'text', | |
| 270 | + 'label' => BackendStrings::getTemplateStrings()['state_province'], | |
| 271 | + 'placeholder' => BackendStrings::getTemplateStrings()['state'], | |
| 272 | + 'required' => false, | |
| 273 | + 'parentId' => 5, | |
| 274 | + 'fieldIndex' => 5, | |
| 275 | + 'defaultValue' => '', | |
| 276 | + 'position' => 4, | |
| 277 | + 'hideLabel' => false, | |
| 278 | + 'description' => '', | |
| 279 | + 'addressType' => 'state', | |
| 280 | + 'settings' => json_encode( | |
| 281 | + [ | |
| 282 | + 'type' => 'state', | |
| 283 | + 'hideLabel' => false, | |
| 284 | + 'description' => '', | |
| 285 | + 'placeholder' => BackendStrings::getTemplateStrings()['state'], | |
| 286 | + 'requiredMessage' => '', | |
| 287 | + 'visible' => true | |
| 288 | + ] | |
| 289 | + ), | |
| 290 | + ], | |
| 291 | + // Zip / Postal Code - Child of Address Field | |
| 292 | + [ | |
| 293 | + 'id' => 17, | |
| 294 | + 'type' => 'text', | |
| 295 | + 'label' => BackendStrings::getTemplateStrings()['zip_postal_code'], | |
| 296 | + 'placeholder' => BackendStrings::getTemplateStrings()['zip'], | |
| 297 | + 'required' => false, | |
| 298 | + 'parentId' => 5, | |
| 299 | + 'fieldIndex' => 5, | |
| 300 | + 'defaultValue' => '', | |
| 301 | + 'position' => 5, | |
| 302 | + 'hideLabel' => false, | |
| 303 | + 'description' => '', | |
| 304 | + 'addressType' => 'zip', | |
| 305 | + 'settings' => json_encode( | |
| 306 | + [ | |
| 307 | + 'type' => 'zip', | |
| 308 | + 'hideLabel' => false, | |
| 309 | + 'description' => '', | |
| 310 | + 'placeholder' => BackendStrings::getTemplateStrings()['zip'], | |
| 311 | + 'requiredMessage' => '', | |
| 312 | + 'visible' => true | |
| 313 | + ] | |
| 314 | + ), | |
| 315 | + ], | |
| 316 | + // Country - Child of Address Field | |
| 317 | + [ | |
| 318 | + 'id' => 19, | |
| 319 | + 'type' => 'text', | |
| 320 | + 'label' => BackendStrings::getTemplateStrings()['country'], | |
| 321 | + 'placeholder' => BackendStrings::getTemplateStrings()['select_country'], | |
| 322 | + 'required' => false, | |
| 323 | + 'parentId' => 5, | |
| 324 | + 'fieldIndex' => 5, | |
| 325 | + 'defaultValue' => '', | |
| 326 | + 'position' => 6, | |
| 327 | + 'hideLabel' => false, | |
| 328 | + 'description' => '', | |
| 329 | + 'addressType' => 'country', | |
| 330 | + 'settings' => json_encode( | |
| 331 | + [ | |
| 332 | + 'type' => 'country', | |
| 333 | + 'hideLabel' => false, | |
| 334 | + 'description' => '', | |
| 335 | + 'placeholder' => BackendStrings::getTemplateStrings()['select_country'], | |
| 336 | + 'requiredMessage' => '', | |
| 337 | + 'visible' => true | |
| 338 | + ] | |
| 339 | + ), | |
| 340 | + ], | |
| 341 | + ]; | |
| 342 | + } | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * Get maintenance request details fields | |
| 346 | + * | |
| 347 | + * @return array<int, array<string, mixed>> | |
| 348 | + */ | |
| 349 | + private static function getMaintenanceRequestFields(): array | |
| 350 | + { | |
| 351 | + return [ | |
| 352 | + // Type of Maintenance / Issue | |
| 353 | + [ | |
| 354 | + 'id' => 25, | |
| 355 | + 'fieldIndex' => 6, | |
| 356 | + 'type' => 'select', | |
| 357 | + 'label' => BackendStrings::getTemplateStrings()['type_of_maintenance_issue'], | |
| 358 | + 'placeholder' => BackendStrings::getTemplateStrings()['select_type_of_maintenance'], | |
| 359 | + 'required' => true, | |
| 360 | + 'parentId' => null, | |
| 361 | + 'defaultValue' => '', | |
| 362 | + 'position' => 6, | |
| 363 | + 'fieldOptions' => [ | |
| 364 | + [ | |
| 365 | + 'id' => 20, | |
| 366 | + 'label' => BackendStrings::getTemplateStrings()['electrical'], | |
| 367 | + 'value' => 'electrical', | |
| 368 | + 'isDefault' => false, | |
| 369 | + 'position' => 1 | |
| 370 | + ], | |
| 371 | + [ | |
| 372 | + 'id' => 21, | |
| 373 | + 'label' => BackendStrings::getTemplateStrings()['plumbing'], | |
| 374 | + 'value' => 'plumbing', | |
| 375 | + 'isDefault' => false, | |
| 376 | + 'position' => 2 | |
| 377 | + ], | |
| 378 | + [ | |
| 379 | + 'id' => 22, | |
| 380 | + 'label' => BackendStrings::getTemplateStrings()['hvac'], | |
| 381 | + 'value' => 'hvac', | |
| 382 | + 'isDefault' => false, | |
| 383 | + 'position' => 3 | |
| 384 | + ], | |
| 385 | + [ | |
| 386 | + 'id' => 23, | |
| 387 | + 'label' => BackendStrings::getTemplateStrings()['general_repair'], | |
| 388 | + 'value' => 'general_repair', | |
| 389 | + 'isDefault' => false, | |
| 390 | + 'position' => 4 | |
| 391 | + ], | |
| 392 | + [ | |
| 393 | + 'id' => 24, | |
| 394 | + 'label' => BackendStrings::getTemplateStrings()['other'], | |
| 395 | + 'value' => 'other', | |
| 396 | + 'isDefault' => false, | |
| 397 | + 'position' => 5 | |
| 398 | + ], | |
| 399 | + ] | |
| 400 | + ], | |
| 401 | + // Description of Problem | |
| 402 | + [ | |
| 403 | + 'id' => 26, | |
| 404 | + 'fieldIndex' => 7, | |
| 405 | + 'type' => 'textarea', | |
| 406 | + 'label' => BackendStrings::getTemplateStrings()['description_of_problem'], | |
| 407 | + 'placeholder' => BackendStrings::getTemplateStrings()['describe_the_maintenance_issue'], | |
| 408 | + 'required' => false, | |
| 409 | + 'parentId' => null, | |
| 410 | + 'defaultValue' => '', | |
| 411 | + 'position' => 7, | |
| 412 | + ], | |
| 413 | + // Urgency / Priority | |
| 414 | + [ | |
| 415 | + 'id' => 30, | |
| 416 | + 'fieldIndex' => 8, | |
| 417 | + 'type' => 'select', | |
| 418 | + 'label' => BackendStrings::getTemplateStrings()['urgency_priority'], | |
| 419 | + 'placeholder' => BackendStrings::getTemplateStrings()['select_urgency_level'], | |
| 420 | + 'required' => false, | |
| 421 | + 'parentId' => null, | |
| 422 | + 'defaultValue' => '', | |
| 423 | + 'position' => 8, | |
| 424 | + 'fieldOptions' => [ | |
| 425 | + [ | |
| 426 | + 'id' => 27, | |
| 427 | + 'label' => BackendStrings::getTemplateStrings()['low'], | |
| 428 | + 'value' => 'low', | |
| 429 | + 'isDefault' => false, | |
| 430 | + 'position' => 1 | |
| 431 | + ], | |
| 432 | + [ | |
| 433 | + 'id' => 28, | |
| 434 | + 'label' => BackendStrings::getTemplateStrings()['medium'], | |
| 435 | + 'value' => 'medium', | |
| 436 | + 'isDefault' => false, | |
| 437 | + 'position' => 2 | |
| 438 | + ], | |
| 439 | + [ | |
| 440 | + 'id' => 29, | |
| 441 | + 'label' => BackendStrings::getTemplateStrings()['high'], | |
| 442 | + 'value' => 'high', | |
| 443 | + 'isDefault' => false, | |
| 444 | + 'position' => 3 | |
| 445 | + ], | |
| 446 | + ] | |
| 447 | + ], | |
| 448 | + [ | |
| 449 | + 'id' => 31, | |
| 450 | + 'fieldIndex' => 9, | |
| 451 | + 'type' => 'time', | |
| 452 | + 'label' => BackendStrings::getTemplateStrings()['preferred_date_time'], | |
| 453 | + 'placeholder' => BackendStrings::getTemplateStrings()['select_preferred_date_time'], | |
| 454 | + 'required' => false, | |
| 455 | + 'parentId' => null, | |
| 456 | + 'defaultValue' => '', | |
| 457 | + 'position' => 9, | |
| 458 | + 'timeFieldType' => 'time-picker', | |
| 459 | + 'timeFormat' => 'ampm', | |
| 460 | + ], | |
| 461 | + // Additional Instructions / Notes | |
| 462 | + [ | |
| 463 | + 'id' => 32, | |
| 464 | + 'fieldIndex' => 10, | |
| 465 | + 'type' => 'textarea', | |
| 466 | + 'label' => BackendStrings::getTemplateStrings()['additional_instructions_notes'], | |
| 467 | + 'placeholder' => BackendStrings::getTemplateStrings()['add_any_additional_notes'], | |
| 468 | + 'required' => false, | |
| 469 | + 'parentId' => null, | |
| 470 | + 'defaultValue' => '', | |
| 471 | + 'position' => 10, | |
| 472 | + ], | |
| 473 | + ]; | |
| 474 | + } | |
| 475 | + | |
| 476 | + /** | |
| 477 | + * Get submission/approval fields | |
| 478 | + * | |
| 479 | + * @return array<int, array<string, mixed>> | |
| 480 | + */ | |
| 481 | + private static function getSubmissionApprovalFields(): array | |
| 482 | + { | |
| 483 | + return [ | |
| 484 | + // Supervisor Approval Required? | |
| 485 | + [ | |
| 486 | + 'id' => 35, | |
| 487 | + 'fieldIndex' => 11, | |
| 488 | + 'type' => 'radio', | |
| 489 | + 'label' => BackendStrings::getTemplateStrings()['supervisor_approval_required'], | |
| 490 | + 'placeholder' => '', | |
| 491 | + 'required' => false, | |
| 492 | + 'parentId' => null, | |
| 493 | + 'defaultValue' => '', | |
| 494 | + 'position' => 11, | |
| 495 | + 'fieldOptions' => [ | |
| 496 | + [ | |
| 497 | + 'id' => 33, | |
| 498 | + 'label' => BackendStrings::getTemplateStrings()['yes'], | |
| 499 | + 'value' => 'yes', | |
| 500 | + 'isDefault' => false, | |
| 501 | + 'position' => 1 | |
| 502 | + ], | |
| 503 | + [ | |
| 504 | + 'id' => 34, | |
| 505 | + 'label' => BackendStrings::getTemplateStrings()['no'], | |
| 506 | + 'value' => 'no', | |
| 507 | + 'isDefault' => false, | |
| 508 | + 'position' => 2 | |
| 509 | + ], | |
| 510 | + ] | |
| 511 | + ], | |
| 512 | + // Date Submitted | |
| 513 | + [ | |
| 514 | + 'id' => 36, | |
| 515 | + 'fieldIndex' => 12, | |
| 516 | + 'type' => 'date', | |
| 517 | + 'label' => BackendStrings::getTemplateStrings()['date_submitted'], | |
| 518 | + 'placeholder' => '', | |
| 519 | + 'required' => false, | |
| 520 | + 'parentId' => null, | |
| 521 | + 'defaultValue' => '', | |
| 522 | + 'position' => 12, | |
| 523 | + 'dateFieldType' => 'picker', | |
| 524 | + 'dateFormat' => 'MM/DD/YYYY', | |
| 525 | + ], | |
| 526 | + ]; | |
| 527 | + } | |
| 528 | +} | |