mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
libraryItem forms added
This commit is contained in:
@@ -17,6 +17,7 @@ enum LibraryItemType: string
|
||||
case Book = 'book';
|
||||
case BlogArticle = 'blog_article';
|
||||
case MarkdownArticle = 'markdown_article';
|
||||
case MarkdownArticleExtern = 'markdown_article_extern';
|
||||
case YoutubeVideo = 'youtube_video';
|
||||
case VimeoVideo = 'vimeo_video';
|
||||
case PodcastEpisode = 'podcast_episode';
|
||||
@@ -25,26 +26,28 @@ enum LibraryItemType: string
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'book' => __('Book'),
|
||||
'blog_article' => __('Article'),
|
||||
'markdown_article' => __('Markdown Article'),
|
||||
'youtube_video' => __('Youtube Video'),
|
||||
'vimeo_video' => __('Vimeo Video'),
|
||||
'podcast_episode' => __('Podcast Episode'),
|
||||
'downloadable_file' => __('Downloadable File'),
|
||||
'book' => __('Book'),
|
||||
'blog_article' => __('Article'),
|
||||
'markdown_article' => __('Markdown Article'),
|
||||
'markdown_article_extern' => __('Markdown Article Extern'),
|
||||
'youtube_video' => __('Youtube Video'),
|
||||
'vimeo_video' => __('Vimeo Video'),
|
||||
'podcast_episode' => __('Podcast Episode'),
|
||||
'downloadable_file' => __('Downloadable File'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function icons(): array
|
||||
{
|
||||
return [
|
||||
'book' => 'book',
|
||||
'blog_article' => 'newspaper',
|
||||
'markdown_article' => 'newspaper',
|
||||
'youtube_video' => 'video',
|
||||
'vimeo_video' => 'video',
|
||||
'podcast_episode' => 'podcast',
|
||||
'downloadable_file' => 'download',
|
||||
'book' => 'book',
|
||||
'blog_article' => 'newspaper',
|
||||
'markdown_article' => 'newspaper',
|
||||
'markdown_article_extern' => 'newspaper',
|
||||
'youtube_video' => 'video',
|
||||
'vimeo_video' => 'video',
|
||||
'podcast_episode' => 'podcast',
|
||||
'downloadable_file' => 'download',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ class CityForm extends Component
|
||||
if (!$this->city) {
|
||||
$this->city = new City();
|
||||
}
|
||||
if (!$this->fromUrl) {
|
||||
$this->fromUrl = url()->previous();
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
@@ -39,7 +42,7 @@ class CityForm extends Component
|
||||
$this->validate();
|
||||
$this->city->save();
|
||||
|
||||
return redirect($this->fromUrl);
|
||||
return redirect($this->fromUrl ?? url()->route('welcome'));
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
69
app/Http/Livewire/ContentCreator/Form/ContentCreatorForm.php
Normal file
69
app/Http/Livewire/ContentCreator/Form/ContentCreatorForm.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\ContentCreator\Form;
|
||||
|
||||
use App\Models\Lecturer;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class ContentCreatorForm extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public ?Lecturer $lecturer = null;
|
||||
public $image;
|
||||
|
||||
public ?string $fromUrl = '';
|
||||
|
||||
protected $queryString = ['fromUrl' => ['except' => '']];
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'image' => [Rule::requiredIf(!$this->lecturer->id), 'nullable', 'mimes:jpeg,png,jpg,gif', 'max:10240'],
|
||||
|
||||
'lecturer.name' => 'required',
|
||||
'lecturer.active' => 'boolean',
|
||||
'lecturer.subtitle' => 'required',
|
||||
'lecturer.intro' => 'required',
|
||||
'lecturer.twitter_username' => 'nullable|string',
|
||||
'lecturer.website' => 'nullable|url',
|
||||
'lecturer.lightning_address' => 'nullable|string',
|
||||
'lecturer.lnurl' => 'nullable|string',
|
||||
'lecturer.node_id' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if (!$this->lecturer) {
|
||||
$this->lecturer = new Lecturer([
|
||||
'intro' => '',
|
||||
'active' => true,
|
||||
'team_id' => true,
|
||||
]);
|
||||
}
|
||||
if (!$this->fromUrl) {
|
||||
$this->fromUrl = url()->previous();
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
$this->lecturer->save();
|
||||
|
||||
if ($this->image) {
|
||||
$this->lecturer->addMedia($this->image)
|
||||
->toMediaCollection('avatar');
|
||||
}
|
||||
|
||||
return redirect($this->fromUrl ?? url()->route('welcome'));
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.content-creator.form.content-creator-form');
|
||||
}
|
||||
}
|
||||
122
app/Http/Livewire/Library/Form/LibraryItemForm.php
Normal file
122
app/Http/Livewire/Library/Form/LibraryItemForm.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Library\Form;
|
||||
|
||||
use App\Enums\LibraryItemType;
|
||||
use App\Models\Country;
|
||||
use App\Models\Library;
|
||||
use App\Models\LibraryItem;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Spatie\LaravelOptions\Options;
|
||||
|
||||
class LibraryItemForm extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Country $country;
|
||||
|
||||
public ?LibraryItem $libraryItem = null;
|
||||
public $library;
|
||||
public $image;
|
||||
public $file;
|
||||
|
||||
public bool $lecturer = false;
|
||||
public ?string $fromUrl = '';
|
||||
|
||||
protected $queryString = [
|
||||
'fromUrl' => ['except' => ''],
|
||||
'lecturer' => ['except' => false],
|
||||
];
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'image' => [Rule::requiredIf(!$this->libraryItem->id), 'nullable', 'mimes:jpeg,png,jpg,gif', 'max:10240'],
|
||||
|
||||
'library' => 'required',
|
||||
|
||||
'libraryItem.lecturer_id' => 'required',
|
||||
'libraryItem.name' => 'required',
|
||||
'libraryItem.type' => 'required',
|
||||
'libraryItem.language_code' => 'required',
|
||||
'libraryItem.value' => [
|
||||
'required',
|
||||
Rule::when(
|
||||
$this->libraryItem->type !== LibraryItemType::MarkdownArticle
|
||||
&& $this->libraryItem->type !== LibraryItemType::MarkdownArticleExtern
|
||||
&& $this->libraryItem->type !== LibraryItemType::DownloadableFile, ['url']
|
||||
)
|
||||
],
|
||||
'libraryItem.subtitle' => 'required',
|
||||
'libraryItem.excerpt' => 'required',
|
||||
'libraryItem.main_image_caption' => 'required',
|
||||
'libraryItem.read_time' => 'required',
|
||||
'libraryItem.approved' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if (!$this->libraryItem) {
|
||||
$this->libraryItem = new LibraryItem([
|
||||
'approved' => true,
|
||||
'read_time' => 1,
|
||||
]);
|
||||
if ($this->lecturer) {
|
||||
$this->library = Library::query()
|
||||
->firstWhere('name', '=', 'Dozentenmaterial')?->id;
|
||||
}
|
||||
} else {
|
||||
$this->library = $this->libraryItem->libraries()
|
||||
->first()
|
||||
->id;
|
||||
}
|
||||
if (!$this->fromUrl) {
|
||||
$this->fromUrl = url()->previous();
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
$this->libraryItem->save();
|
||||
$this->libraryItem->setStatus('published');
|
||||
|
||||
if ($this->image) {
|
||||
$this->libraryItem->addMedia($this->image)
|
||||
->toMediaCollection('main');
|
||||
}
|
||||
|
||||
if ($this->file) {
|
||||
$this->libraryItem->addMedia($this->file)
|
||||
->toMediaCollection('single_file');
|
||||
}
|
||||
|
||||
$this->libraryItem->libraries()
|
||||
->syncWithoutDetaching([(int) $this->library]);
|
||||
|
||||
return to_route('library.table.libraryItems', ['country' => $this->country]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
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()
|
||||
->where('is_public', true)
|
||||
->get()
|
||||
->map(fn($library) => [
|
||||
'id' => $library->id,
|
||||
'name' => $library->name,
|
||||
])
|
||||
->toArray(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user