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