mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
add dedicated Bindle page
This commit is contained in:
39
app/Http/Livewire/Bindle/Gallery.php
Normal file
39
app/Http/Livewire/Bindle/Gallery.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Bindle;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Livewire\Component;
|
||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||
|
||||
class Gallery extends Component
|
||||
{
|
||||
public Collection $bindles;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->bindles = LibraryItem::query()
|
||||
->where('type', 'bindle')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function deleteBindle($id)
|
||||
{
|
||||
LibraryItem::query()->find($id)?->delete();
|
||||
|
||||
return to_route('bindles');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.bindle.gallery')
|
||||
->layout('layouts.app', [
|
||||
'SEOData' => new SEOData(
|
||||
title: __('Bindle Gallery'),
|
||||
description: __('Die berühmte Bindlesammlung von FiatTracker.'),
|
||||
image: asset('img/fiat_tracker.jpg'),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ use App\Enums\LibraryItemType;
|
||||
use App\Models\Country;
|
||||
use App\Models\Library;
|
||||
use App\Models\LibraryItem;
|
||||
use App\Models\Tag;
|
||||
use App\Traits\HasTagsTrait;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Component;
|
||||
@@ -33,7 +32,7 @@ class LibraryItemForm extends Component
|
||||
public ?string $fromUrl = '';
|
||||
|
||||
protected $queryString = [
|
||||
'fromUrl' => ['except' => ''],
|
||||
'fromUrl' => ['except' => ''],
|
||||
'lecturer' => ['except' => false],
|
||||
];
|
||||
|
||||
@@ -46,11 +45,11 @@ class LibraryItemForm extends Component
|
||||
|
||||
'selectedTags' => 'array|min:1',
|
||||
|
||||
'libraryItem.lecturer_id' => 'required',
|
||||
'libraryItem.name' => 'required',
|
||||
'libraryItem.type' => 'required',
|
||||
'libraryItem.language_code' => 'required',
|
||||
'libraryItem.value' => [
|
||||
'libraryItem.lecturer_id' => 'required',
|
||||
'libraryItem.name' => 'required',
|
||||
'libraryItem.type' => 'required',
|
||||
'libraryItem.language_code' => 'required',
|
||||
'libraryItem.value' => [
|
||||
'required',
|
||||
Rule::when(
|
||||
$this->libraryItem->type !== LibraryItemType::MarkdownArticle()
|
||||
@@ -58,11 +57,35 @@ class LibraryItemForm extends Component
|
||||
&& $this->libraryItem->type !== LibraryItemType::DownloadableFile(), ['url']
|
||||
),
|
||||
],
|
||||
'libraryItem.subtitle' => 'required',
|
||||
'libraryItem.excerpt' => 'required',
|
||||
'libraryItem.main_image_caption' => 'required',
|
||||
'libraryItem.read_time' => 'required',
|
||||
'libraryItem.approved' => 'boolean',
|
||||
'libraryItem.subtitle' => 'required',
|
||||
'libraryItem.excerpt' =>
|
||||
[
|
||||
Rule::when(
|
||||
$this->libraryItem->type !== 'bindle',
|
||||
'required',
|
||||
)
|
||||
],
|
||||
'libraryItem.main_image_caption' =>
|
||||
[
|
||||
Rule::when(
|
||||
$this->libraryItem->type !== 'bindle',
|
||||
'required',
|
||||
)
|
||||
],
|
||||
'libraryItem.read_time' =>
|
||||
[
|
||||
Rule::when(
|
||||
$this->libraryItem->type !== 'bindle',
|
||||
'required',
|
||||
)
|
||||
],
|
||||
'libraryItem.approved' =>
|
||||
[
|
||||
Rule::when(
|
||||
$this->libraryItem->type !== 'bindle',
|
||||
'required',
|
||||
)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -70,22 +93,22 @@ class LibraryItemForm extends Component
|
||||
{
|
||||
if (!$this->libraryItem) {
|
||||
$this->libraryItem = new LibraryItem([
|
||||
'approved' => true,
|
||||
'approved' => true,
|
||||
'read_time' => 1,
|
||||
'value' => '',
|
||||
'value' => '',
|
||||
]);
|
||||
if ($this->lecturer) {
|
||||
$this->library = Library::query()
|
||||
->firstWhere('name', '=', 'Dozentenmaterial')?->id;
|
||||
->firstWhere('name', '=', 'Dozentenmaterial')?->id;
|
||||
}
|
||||
} else {
|
||||
$this->selectedTags = $this->libraryItem->tags()
|
||||
->where('type', 'library_item')
|
||||
->get()
|
||||
->map(fn($tag) => $tag->name)
|
||||
->toArray();
|
||||
->where('type', 'library_item')
|
||||
->get()
|
||||
->map(fn($tag) => $tag->name)
|
||||
->toArray();
|
||||
$this->library = $this->libraryItem->libraries()
|
||||
->first()
|
||||
->first()
|
||||
->id;
|
||||
}
|
||||
if (!$this->fromUrl) {
|
||||
@@ -106,38 +129,55 @@ class LibraryItemForm extends Component
|
||||
|
||||
if ($this->image) {
|
||||
$this->libraryItem->addMedia($this->image)
|
||||
->usingFileName(md5($this->image->getClientOriginalName()).'.'.$this->image->getClientOriginalExtension())
|
||||
->toMediaCollection('main');
|
||||
->usingFileName(md5($this->image->getClientOriginalName()) . '.' . $this->image->getClientOriginalExtension())
|
||||
->toMediaCollection('main');
|
||||
}
|
||||
|
||||
if ($this->file) {
|
||||
$this->libraryItem->addMedia($this->file)
|
||||
->usingFileName(md5($this->file->getClientOriginalName()).'.'.$this->file->getClientOriginalExtension())
|
||||
->toMediaCollection('single_file');
|
||||
->usingFileName(md5($this->file->getClientOriginalName()) . '.' . $this->file->getClientOriginalExtension())
|
||||
->toMediaCollection('single_file');
|
||||
}
|
||||
|
||||
$this->libraryItem->libraries()
|
||||
->syncWithoutDetaching([(int) $this->library]);
|
||||
->syncWithoutDetaching([(int)$this->library]);
|
||||
|
||||
if ($this->libraryItem->type === 'bindle') {
|
||||
return to_route('bindles');
|
||||
}
|
||||
|
||||
return to_route('library.table.libraryItems', ['country' => $this->country]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$types = Options::forEnum(LibraryItemType::class)
|
||||
->filter(
|
||||
fn($type) => $type !== LibraryItemType::PodcastEpisode
|
||||
&& $type !== LibraryItemType::MarkdownArticle
|
||||
)
|
||||
->toArray();
|
||||
$libaries = Library::query()
|
||||
->when(auth()->id() !== config('portal.bonus.fiat-tracker-user-id'),
|
||||
fn($query) => $query->where('name', '!=', 'Bindle')
|
||||
)
|
||||
->get()
|
||||
->map(fn($library) => [
|
||||
'id' => $library->id,
|
||||
'name' => $library->name,
|
||||
])
|
||||
->toArray();
|
||||
|
||||
if (auth()->id() === config('portal.bonus.fiat-tracker-user-id')) {
|
||||
$types = collect($types)->prepend([
|
||||
'label' => 'Bindle',
|
||||
'value' => 'bindle',
|
||||
]);
|
||||
}
|
||||
|
||||
return view('livewire.library.form.library-item-form', [
|
||||
'types' => Options::forEnum(LibraryItemType::class)
|
||||
->filter(
|
||||
fn($type) => $type !== LibraryItemType::PodcastEpisode
|
||||
&& $type !== LibraryItemType::MarkdownArticle
|
||||
)
|
||||
->toArray(),
|
||||
'libraries' => Library::query()
|
||||
->get()
|
||||
->map(fn($library) => [
|
||||
'id' => $library->id,
|
||||
'name' => $library->name,
|
||||
])
|
||||
->toArray(),
|
||||
'types' => $types,
|
||||
'libraries' => $libaries,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ class LibraryTable extends Component
|
||||
|
||||
protected $queryString = [
|
||||
'currentTab' => ['except' => '*'],
|
||||
'filters' => ['except' => ''],
|
||||
'search' => ['except' => ''],
|
||||
'filters' => ['except' => ''],
|
||||
'search' => ['except' => ''],
|
||||
];
|
||||
|
||||
public function loadMore()
|
||||
@@ -56,10 +56,11 @@ class LibraryTable extends Component
|
||||
{
|
||||
$shouldBePublic = !$this->isLecturerPage;
|
||||
$libraries = \App\Models\Library::query()
|
||||
->whereNull('parent_id')
|
||||
->where('is_public', $shouldBePublic)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
->where('name', '!=', 'Bindle')
|
||||
->whereNull('parent_id')
|
||||
->where('is_public', $shouldBePublic)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
$tabs = collect([
|
||||
[
|
||||
'name' => '*',
|
||||
@@ -73,49 +74,50 @@ class LibraryTable extends Component
|
||||
|
||||
if ($this->currentTab !== '*') {
|
||||
$parentLibrary = Library::query()
|
||||
->where('name', $this->currentTab)
|
||||
->first();
|
||||
->where('name', $this->currentTab)
|
||||
->first();
|
||||
}
|
||||
$searchTags = [];
|
||||
if ($this->search) {
|
||||
$searchTags = Tag::where('name', 'ilike', '%'.$this->search.'%')
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
$searchTags = Tag::where('name', 'ilike', '%' . $this->search . '%')
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
return view('livewire.library.library-table', [
|
||||
'libraries' => $tabs,
|
||||
'libraries' => $tabs,
|
||||
'libraryItems' => LibraryItem::query()
|
||||
->with([
|
||||
'lecturer',
|
||||
'tags',
|
||||
])
|
||||
->when($this->search, fn($query) => $query
|
||||
->where('name', 'ilike', '%'.$this->search.'%')
|
||||
->orWhere(fn($query) => $query
|
||||
->when(count($searchTags) > 0 && count($this->filters) < 1,
|
||||
fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $searchTags)))
|
||||
)
|
||||
)
|
||||
->when($this->currentTab !== '*', fn($query) => $query
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query
|
||||
->where('libraries.name', $this->currentTab)
|
||||
)
|
||||
)
|
||||
->when(isset($this->filters['lecturer_id']),
|
||||
fn($query) => $query->where('library_items.lecturer_id',
|
||||
$this->filters['lecturer_id'])
|
||||
)
|
||||
->when(isset($this->filters['tag']), fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $this->filters['tag'])))
|
||||
->when(isset($this->filters['language']),
|
||||
fn($query) => $query->whereIn('language_code', $this->filters['language']))
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query->where('libraries.is_public', $shouldBePublic))
|
||||
->orderByDesc('library_items.created_at')
|
||||
->paginate($this->perPage),
|
||||
->with([
|
||||
'lecturer',
|
||||
'tags',
|
||||
])
|
||||
->where('type', '!=', 'bindle')
|
||||
->when($this->search, fn($query) => $query
|
||||
->where('name', 'ilike', '%' . $this->search . '%')
|
||||
->orWhere(fn($query) => $query
|
||||
->when(count($searchTags) > 0 && count($this->filters) < 1,
|
||||
fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $searchTags)))
|
||||
)
|
||||
)
|
||||
->when($this->currentTab !== '*', fn($query) => $query
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query
|
||||
->where('libraries.name', $this->currentTab)
|
||||
)
|
||||
)
|
||||
->when(isset($this->filters['lecturer_id']),
|
||||
fn($query) => $query->where('library_items.lecturer_id',
|
||||
$this->filters['lecturer_id'])
|
||||
)
|
||||
->when(isset($this->filters['tag']), fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $this->filters['tag'])))
|
||||
->when(isset($this->filters['language']),
|
||||
fn($query) => $query->whereIn('language_code', $this->filters['language']))
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query->where('libraries.is_public', $shouldBePublic))
|
||||
->orderByDesc('library_items.created_at')
|
||||
->paginate($this->perPage),
|
||||
])->layout('layouts.app', [
|
||||
'SEOData' => new SEOData(
|
||||
title: __('Library'),
|
||||
|
||||
Reference in New Issue
Block a user