broker_sidebar.php
14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?php
$individual_assignments = get_field('assignments', 'option');
$user_broker_id = get_user_meta(7525, 'broker_id', true);
$farm_team_1 = get_field('farm_team_1', 'option');
$farm_team_2 = get_field('farm_team_2', 'option');
$commercial_team_1 = get_field('commercial_team_1', 'option');
$commercial_team_2 = get_field('commercial_team_2', 'option');
$assignment_arr = [['indep'=>[],'personal'=>[],'farm'=>[],'commercial'=>[]]];
// $assignment_arr[] = ['title'=>__("PERSONAL LINES", 'broker_assignments'),'team'];
//Auto - Sub Category (!could be many!)
//Property - Sub Category (!could be many!)
//Team Leaders - Sub Category (!could be many!)
// $assignment_arr[] = ['title'=>__("COMMERCIAL LINES", 'broker_assignments')];
//Team Assignment - eg Category = Commercial, Sub Category = Commercial Team #2 (then pull from team assignment)
//Field Underwriter - eg Category = Commercial, Sub Category = Field Underwriter
// $assignment_arr[] = ['title'=>__("FARM", 'broker_assignments')];
//Team Assignment - eg Category = Farm, Category = Farm Team #1 (then pull from team assignment)
// $assignment_arr[] = ['title'=>__("CLAIMS", 'broker_assignments')];
//Category Claims Sub (N/A)
// $assignment_arr[] = ['title'=>__("BILLINGS", 'broker_assignments')];
//Category Billings Sub (N/A)
// $assignment_arr[] = ['title'=>__("IT", 'broker_assignments')];
//Category IT Sub (N/A)
function independantAssignment(&$assignment_arr, $staff_contact, $cat) {
$full_name = $staff_contact['full_name'];
$email = $staff_contact['email'];
$phone = $staff_contact['phone'];
fillStaffContact($assignment_arr, 'indep', ['title'=>$cat['label'],
'full_name'=>$full_name,'email'=>$email,'phone'=>$phone]);
}
function personalStaffAssignment(&$assignment_arr, $staff_contact, $cat, $sub_cat) {
//Personal Lines.. the UX is setup as so..
/*
Auto
@email
#phone
Property
@email
#phone
Team Leaders
name
name
*/
$full_name = $staff_contact['full_name'];
$email = $staff_contact['email'];
$phone = $staff_contact['phone'];
//Team leaders fall under 1 label in the UX
if($sub_cat['value'] == 'team_leader') {
fillStaffContact($assignment_arr, 'personal', ['title'=>$cat['label'],
'full_name'=>$full_name,'email'=>$email,'label'=>'team_leader']);
} else {
//It's assumed Auto or Property or anything other would work too if a new label (sub cat) is added as long as it matches the personal cat
fillStaffContact($assignment_arr, 'personal', ['title'=>$cat['label'],
'full_name'=>$full_name,'email'=>$email,'label'=>$sub_cat['label'],'phone'=>$phone]);
}
}
function farmLinesStaffAssignment(&$assignment_arr, $staff_contact, $cat, $sub_cat) {
//Farm Lines.. the UX is setup as so..
/*
Label = Farm Lines
Sub label = eg(Farm Line #1)
Specific Person Name *
@email
#phone
Field Underwriter
Name
@email
#phone
Global
@email
*/
$full_name = $staff_contact['full_name'];
$email = $staff_contact['email'];
$phone = $staff_contact['phone'];
if($sub_cat && strpos(strtolower($sub_cat['value']), 'farm') !== false) {
//General Contact
fillStaffContact($assignment_arr, 'farm', ['title'=>"",
'full_name'=>$full_name,'email'=>$email,'phone'=>$phone,'label'=>$sub_cat['label']]);
} else if($sub_cat && strpos(strtolower($sub_cat['value']), 'writer') !== false) {
//General Contact
fillStaffContact($assignment_arr, 'farm', ['label'=>'','title'=>"Field Underwriter",
'full_name'=>$full_name,'email'=>$email,'phone'=>$phone]);
} else {
//General Contact
fillStaffContact($assignment_arr, 'farm', ['title'=>"",
'full_name'=>$full_name,'email'=>$email,'phone'=>$phone,'label'=>'']);
}
}
function commercialLinesStaffAssignment(&$assignment_arr, $staff_contact, $cat, $sub_cat) {
//Commercial Lines.. the UX is setup as so..
/*
Label = Commercial Lines
Specific Person Name
@email
#phone
General Contact
@email
#phone
*/
// if($sub_cat && $sub_cat['value'] !== 'na') {
// //Specific Person
// } else {
$full_name = $staff_contact['full_name'];
$email = $staff_contact['email'];
$phone = $staff_contact['phone'];
//General Contact
fillStaffContact($assignment_arr, 'commercial', ['title'=>"",
'full_name'=>$full_name,'email'=>$email,'phone'=>$phone,'label'=>'']);
// }
}
function assignStaffContact(&$assignment_arr, $staff_contact, $type) {
$cat = $staff_contact['category'];
$sub_cat = $staff_contact['sub_category'];
//This is for standard none special setups unline (Personal, Farm, and Commercial)
if($type == 'indep' && is_array($cat)) {
independantAssignment($assignment_arr, $staff_contact, $cat);
} else if($type == 'personal' && is_array($sub_cat)) {
personalStaffAssignment($assignment_arr, $staff_contact, $cat, $sub_cat);
} else if($type == 'commercial' && is_array($sub_cat)) {
commercialLinesStaffAssignment($assignment_arr, $staff_contact, $cat, $sub_cat);
} else if($type == 'farm' && is_array($sub_cat)) {
farmLinesStaffAssignment($assignment_arr, $staff_contact, $cat, $sub_cat);
}
}
function fillStaffContactInfo($staff_contact, $user_broker_id, &$assignment_arr) {
//Do not process these ones as normal because they have a special setup needed
$manual_cats = ['personal','commercial','farm'];
$brokerages = $staff_contact['brokerages'];
$cat = $staff_contact['category'];
$sub_cat = $staff_contact['sub_category'];
//Before check for if this is a direct broker assignment and it matches the current user
if($brokerages) {
if(!hasBrokerAssignment($user_broker_id, $brokerages)) {
return;
}
}
//Independant assignment eg(billing, business development, IT)
if(!in_array($cat['value'], $manual_cats)) {
assignStaffContact($assignment_arr, $staff_contact, 'indep');
} else {
//Before check to make sure if there is a team assignment related to this selected sub cat
//The relation is the value of the sub cat field to the name of the field in the Team Assignments ACF group
if($sub_cat) {
if(checkTeamAssignment($user_broker_id, $sub_cat['value'])) {
assignStaffContact($assignment_arr, $staff_contact, $cat['value']);
}
} else {
assignStaffContact($assignment_arr, $staff_contact, $cat['value']);
}
}
return true;
}
function checkTeamAssignment($user_broker_id, $name) {
$team_assignment = get_field($name, 'option');
if($team_assignment) {
$brokerages = $team_assignment['broker_assignment'];
if(hasBrokerAssignment($user_broker_id, $brokerages)) {
return true;
} else {
return false;
}
}
return true;
}
//Used to do a general check if a users broker is assigned to the list of brokerages supplied by the custom field
function hasBrokerAssignment($user_broker_id, $brokerages) {
foreach($brokerages as $broker) {
if($broker->post_author == $user_broker_id) {
return true;
}
}
}
//Used to filter out general name lines
function isValidFullname($name) {
$cleaned_name = trim(strtolower($name));
if(strpos($cleaned_name, 'general')) {
return "";
}
//Filter out this if it's just a single name
if(strpos($cleaned_name, ' ') === false) {
return "";
}
return $name;
}
//Used as the main location of fill the assignment array for the accordion !! you can make global final adjustments to things here such !!
function fillStaffContact(&$assignment_arr, $type, $arr) {
if(isset($arr['full_name'])) {
$arr['full_name'] = isValidFullname( $arr['full_name'] );
}
$assignment_arr[$type][] = $arr;
}
foreach($individual_assignments as $aa) {
fillStaffContactInfo($aa, $user_broker_id, $assignment_arr);
}
?>
<h2><?= _("Your Commonwell Team") ?></h2>
<section>
<div class="accordian">
<div class="accordian_head">
<div class="accordian_toggler"></div>
<span class="accordian_title"><?= __('Personal') ?></span>
</div>
<div class="accordian_body ">
<?php
$team_leaders = [];
foreach($assignment_arr['personal'] as $aa) { ?>
<?php if($aa['label'] == 'team_leader') { $team_leaders[] = $aa; ?>
<?php } else { ?>
<address>
<ul>
<?php if(!empty($aa['label'])) { ?>
<li><b><?= $aa['label'] ?></b></li>
<?php } ?>
<?php if(!empty($aa['email'])) { ?>
<li><a href='mailto:<?= $aa['email'] ?>'><?= $aa['email'] ?></a></li>
<?php } ?>
<?php if(!empty($aa['phone'])) { ?>
<li><?= $aa['phone'] ?></li>
<?php } ?>
</ul>
</address>
<?php } ?>
<?php } ?>
<?php if(count($team_leaders) > 0) { ?>
<address>
<b><?= __("Team Leaders") ?></b>
<ul>
<?php foreach($team_leaders as $tl) { ?>
<li><?= $tl['full_name'] ?></li>
<?php } ?>
</ul>
</address>
<?php } ?>
</div>
</div>
<div class="accordian">
<div class="accordian_head">
<div class="accordian_toggler"></div>
<span class="accordian_title"><?= __('Commercial Lines') ?></span>
</div>
<div class="accordian_body">
<?php
foreach($assignment_arr['commercial'] as $aa) { ?>
<address>
<ul>
<?php if(!empty($aa['label'])) { ?>
<li><b><?= $aa['label'] ?></b></li>
<?php } ?>
<?php if(!empty($aa['full_name'])) { ?>
<li><?= $aa['full_name'] ?></li>
<?php } ?>
<?php if(!empty($aa['email'])) { ?>
<li><a href='mailto:<?= $aa['email'] ?>'><?= $aa['email'] ?></a></li>
<?php } ?>
<?php if(!empty($aa['phone'])) { ?>
<li><?= $aa['phone'] ?></li>
<?php } ?>
</ul>
</address>
<?php } ?>
</div>
</div>
<div class="accordian">
<div class="accordian_head">
<div class="accordian_toggler"></div>
<span class="accordian_title"><?= __('Farm Lines') ?></span>
</div>
<div class="accordian_body">
<?php
$team_labeled = false;
//The team info must be first!
$backlogged_infos = [];
foreach($assignment_arr['farm'] as $aa) { ?>
<?php if(!empty($aa['label'])) { ?>
<?php if(!$team_labeled) { $team_labeled = true; ?> <b><?= __($aa['label']) ?></b> <?php } ?>
<?php } ?>
<?php if(empty($aa['label']) && !$team_labeled) {
$backlogged_infos[] = $aa;
}
?>
<address>
<ul>
<?php if(!empty($aa['title'])) { ?>
<li><b><?= $aa['title'] ?></b></li>
<?php } ?>
<?php if(!empty($aa['full_name'])) { ?>
<li><?= $aa['full_name'] ?></li>
<?php } ?>
<?php if(!empty($aa['email'])) { ?>
<li><a href='mailto:<?= $aa['email'] ?>'><?= $aa['email'] ?></a></li>
<?php } ?>
<?php if(!empty($aa['phone'])) { ?>
<li><?= $aa['phone'] ?></li>
<?php } ?>
</ul>
</address>
<?php foreach($backlogged_infos as $bi) { ?>
<address>
<ul>
<?php if(!empty($aa['title'])) { ?>
<li><?= $aa['title'] ?></li>
<?php } ?>
<?php if(!empty($bi['full_name'])) { ?>
<li><?= $bi['full_name'] ?></li>
<?php } ?>
<?php if(!empty($bi['email'])) { ?>
<li><a href='mailto:<?= $aa['email'] ?>'><?= $bi['email'] ?></a></li>
<?php } ?>
<?php if(!empty($bi['phone'])) { ?>
<li><?= $bi['phone'] ?></li>
<?php } ?>
</ul>
</address>
<?php } ?>
<?php } ?>
</address>
</div>
</div>
<?php foreach($assignment_arr['indep'] as $aa) { ?>
<div class="accordian">
<div class="accordian_head">
<div class="accordian_toggler"></div>
<span class="accordian_title"><?= $aa['title'] ?></span>
</div>
<div class="accordian_body">
<address>
<ul>
<?php if(!empty($aa['label'])) { ?>
<li><?= $aa['label'] ?></li>
<?php } ?>
<?php if(!empty($aa['full_name'])) { ?>
<li><?= $aa['full_name'] ?></li>
<?php } ?>
<?php if(!empty($aa['email'])) { ?>
<li><a href='mailto:<?= $aa['email'] ?>'><?= $aa['email'] ?></a></li>
<?php } ?>
<?php if(!empty($aa['phone'])) { ?>
<li><?= $aa['phone'] ?></li>
<?php } ?>
</ul>
</address>
</div>
</div>
<?php } ?>
</section>