← All changes
|
backend/src/Services/Template/SickLeaveRequestFormTemplate.php
+49
-31
0.7
→
1.5
View file →
| @@ -1,23 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace IvyForms\Services\Template; |
| 4 | 4 | |
| 5 | -// phpcs:disable PSR1.Files.SideEffects | |
| 6 | -if (!defined('ABSPATH')) { | |
| 7 | - exit; // Exit if accessed directly | |
| 8 | -} | |
| 9 | - | |
| 10 | 5 | use IvyForms\Services\Translations\BackendStrings; |
| 11 | 6 | |
| 12 | 7 | class SickLeaveRequestFormTemplate |
| 13 | 8 | { |
| 14 | 9 | /** |
| 15 | - * Get the sick leave request form template | |
| 10 | + * Get template metadata (without form_data) | |
| 16 | 11 | * |
| 17 | 12 | * @return array<string, mixed> |
| 18 | 13 | */ |
| 19 | - public static function getTemplate(): array | |
| 14 | + public static function getTemplateMeta(): array | |
| 20 | 15 | { |
| 21 | 16 | return [ |
| 22 | 17 | 'id' => 'sick_leave_request_form', |
| 23 | 18 | 'name' => BackendStrings::getTemplateStrings()['sick_leave_request_form'], |
| @@ -22,10 +17,24 @@ | ||
| 22 | 17 | 'id' => 'sick_leave_request_form', |
| 23 | 18 | 'name' => BackendStrings::getTemplateStrings()['sick_leave_request_form'], |
| 24 | 19 | 'description' => BackendStrings::getTemplateStrings()['sick_leave_request_form_desc'], |
| 25 | 20 | 'category' => 'leave-request', |
| 21 | + 'subcategory' => 'leave-request-forms', | |
| 26 | 22 | 'is_pro' => false, |
| 27 | - 'screenshot' => IVYFORMS_TEMPLATES_IMAGES_URL . 'sick-leave-request-form.svg', | |
| 23 | + 'screenshot' => IVYFORMS_TEMPLATES_IMAGES_URL . 'sick-leave-request-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 | + [ | |
| 28 | 37 | 'form_data' => [ |
| 29 | 38 | 'name' => BackendStrings::getTemplateStrings()['sick_leave_request_form'], |
| 30 | 39 | 'published' => 1, |
| 31 | 40 | 'showTitle' => 1, |
| @@ -33,9 +42,10 @@ | ||
| 33 | 42 | 'integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings(), |
| 34 | 43 | 'fields' => self::getFormFields(), |
| 35 | 44 | 'settings' => [] |
| 36 | 45 | ] |
| 37 | - ]; | |
| 46 | + ] | |
| 47 | + ); | |
| 38 | 48 | } |
| 39 | 49 | |
| 40 | 50 | /** |
| 41 | 51 | * Get all form fields |
| @@ -64,9 +74,9 @@ | ||
| 64 | 74 | */ |
| 65 | 75 | private static function getNameField(): array |
| 66 | 76 | { |
| 67 | 77 | return [ |
| 68 | - 'id' => 0, | |
| 78 | + 'id' => 1, | |
| 69 | 79 | 'fieldIndex' => 1, |
| 70 | 80 | 'type' => 'name', |
| 71 | 81 | 'label' => BackendStrings::getTemplateStrings()['full_name'], |
| 72 | 82 | 'parentId' => null, |
| @@ -85,14 +95,14 @@ | ||
| 85 | 95 | */ |
| 86 | 96 | private static function getFirstNameField(): array |
| 87 | 97 | { |
| 88 | 98 | return [ |
| 89 | - 'id' => 0, | |
| 99 | + 'id' => 2, | |
| 90 | 100 | 'type' => 'text', |
| 91 | 101 | 'label' => BackendStrings::getNewFormStrings()['first_name'], |
| 92 | 102 | 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_first_name'], |
| 93 | 103 | 'required' => true, |
| 94 | - 'parentId' => 0, | |
| 104 | + 'parentId' => 1, | |
| 95 | 105 | 'fieldIndex' => 1, |
| 96 | 106 | 'defaultValue' => '', |
| 97 | 107 | 'position' => 1, |
| 98 | 108 | 'optionHide' => false, |
| @@ -108,14 +118,14 @@ | ||
| 108 | 118 | */ |
| 109 | 119 | private static function getLastNameField(): array |
| 110 | 120 | { |
| 111 | 121 | return [ |
| 112 | - 'id' => 0, | |
| 122 | + 'id' => 3, | |
| 113 | 123 | 'type' => 'text', |
| 114 | 124 | 'label' => BackendStrings::getNewFormStrings()['last_name'], |
| 115 | 125 | 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_last_name'], |
| 116 | 126 | 'required' => true, |
| 117 | - 'parentId' => 0, | |
| 127 | + 'parentId' => 1, | |
| 118 | 128 | 'fieldIndex' => 1, |
| 119 | 129 | 'defaultValue' => '', |
| 120 | 130 | 'position' => 2, |
| 121 | 131 | 'optionHide' => false, |
| @@ -131,9 +141,9 @@ | ||
| 131 | 141 | */ |
| 132 | 142 | private static function getEmailField(): array |
| 133 | 143 | { |
| 134 | 144 | return [ |
| 135 | - 'id' => 0, | |
| 145 | + 'id' => 4, | |
| 136 | 146 | 'fieldIndex' => 2, |
| 137 | 147 | 'type' => 'email', |
| 138 | 148 | 'label' => BackendStrings::getTemplateStrings()['email_address'], |
| 139 | 149 | 'placeholder' => '[email protected]', |
| @@ -151,9 +161,9 @@ | ||
| 151 | 161 | */ |
| 152 | 162 | private static function getDepartmentField(): array |
| 153 | 163 | { |
| 154 | 164 | return [ |
| 155 | - 'id' => 0, | |
| 165 | + 'id' => 5, | |
| 156 | 166 | 'fieldIndex' => 3, |
| 157 | 167 | 'type' => 'select', |
| 158 | 168 | 'label' => BackendStrings::getTemplateStrings()['department'], |
| 159 | 169 | 'placeholder' => BackendStrings::getTemplateStrings()['select_department'], |
| @@ -160,9 +170,9 @@ | ||
| 160 | 170 | 'required' => true, |
| 161 | 171 | 'parentId' => null, |
| 162 | 172 | 'defaultValue' => '', |
| 163 | 173 | 'position' => 3, |
| 164 | - 'fieldOptions' => self::getDepartmentOptions(), | |
| 174 | + 'fieldOptions' => self::getDepartmentOptions(1), | |
| 165 | 175 | ]; |
| 166 | 176 | } |
| 167 | 177 | |
| 168 | 178 | /** |
| @@ -167,15 +177,17 @@ | ||
| 167 | 177 | |
| 168 | 178 | /** |
| 169 | 179 | * Get department field options |
| 170 | 180 | * |
| 181 | + * @param int $startId Starting ID for the options | |
| 182 | + * | |
| 171 | 183 | * @return array<int, array<string, mixed>> |
| 172 | 184 | */ |
| 173 | - private static function getDepartmentOptions(): array | |
| 185 | + private static function getDepartmentOptions(int $startId): array | |
| 174 | 186 | { |
| 175 | 187 | return [ |
| 176 | 188 | [ |
| 177 | - 'id' => 0, | |
| 189 | + 'id' => $startId, | |
| 178 | 190 | 'label' => BackendStrings::getTemplateStrings()['hr'], |
| 179 | 191 | 'value' => 'hr', |
| 180 | 192 | 'isDefault' => false, |
| 181 | 193 | 'position' => 1 |
| @@ -180,9 +192,9 @@ | ||
| 180 | 192 | 'isDefault' => false, |
| 181 | 193 | 'position' => 1 |
| 182 | 194 | ], |
| 183 | 195 | [ |
| 184 | - 'id' => 0, | |
| 196 | + 'id' => $startId + 1, | |
| 185 | 197 | 'label' => BackendStrings::getTemplateStrings()['it'], |
| 186 | 198 | 'value' => 'it', |
| 187 | 199 | 'isDefault' => false, |
| 188 | 200 | 'position' => 2 |
| @@ -187,9 +199,9 @@ | ||
| 187 | 199 | 'isDefault' => false, |
| 188 | 200 | 'position' => 2 |
| 189 | 201 | ], |
| 190 | 202 | [ |
| 191 | - 'id' => 0, | |
| 203 | + 'id' => $startId + 2, | |
| 192 | 204 | 'label' => BackendStrings::getTemplateStrings()['sales'], |
| 193 | 205 | 'value' => 'sales', |
| 194 | 206 | 'isDefault' => false, |
| 195 | 207 | 'position' => 3 |
| @@ -194,9 +206,9 @@ | ||
| 194 | 206 | 'isDefault' => false, |
| 195 | 207 | 'position' => 3 |
| 196 | 208 | ], |
| 197 | 209 | [ |
| 198 | - 'id' => 0, | |
| 210 | + 'id' => $startId + 3, | |
| 199 | 211 | 'label' => BackendStrings::getTemplateStrings()['marketing'], |
| 200 | 212 | 'value' => 'marketing', |
| 201 | 213 | 'isDefault' => false, |
| 202 | 214 | 'position' => 4 |
| @@ -201,9 +213,9 @@ | ||
| 201 | 213 | 'isDefault' => false, |
| 202 | 214 | 'position' => 4 |
| 203 | 215 | ], |
| 204 | 216 | [ |
| 205 | - 'id' => 0, | |
| 217 | + 'id' => $startId + 4, | |
| 206 | 218 | 'label' => BackendStrings::getTemplateStrings()['other'], |
| 207 | 219 | 'value' => 'other', |
| 208 | 220 | 'isDefault' => false, |
| 209 | 221 | 'position' => 5 |
| @@ -218,9 +230,9 @@ | ||
| 218 | 230 | */ |
| 219 | 231 | private static function getSickLeaveStartDateField(): array |
| 220 | 232 | { |
| 221 | 233 | return [ |
| 222 | - 'id' => 0, | |
| 234 | + 'id' => 11, | |
| 223 | 235 | 'fieldIndex' => 4, |
| 224 | 236 | 'type' => 'date', |
| 225 | 237 | 'label' => BackendStrings::getTemplateStrings()['sick_leave_start_date'], |
| 226 | 238 | 'placeholder' => BackendStrings::getTemplateStrings()['select_start_date'], |
| @@ -227,8 +239,10 @@ | ||
| 227 | 239 | 'required' => true, |
| 228 | 240 | 'parentId' => null, |
| 229 | 241 | 'defaultValue' => '', |
| 230 | 242 | 'position' => 5, |
| 243 | + 'dateFieldType' => 'picker', | |
| 244 | + 'dateFormat' => 'MM/DD/YYYY', | |
| 231 | 245 | ]; |
| 232 | 246 | } |
| 233 | 247 | |
| 234 | 248 | /** |
| @@ -238,9 +252,9 @@ | ||
| 238 | 252 | */ |
| 239 | 253 | private static function getSickLeaveEndDateField(): array |
| 240 | 254 | { |
| 241 | 255 | return [ |
| 242 | - 'id' => 0, | |
| 256 | + 'id' => 12, | |
| 243 | 257 | 'fieldIndex' => 5, |
| 244 | 258 | 'type' => 'date', |
| 245 | 259 | 'label' => BackendStrings::getTemplateStrings()['sick_leave_end_date'], |
| 246 | 260 | 'placeholder' => BackendStrings::getTemplateStrings()['select_end_date'], |
| @@ -247,8 +261,10 @@ | ||
| 247 | 261 | 'required' => true, |
| 248 | 262 | 'parentId' => null, |
| 249 | 263 | 'defaultValue' => '', |
| 250 | 264 | 'position' => 6, |
| 265 | + 'dateFieldType' => 'picker', | |
| 266 | + 'dateFormat' => 'MM/DD/YYYY', | |
| 251 | 267 | ]; |
| 252 | 268 | } |
| 253 | 269 | |
| 254 | 270 | /** |
| @@ -258,9 +274,9 @@ | ||
| 258 | 274 | */ |
| 259 | 275 | private static function getDoctorsNoteField(): array |
| 260 | 276 | { |
| 261 | 277 | return [ |
| 262 | - 'id' => 0, | |
| 278 | + 'id' => 13, | |
| 263 | 279 | 'fieldIndex' => 6, |
| 264 | 280 | 'type' => 'textarea', |
| 265 | 281 | 'label' => BackendStrings::getTemplateStrings()['doctors_note'], |
| 266 | 282 | 'placeholder' => BackendStrings::getTemplateStrings()['attach_doctors_note_if_required'], |
| @@ -278,9 +294,9 @@ | ||
| 278 | 294 | */ |
| 279 | 295 | private static function getNotifySupervisorField(): array |
| 280 | 296 | { |
| 281 | 297 | return [ |
| 282 | - 'id' => 0, | |
| 298 | + 'id' => 14, | |
| 283 | 299 | 'fieldIndex' => 7, |
| 284 | 300 | 'type' => 'radio', |
| 285 | 301 | 'label' => BackendStrings::getTemplateStrings()['notify_supervisor'], |
| 286 | 302 | 'placeholder' => '', |
| @@ -287,9 +303,9 @@ | ||
| 287 | 303 | 'required' => false, |
| 288 | 304 | 'parentId' => null, |
| 289 | 305 | 'defaultValue' => '', |
| 290 | 306 | 'position' => 8, |
| 291 | - 'fieldOptions' => self::getNotifySupervisorOptions(), | |
| 307 | + 'fieldOptions' => self::getNotifySupervisorOptions(1), | |
| 292 | 308 | ]; |
| 293 | 309 | } |
| 294 | 310 | |
| 295 | 311 | /** |
| @@ -294,15 +310,17 @@ | ||
| 294 | 310 | |
| 295 | 311 | /** |
| 296 | 312 | * Get notify supervisor field options |
| 297 | 313 | * |
| 314 | + * @param int $startId Starting ID for the options | |
| 315 | + * | |
| 298 | 316 | * @return array<int, array<string, mixed>> |
| 299 | 317 | */ |
| 300 | - private static function getNotifySupervisorOptions(): array | |
| 318 | + private static function getNotifySupervisorOptions(int $startId): array | |
| 301 | 319 | { |
| 302 | 320 | return [ |
| 303 | 321 | [ |
| 304 | - 'id' => 0, | |
| 322 | + 'id' => $startId, | |
| 305 | 323 | 'label' => BackendStrings::getTemplateStrings()['yes'], |
| 306 | 324 | 'value' => 'yes', |
| 307 | 325 | 'isDefault' => false, |
| 308 | 326 | 'position' => 1 |
| @@ -307,9 +325,9 @@ | ||
| 307 | 325 | 'isDefault' => false, |
| 308 | 326 | 'position' => 1 |
| 309 | 327 | ], |
| 310 | 328 | [ |
| 311 | - 'id' => 0, | |
| 329 | + 'id' => $startId + 1, | |
| 312 | 330 | 'label' => BackendStrings::getTemplateStrings()['no'], |
| 313 | 331 | 'value' => 'no', |
| 314 | 332 | 'isDefault' => false, |
| 315 | 333 | 'position' => 2 |