diff --git a/app/Livewire/Concerns/ProvidesPressReleasePresubmitChecks.php b/app/Livewire/Concerns/ProvidesPressReleasePresubmitChecks.php new file mode 100644 index 00000000..c56b47df --- /dev/null +++ b/app/Livewire/Concerns/ProvidesPressReleasePresubmitChecks.php @@ -0,0 +1,72 @@ + + */ + #[Computed] + public function presubmitChecks(): array + { + $titleLen = mb_strlen(trim($this->title)); + $textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text); + $tagsCount = count($this->tagsArray()); + + return [ + [ + 'key' => 'title', + 'status' => $titleLen >= 5 ? 'ok' : 'err', + 'label' => __('Titel vorhanden'), + 'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'), + ], + [ + 'key' => 'text', + 'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'), + 'label' => __('Mindestlänge Fließtext erreicht'), + 'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]), + ], + [ + 'key' => 'company', + 'status' => $this->companyId ? 'ok' : 'err', + 'label' => __('Firma zugeordnet'), + 'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'), + ], + [ + 'key' => 'category', + 'status' => $this->categoryId ? 'ok' : 'err', + 'label' => __('Kategorie gewählt'), + 'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'), + ], + [ + 'key' => 'contact', + 'status' => $this->contactId ? 'ok' : 'warn', + 'label' => __('Pressekontakt zugeordnet'), + 'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'), + ], + [ + 'key' => 'tags', + 'status' => $tagsCount >= 1 ? 'ok' : 'warn', + 'label' => __('Themen-Tags vergeben'), + 'sub' => $tagsCount >= 1 + ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) + : __('empfohlen für SEO & Auffindbarkeit'), + ], + ]; + } +} diff --git a/resources/views/livewire/admin/press-releases/create.blade.php b/resources/views/livewire/admin/press-releases/create.blade.php index 3ac4c587..e40da60b 100644 --- a/resources/views/livewire/admin/press-releases/create.blade.php +++ b/resources/views/livewire/admin/press-releases/create.blade.php @@ -22,6 +22,7 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling; use \App\Livewire\Concerns\InteractsWithPressReleaseTags; use \App\Livewire\Concerns\ProvidesPressReleaseFormRules; + use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks; public string $portal = 'presseecho'; @@ -183,7 +184,7 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex ->limit(50) ->get(['id', 'name']); - $selectedCompany = $this->companyId ? Company::withoutGlobalScopes()->find((int) $this->companyId) : null; + $selectedCompany = $this->selectedCompany(); return [ 'companies' => $companies, @@ -201,51 +202,11 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex return $this->tagsArray(); } - #[Computed] - public function presubmitChecks(): array + private function selectedCompany(): ?Company { - $titleLen = mb_strlen(trim($this->title)); - $textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text); - $tagsCount = count($this->tagsArray()); - - return [ - [ - 'key' => 'title', - 'status' => $titleLen >= 5 ? 'ok' : 'err', - 'label' => __('Titel vorhanden'), - 'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'), - ], - [ - 'key' => 'text', - 'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'), - 'label' => __('Mindestlänge Fließtext erreicht'), - 'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]), - ], - [ - 'key' => 'company', - 'status' => $this->companyId ? 'ok' : 'err', - 'label' => __('Firma zugeordnet'), - 'sub' => $this->companyId ? '' : __('Keine Firma gewählt'), - ], - [ - 'key' => 'category', - 'status' => $this->categoryId ? 'ok' : 'err', - 'label' => __('Kategorie gewählt'), - 'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'), - ], - [ - 'key' => 'contact', - 'status' => $this->contactId ? 'ok' : 'warn', - 'label' => __('Pressekontakt zugeordnet'), - 'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'), - ], - [ - 'key' => 'tags', - 'status' => $tagsCount >= 1 ? 'ok' : 'warn', - 'label' => __('Themen-Tags vergeben'), - 'sub' => $tagsCount >= 1 ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) : __('empfohlen für SEO & Auffindbarkeit'), - ], - ]; + return $this->companyId + ? Company::withoutGlobalScopes()->find((int) $this->companyId) + : null; } private function defaultContactIdFor(int $companyId): ?int diff --git a/resources/views/livewire/admin/press-releases/edit.blade.php b/resources/views/livewire/admin/press-releases/edit.blade.php index 7b1c889c..e6864b01 100644 --- a/resources/views/livewire/admin/press-releases/edit.blade.php +++ b/resources/views/livewire/admin/press-releases/edit.blade.php @@ -27,6 +27,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling; use \App\Livewire\Concerns\InteractsWithPressReleaseTags; use \App\Livewire\Concerns\ProvidesPressReleaseFormRules; + use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks; #[Locked] public int $id; @@ -369,7 +370,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl $statusEnum = PressReleaseStatus::tryFrom($this->currentStatus); - $selectedCompany = $this->companyId ? Company::withoutGlobalScopes()->find((int) $this->companyId) : null; + $selectedCompany = $this->selectedCompany(); return [ 'companies' => $companies, @@ -390,51 +391,11 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl return $this->tagsArray(); } - #[Computed] - public function presubmitChecks(): array + private function selectedCompany(): ?Company { - $titleLen = mb_strlen(trim($this->title)); - $textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text); - $tagsCount = count($this->tagsArray()); - - return [ - [ - 'key' => 'title', - 'status' => $titleLen >= 5 ? 'ok' : 'err', - 'label' => __('Titel vorhanden'), - 'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'), - ], - [ - 'key' => 'text', - 'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'), - 'label' => __('Mindestlänge Fließtext erreicht'), - 'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]), - ], - [ - 'key' => 'company', - 'status' => $this->companyId ? 'ok' : 'err', - 'label' => __('Firma zugeordnet'), - 'sub' => $this->companyId ? '' : __('Keine Firma gewählt'), - ], - [ - 'key' => 'category', - 'status' => $this->categoryId ? 'ok' : 'err', - 'label' => __('Kategorie gewählt'), - 'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'), - ], - [ - 'key' => 'contact', - 'status' => $this->contactId ? 'ok' : 'warn', - 'label' => __('Pressekontakt zugeordnet'), - 'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'), - ], - [ - 'key' => 'tags', - 'status' => $tagsCount >= 1 ? 'ok' : 'warn', - 'label' => __('Themen-Tags vergeben'), - 'sub' => $tagsCount >= 1 ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) : __('empfohlen für SEO & Auffindbarkeit'), - ], - ]; + return $this->companyId + ? Company::withoutGlobalScopes()->find((int) $this->companyId) + : null; } private function defaultContactIdFor(int $companyId): ?int diff --git a/resources/views/livewire/customer/press-releases/create.blade.php b/resources/views/livewire/customer/press-releases/create.blade.php index 87565500..44ba12ef 100644 --- a/resources/views/livewire/customer/press-releases/create.blade.php +++ b/resources/views/livewire/customer/press-releases/create.blade.php @@ -28,6 +28,7 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling; use \App\Livewire\Concerns\InteractsWithPressReleaseTags; use \App\Livewire\Concerns\ProvidesPressReleaseFormRules; + use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks; public string $portal = 'presseecho'; @@ -414,58 +415,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex return $this->tagsArray(); } - #[Computed] - public function presubmitChecks(): array - { - $titleLen = mb_strlen(trim($this->title)); - $textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text); - $tagsCount = count($this->tagsArray()); - - return [ - [ - 'key' => 'title', - 'status' => $titleLen >= 5 ? 'ok' : 'err', - 'label' => __('Titel vorhanden'), - 'sub' => $titleLen > 0 - ? trans_choice('{0}Noch leer|{1}:n Zeichen|[2,*]:n Zeichen', $titleLen, ['n' => $titleLen]) - : __('Noch leer'), - ], - [ - 'key' => 'text', - 'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'), - 'label' => __('Mindestlänge Fließtext erreicht'), - 'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]), - ], - [ - 'key' => 'company', - 'status' => $this->companyId ? 'ok' : 'err', - 'label' => __('Firma zugeordnet'), - 'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'), - ], - [ - 'key' => 'category', - 'status' => $this->categoryId ? 'ok' : 'err', - 'label' => __('Kategorie gewählt'), - 'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'), - ], - [ - 'key' => 'contact', - 'status' => $this->contactId ? 'ok' : 'warn', - 'label' => __('Pressekontakt zugeordnet'), - 'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'), - ], - [ - 'key' => 'tags', - 'status' => $tagsCount >= 1 ? 'ok' : 'warn', - 'label' => __('Themen-Tags vergeben'), - 'sub' => $tagsCount >= 1 - ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) - : __('empfohlen für SEO & Auffindbarkeit'), - ], - ]; - } - - private function defaultContactIdFor(int $companyId): ?int { return $this->companyContacts($companyId)->first()?->id; diff --git a/resources/views/livewire/customer/press-releases/edit.blade.php b/resources/views/livewire/customer/press-releases/edit.blade.php index 0679cb73..f7d85b59 100644 --- a/resources/views/livewire/customer/press-releases/edit.blade.php +++ b/resources/views/livewire/customer/press-releases/edit.blade.php @@ -28,6 +28,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling; use \App\Livewire\Concerns\InteractsWithPressReleaseTags; use \App\Livewire\Concerns\ProvidesPressReleaseFormRules; + use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks; #[Locked] public int $id; @@ -397,56 +398,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl return $this->tagsArray(); } - #[Computed] - public function presubmitChecks(): array - { - $titleLen = mb_strlen(trim($this->title)); - $textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text); - $tagsCount = count($this->tagsArray()); - - return [ - [ - 'key' => 'title', - 'status' => $titleLen >= 5 ? 'ok' : 'err', - 'label' => __('Titel vorhanden'), - 'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'), - ], - [ - 'key' => 'text', - 'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'), - 'label' => __('Mindestlänge Fließtext erreicht'), - 'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]), - ], - [ - 'key' => 'company', - 'status' => $this->companyId ? 'ok' : 'err', - 'label' => __('Firma zugeordnet'), - 'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'), - ], - [ - 'key' => 'category', - 'status' => $this->categoryId ? 'ok' : 'err', - 'label' => __('Kategorie gewählt'), - 'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'), - ], - [ - 'key' => 'contact', - 'status' => $this->contactId ? 'ok' : 'warn', - 'label' => __('Pressekontakt zugeordnet'), - 'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'), - ], - [ - 'key' => 'tags', - 'status' => $tagsCount >= 1 ? 'ok' : 'warn', - 'label' => __('Themen-Tags vergeben'), - 'sub' => $tagsCount >= 1 - ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) - : __('empfohlen für SEO & Auffindbarkeit'), - ], - ]; - } - - private function defaultContactIdFor(int $companyId): ?int { return $this->companyContacts($companyId)->first()?->id;