toby/app/Infrastructure/Slack/Elements/VacationRequestsAttachment.php
Ewelina Lasowy 7154caa340
#132 - clean up notifications (#147)
* #132 - added translations

* wip

* #132 - added translations

* #132 - cs fix

* #132 - cs fix

Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl>
2022-05-17 15:17:09 +02:00

39 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Slack\Elements;
use Illuminate\Support\Collection;
use Toby\Eloquent\Models\VacationRequest;
class VacationRequestsAttachment extends ListAttachment
{
public function __construct(Collection $vacationRequests)
{
parent::__construct();
$this
->setColor("#527aba")
->setItems($this->mapVacationRequests($vacationRequests));
}
protected function mapVacationRequests(Collection $vacationRequests): Collection
{
return $vacationRequests->map(function (VacationRequest $request): string {
$url = route("vacation.requests.show", ["vacationRequest" => $request->id]);
$date = $request->from->equalTo($request->to)
? "{$request->from->toDisplayString()}"
: "{$request->from->toDisplayString()} - {$request->to->toDisplayString()}";
return __("<:url|Request no. :request> for user :user (:date)", [
"url" => $url,
"request" => $request->name,
"user" => $request->user->profile->full_name,
"date" => $date,
]);
});
}
}