Skip to content

Commit 1c39f4d

Browse files
juancpbinarioywarnier
authored andcommitted
Session: Scheduled announcements: Add user extra fields to scheduled announcements editor - refs #4816
Co-authored-by: Juan Cortizas Ponte <124381395+juancpbinario@users.noreply.github.com>
1 parent 2150bf2 commit 1c39f4d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

main/inc/lib/ScheduledAnnouncement.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ public function sendPendingMessages($urlId = 0)
301301
$result = $this->get_all();
302302
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
303303

304+
// get user extra fields list (only visible to self and filter-able)
305+
$extraField = new ExtraField('user');
306+
$extraFields = $extraField->get_all(['filter = ? AND visible_to_self = ?' => [1, 1]]);
307+
308+
304309
foreach ($result as $result) {
305310
if (empty($result['sent'])) {
306311
if (!empty($result['date']) && $result['date'] < $now) {
@@ -412,6 +417,19 @@ public function sendPendingMessages($urlId = 0)
412417
'((lp_progress))' => $progress,
413418
];
414419

420+
if (!empty($extraFields)) {
421+
$efv = new ExtraFieldValue('user');
422+
423+
foreach ($extraFields as $extraField) {
424+
$valueExtra = $efv->get_values_by_handler_and_field_variable(
425+
$user['user_id'],
426+
$extraField['variable'],
427+
true
428+
);
429+
$tags['(('.strtolower($extraField['variable']).'))'] = $valueExtra['value'];
430+
}
431+
}
432+
415433
$message = str_replace(array_keys($tags), $tags, $message);
416434
$message .= $attachments;
417435

@@ -461,6 +479,14 @@ public function getTags()
461479
'((user_picture))',
462480
'((lp_progress))',
463481
];
482+
// get user extra fields list (only visible to self and filter-able)
483+
$extraField = new ExtraField('user');
484+
$extraFields = $extraField->get_all(['filter = ? AND visible_to_self = ?' => [1, 1]]);
485+
if (!empty($extraFields)) {
486+
foreach ($extraFields as $extraField) {
487+
$tags[] = '(('.strtolower($extraField['variable']).'))';
488+
}
489+
}
464490

465491
return $tags;
466492
}

0 commit comments

Comments
 (0)