
* #126 - vacation request reminders * #126 - fix workdays * #126 - changes * #126 - cs fix * #5 - bump codestyle * #126 - fix * #126 - fix * #126 - fix * #126 - fix * #126 - tests * #126 - fix * #126 - fix * #126 - fix seeders * #126 - fix * #126 - tests Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Toby\Domain\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
use Toby\Eloquent\Models\User;
|
|
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
|
|
|
class KeyHasBeenGivenNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
protected User $sender,
|
|
protected User $recipient,
|
|
) {}
|
|
|
|
public function via(): array
|
|
{
|
|
return [Channels::SLACK];
|
|
}
|
|
|
|
public function toSlack(Notifiable $notifiable): SlackMessage
|
|
{
|
|
return (new SlackMessage())
|
|
->text(__(":sender gives key no :key to :recipient", [
|
|
"sender" => $this->getName($this->sender),
|
|
"recipient" => $this->getName($this->recipient),
|
|
"key" => $notifiable->id,
|
|
]));
|
|
}
|
|
|
|
protected function getName(User $user): string
|
|
{
|
|
if ($user->profile->slack_id !== null) {
|
|
return "<@{$user->profile->slack_id}>";
|
|
}
|
|
|
|
return $user->profile->full_name;
|
|
}
|
|
}
|