72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Motion;
|
|
|
|
use App\Services\RiksdagenService;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Component;
|
|
|
|
class Show extends Component
|
|
{
|
|
public $motionId;
|
|
|
|
public $motion;
|
|
|
|
private RiksdagenService $service;
|
|
|
|
public function mount($motionId)
|
|
{
|
|
$this->motionId = $motionId;
|
|
$this->service = app(RiksdagenService::class);
|
|
|
|
$result = Cache::remember('motion_'.$motionId, 24 * 60 * 60, function () use ($motionId) {
|
|
return $this->service->getMotion($motionId);
|
|
});
|
|
|
|
$this->motion = $result->original->dokumentlista->dokument[0] ?? null;
|
|
}
|
|
|
|
#[Computed()]
|
|
public function riksdagenUrl()
|
|
{
|
|
return 'https://www.riksdagen.se/sv/dokument-lagar/dokument/'.$this->motionId;
|
|
}
|
|
|
|
#[Computed()]
|
|
public function authors()
|
|
{
|
|
if (! $this->motion || ! isset($this->motion->dokintressent->intressent)) {
|
|
return collect();
|
|
}
|
|
|
|
$intressenter = $this->motion->dokintressent->intressent;
|
|
if (! is_array($intressenter)) {
|
|
$intressenter = [$intressenter];
|
|
}
|
|
|
|
return collect($intressenter)->where('roll', 'undertecknare');
|
|
}
|
|
|
|
#[Computed()]
|
|
public function attachments()
|
|
{
|
|
if (! $this->motion || ! isset($this->motion->filbilaga->fil)) {
|
|
return collect();
|
|
}
|
|
|
|
$files = $this->motion->filbilaga->fil;
|
|
if (! is_array($files)) {
|
|
$files = [$files];
|
|
}
|
|
|
|
return collect($files);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.motion.show')
|
|
->title(($this->motion->titel ?? 'Motion').' - Riksdagen App');
|
|
}
|
|
}
|