49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\View\Components\Site;
|
|
|
|
use App\Enums\CacheTag;
|
|
use App\Models\DocumentationVersion;
|
|
use App\Models\Project;
|
|
use App\Models\User;
|
|
use App\Services\WebsiteTranslations;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\View\Component;
|
|
use Illuminate\View\View;
|
|
|
|
final class ChooseVersion extends Component
|
|
{
|
|
public function __construct(
|
|
private readonly DocumentationVersion $version,
|
|
private readonly WebsiteTranslations $websiteTranslations,
|
|
private readonly Project $project,
|
|
private readonly ?User $user,
|
|
) { }
|
|
|
|
public function render(): View
|
|
{
|
|
$isPublic = null;
|
|
if (\is_null($this->user) || $this->user->cannot('viewAny', DocumentationVersion::class)) {
|
|
$isPublic = 1;
|
|
}
|
|
|
|
$seconds = 3600 * 12;
|
|
$versions = CacheTag::DocumantationVersion->getCache()
|
|
->remember(self::class . $this->project->id . '-' . $isPublic ?? 0, $seconds, function () use ($isPublic) {
|
|
return $this->project->documentationVersions()
|
|
->when($isPublic, function (Builder $query) {
|
|
$query->where('is_public', 1);
|
|
})
|
|
->get();
|
|
});
|
|
|
|
return view('components.site.choose-version', [
|
|
'websiteTranslations' => $this->websiteTranslations,
|
|
'versions' => $versions,
|
|
'version' => $this->version,
|
|
'project' => $this->project,
|
|
]);
|
|
}
|
|
}
|