|
|
@@ -16,21 +16,22 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class EmailComunications extends Component
|
|
|
{
|
|
|
- public $records, $subject, $message, $selectedRecipients = [], $scheduledDateTime, $sendNow = true;
|
|
|
+ public $records, $subject, $message, $attachments = [], $recipients = [], $scheduledDateTime, $sendNow = true;
|
|
|
public $dataId, $update = false, $add = false;
|
|
|
public $users = [];
|
|
|
+ public $categories = [];
|
|
|
|
|
|
protected $rules = [
|
|
|
'subject' => 'required|string|max:255',
|
|
|
'message' => 'required|string',
|
|
|
- 'selectedRecipients' => 'required|array|min:1',
|
|
|
+ // 'recipients' => 'required|array|min:1',
|
|
|
'scheduledDateTime' => 'required_if:sendNow,false|date|after:now',
|
|
|
];
|
|
|
|
|
|
protected $messages = [
|
|
|
'subject.required' => 'L\'oggetto è obbligatorio',
|
|
|
'message.required' => 'Il messaggio è obbligatorio',
|
|
|
- 'selectedRecipients.required' => 'Seleziona almeno un gruppo di destinatari',
|
|
|
+ // 'recipients.required' => 'Seleziona almeno un gruppo di destinatari',
|
|
|
'scheduledDateTime.required_if' => 'La data di programmazione è obbligatoria',
|
|
|
'scheduledDateTime.after' => 'La data di programmazione deve essere futura',
|
|
|
];
|
|
|
@@ -45,7 +46,7 @@ class EmailComunications extends Component
|
|
|
|
|
|
public function sortBy($field)
|
|
|
{
|
|
|
- if($this->sortField === $field) {
|
|
|
+ if ($this->sortField === $field) {
|
|
|
$this->sortAsc = ! $this->sortAsc;
|
|
|
} else {
|
|
|
$this->sortAsc = true;
|
|
|
@@ -58,24 +59,35 @@ class EmailComunications extends Component
|
|
|
{
|
|
|
$this->subject = '';
|
|
|
$this->message = '';
|
|
|
- $this->selectedRecipients = [];
|
|
|
+ $this->attachments = [];
|
|
|
+ $this->recipients = [];
|
|
|
$this->sendNow = true;
|
|
|
$this->scheduledDateTime = now()->addHour()->format('Y-m-d\TH:i');
|
|
|
+
|
|
|
$this->emit('load-data-table');
|
|
|
+ $this->emit('load-editor');
|
|
|
}
|
|
|
|
|
|
public function mount()
|
|
|
{
|
|
|
- if(Auth::user()->level != env('LEVEL_ADMIN', 0))
|
|
|
+ if (Auth::user()->level != env('LEVEL_ADMIN', 0))
|
|
|
return redirect()->to('/dashboard');
|
|
|
|
|
|
$this->users = Member::select('id', 'last_name', 'email')->get();
|
|
|
+
|
|
|
+ $this->categories = [];
|
|
|
+ $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->orderBy('name')->get(), 0);
|
|
|
+
|
|
|
$this->scheduledDateTime = now()->addHour()->format('Y-m-d\TH:i');
|
|
|
}
|
|
|
|
|
|
public function render()
|
|
|
{
|
|
|
$this->records = EmailTemplate::orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')->get();
|
|
|
+
|
|
|
+ $this->categories = [];
|
|
|
+ $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->orderBy('name')->get(), 0);
|
|
|
+
|
|
|
return view('livewire.email_comunications');
|
|
|
}
|
|
|
|
|
|
@@ -97,7 +109,7 @@ class EmailComunications extends Component
|
|
|
'created_by' => Auth::id(),
|
|
|
]);
|
|
|
|
|
|
- $recipients = User::whereIn('id', $this->selectedRecipients)->get();
|
|
|
+ $recipients = User::whereIn('id', $this->recipients)->get();
|
|
|
|
|
|
if ($this->sendNow) {
|
|
|
$this->sendEmailNow($template, $recipients);
|
|
|
@@ -127,6 +139,8 @@ class EmailComunications extends Component
|
|
|
$this->dataId = $template->id;
|
|
|
$this->update = true;
|
|
|
$this->add = false;
|
|
|
+
|
|
|
+ $this->emit('load-editor');
|
|
|
}
|
|
|
} catch (\Exception $ex) {
|
|
|
session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
@@ -203,4 +217,13 @@ class EmailComunications extends Component
|
|
|
|
|
|
Log::info("Email scheduled for {$this->scheduledDateTime} to {$recipients->count()} recipients: {$template->name}");
|
|
|
}
|
|
|
+
|
|
|
+ public function getCategories($records, $indentation)
|
|
|
+ {
|
|
|
+ foreach ($records as $record) {
|
|
|
+ $this->categories[] = array('id' => $record->id, 'name' => $record->getTree());
|
|
|
+ if (count($record->childs))
|
|
|
+ $this->getCategories($record->childs, $indentation + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|