Add the ability to include groups in either Cc: or Bcc:

This commit is contained in:
Antoine Le Gonidec 2024-07-27 18:20:12 +02:00
parent 42b9cbdba9
commit 981eb2b31b
Signed by: vv221
GPG key ID: 636B78F91CEB80D8
2 changed files with 67 additions and 18 deletions

View file

@ -102,22 +102,44 @@ class MMFCustomersGroupsServiceProvider extends ServiceProvider {
// Update the list of recipients if some groups have been selected. // Update the list of recipients if some groups have been selected.
Eventy::addAction('conversation.send_reply_save', function($conversation, $request) { Eventy::addAction('conversation.send_reply_save', function($conversation, $request) {
$groups = $request->groups; $groups_cc = $request->groups_cc;
$groups_bcc = $request->groups_bcc;
// Return early if no group has been selected. // Return early if no group has been selected.
if ( empty($groups) ) return; if ( empty($groups_cc) && empty($groups_bcc) ) return;
// Get the list of e-mails included in the selected groups.
// Cc - Get the list of e-mails included in the selected groups.
if ( !empty($groups_cc) ) {
$emails = new Collection; $emails = new Collection;
foreach ( $groups as $group_id ) { foreach ( $groups_cc as $group_id ) {
$group = CustomersGroup::find($group_id); $group = CustomersGroup::find($group_id);
$emails = $emails->concat($group->emails()); $emails = $emails->concat($group->emails());
} }
$emails = $emails->unique('email')->pluck('email'); $emails = $emails->unique('email')->pluck('email');
// Update the list of cc emails. // Update the list of Cc emails.
$cc = array_unique(array_merge( $cc = array_unique(array_merge(
$conversation->getCcArray(), $conversation->getCcArray(),
$emails->toArray() $emails->toArray()
)); ));
$conversation->setCc($cc); $conversation->setCc($cc);
}
// Bcc - Get the list of e-mails included in the selected groups.
if ( !empty($groups_bcc) ) {
$emails = new Collection;
foreach ( $groups_bcc as $group_id ) {
$group = CustomersGroup::find($group_id);
$emails = $emails->concat($group->emails());
}
$emails = $emails->unique('email')->pluck('email');
// Update the list of Bcc emails.
$bcc = array_unique(array_merge(
$conversation->getBccArray(),
$emails->toArray()
));
$conversation->setBcc($bcc);
}
// TODO: Check if this explicit save() call is required.
$conversation->save(); $conversation->save();
}, 20, 2); }, 20, 2);
} }

View file

@ -7,9 +7,9 @@
@include('partials/flash_messages') @include('partials/flash_messages')
<!-- List of Customers Groups that should be included in this Conversation --> <!-- List of Customers Groups that should be included in this Conversation as Cc: -->
<div class="form-group{{ $errors->has('groups') ? ' has-error' : '' }}"> <div class="form-group{{ $errors->has('groups_cc') ? ' has-error' : '' }}">
<label for="groups" class="col-sm-2 control-label">{{ __('Groups selection') }}</label> <label for="groups_cc" class="col-sm-2 control-label">{{ __('Groups selection - Cc:') }}</label>
<div class="col-sm-9"> <div class="col-sm-9">
<div class="multi-container"> <div class="multi-container">
@foreach ( $groups as $group ) @foreach ( $groups as $group )
@ -22,7 +22,34 @@
> >
<input <input
type="checkbox" type="checkbox"
name="groups[]" name="groups_cc[]"
id="group-{{ $group->id }}"
value="{{ $group->id }}"
>
{{ $group->name }}
</label>
</div>
</div>
@endforeach
</div>
</div>
</div>
<!-- List of Customers Groups that should be included in this Conversation as Bcc: -->
<div class="form-group{{ $errors->has('groups_bcc') ? ' has-error' : '' }}">
<label for="groups_bcc" class="col-sm-2 control-label">{{ __('Groups selection - Bcc:') }}</label>
<div class="col-sm-9">
<div class="multi-container">
@foreach ( $groups as $group )
<div class="control-group">
<div class="controls">
<label
class="control-label checkbox"
for="group-{{ $group->id }}"
style="text-align: left;"
>
<input
type="checkbox"
name="groups_bcc[]"
id="group-{{ $group->id }}" id="group-{{ $group->id }}"
value="{{ $group->id }}" value="{{ $group->id }}"
> >