toby/app/Infrastructure/Slack/Elements/VacationRequestsAttachment.php
2022-05-06 08:01:09 +02:00

34 lines
1.1 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->profile->full_name,"date"=>$date]);
});
}
}