You've already forked isop-mirror
feat: implement email notification for internship status updates and add missing student relationship
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\InternshipStatusUpdated;
|
||||
use App\Models\Internship;
|
||||
use App\Models\InternshipStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Mail;
|
||||
|
||||
class InternshipStatusController extends Controller
|
||||
{
|
||||
@@ -127,6 +129,8 @@ class InternshipStatusController extends Controller
|
||||
'modified_by' => $user->id
|
||||
]);
|
||||
|
||||
Mail::to($internship->student)->sendNow(new InternshipStatusUpdated($internship, $user->name, $internship->student->name, $internship->company->name, $internshipStatus->status, $request->status, $request->note));
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
|
||||
88
backend/app/Mail/InternshipStatusUpdated.php
Normal file
88
backend/app/Mail/InternshipStatusUpdated.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Internship;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class InternshipStatusUpdated extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
private Internship $internship;
|
||||
private string $changedByName;
|
||||
private string $studentName;
|
||||
private string $companyName;
|
||||
private string $oldStatus;
|
||||
private string $newStatus;
|
||||
private string $note;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(Internship $internship, string $changedByName, string $studentName, string $companyName, string $oldStatus, string $newStatus, string $note)
|
||||
{
|
||||
$this->internship = $internship;
|
||||
$this->changedByName = $changedByName;
|
||||
$this->studentName = $studentName;
|
||||
$this->companyName = $companyName;
|
||||
$this->oldStatus = $oldStatus;
|
||||
$this->newStatus = $newStatus;
|
||||
$this->note = $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Internship Status Updated',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'mail.internship.status_updated',
|
||||
with: [
|
||||
"internship" => $this->internship,
|
||||
"changedByName" => $this->changedByName,
|
||||
"studentName" => $this->studentName,
|
||||
"companyName" => $this->companyName,
|
||||
"oldStatus" => $this->prettyStatus($this->oldStatus),
|
||||
"newStatus" => $this->prettyStatus($this->newStatus),
|
||||
"note" => $this->note,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function prettyStatus(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
'SUBMITTED' => 'Zadané',
|
||||
'CONFIRMED' => 'Potvrdená',
|
||||
'DENIED' => 'Zamietnutá',
|
||||
'DEFENDED' => 'Obhájená',
|
||||
'NOT_DEFENDED' => 'Neobhájená',
|
||||
default => throw new \Exception("Invalid status: $status")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,11 @@ class Internship extends Model
|
||||
];
|
||||
}
|
||||
|
||||
public function student()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id');
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
@include("parts.header")
|
||||
<p>Vážená/ý {{ $studentName }},</p>
|
||||
<p>stav vašej praxe vo firme {{ $companyName }} bola aktualizovaná zo stavu "{{ $oldStatus }}" na
|
||||
"{{ $newStatus }}".</p>
|
||||
<p>Zmenu vykonal <em>{{ $changedByName }}</em>.</p>
|
||||
<br />
|
||||
|
||||
<p>Poznámka: <em>{{ $note }}</em>.</p>
|
||||
|
||||
<br />
|
||||
|
||||
<p>s pozdravom</p>
|
||||
<p>Systém ISOP UKF</p>
|
||||
@include("parts.footer")
|
||||
@@ -61,6 +61,9 @@ async function submit() {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<!-- Čakajúca hláška -->
|
||||
<LoadingAlert v-if="loading" />
|
||||
|
||||
<!-- Chybová hláška -->
|
||||
<ErrorAlert v-if="save_error" :error="`Nepodarilo uložiť: ${save_error}`" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user