Optimierung 2.5: Kontakt-Helfer + tagSuggestionsFor zentralisiert
Erkenntnis: Die Admin-Inline-Query (Contact::withoutGlobalScopes()->where ->orderBy) ist exakt der Contact::forCompany()-Scope -> alle vier Kontakt-Helfer waren funktional identisch. companyContacts/companyContact/ defaultContactIdFor in neuen Concern InteractsWithPressReleaseContacts (ueber forCompany) ausgelagert. tagSuggestionsFor() (4x identisch) in InteractsWithPressReleaseTags verschoben. Ungenutzte Collection-Importe in den Customer-Editoren entfernt; selectedCompany() bleibt je Kontext (Admin: withoutGlobalScopes find; Customer: CustomerCompanyContext). Tests: volle Suite gruen (794 passed, 1 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5ed60c171c
commit
64b16cd93e
6 changed files with 80 additions and 178 deletions
47
app/Livewire/Concerns/InteractsWithPressReleaseContacts.php
Normal file
47
app/Livewire/Concerns/InteractsWithPressReleaseContacts.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Concerns;
|
||||
|
||||
use App\Models\Contact;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Pressekontakt-Helfer der PM-Editoren (Admin + Customer).
|
||||
*
|
||||
* Alle vier Editoren lesen die Kontakte einer Firma identisch über den
|
||||
* `Contact::forCompany()`-Scope (ohne globale Scopes, sortiert nach Name).
|
||||
* Single Source of Truth für die Kontaktauflösung im Editor.
|
||||
*/
|
||||
trait InteractsWithPressReleaseContacts
|
||||
{
|
||||
/**
|
||||
* @return Collection<int, Contact>
|
||||
*/
|
||||
private function companyContacts(int $companyId): Collection
|
||||
{
|
||||
if ($companyId <= 0) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
return Contact::forCompany($companyId)
|
||||
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
|
||||
}
|
||||
|
||||
private function companyContact(int $contactId, int $companyId): ?Contact
|
||||
{
|
||||
if ($contactId <= 0 || $companyId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Contact::forCompany($companyId)->whereKey($contactId)->first();
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
if ($companyId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Livewire\Concerns;
|
||||
|
||||
use App\Models\Company;
|
||||
|
||||
/**
|
||||
* Themen-Tag-Verwaltung für die PM-Editoren (Erstellen/Bearbeiten).
|
||||
*
|
||||
|
|
@ -65,4 +67,31 @@ trait InteractsWithPressReleaseTags
|
|||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag-Vorschläge: Portal-Label und Länderbezug der Firma plus generische
|
||||
* Defaults. Identisch in allen vier PM-Editoren.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function tagSuggestionsFor(?Company $company): array
|
||||
{
|
||||
$defaults = [
|
||||
__('Mittelstand'),
|
||||
__('Unternehmen'),
|
||||
__('Eröffnung'),
|
||||
__('Innovation'),
|
||||
__('Nachhaltigkeit'),
|
||||
];
|
||||
|
||||
if (! $company) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter([
|
||||
$company->portal?->label(),
|
||||
$company->country_code === 'DE' ? __('Deutschland') : null,
|
||||
...$defaults,
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use Livewire\Attributes\Title;
|
|||
use Livewire\Volt\Component;
|
||||
|
||||
new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class extends Component {
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
|
|
@ -209,50 +210,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
: null;
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
if ($companyId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Contact>
|
||||
*/
|
||||
private function companyContacts(int $companyId): Collection
|
||||
{
|
||||
return Contact::withoutGlobalScopes()
|
||||
->where('company_id', $companyId)
|
||||
->orderBy('last_name')
|
||||
->orderBy('first_name')
|
||||
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
|
||||
}
|
||||
|
||||
private function companyContact(int $contactId, int $companyId): ?Contact
|
||||
{
|
||||
if ($contactId <= 0 || $companyId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Contact::withoutGlobalScopes()->where('company_id', $companyId)->whereKey($contactId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function tagSuggestionsFor(?Company $company): array
|
||||
{
|
||||
$defaults = [__('Mittelstand'), __('Unternehmen'), __('Eröffnung'), __('Innovation'), __('Nachhaltigkeit')];
|
||||
|
||||
if (!$company) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter([$company->portal?->label(), $company->country_code === 'DE' ? __('Deutschland') : null, ...$defaults])));
|
||||
}
|
||||
|
||||
private function categoryOptions(): Collection
|
||||
{
|
||||
return app(AdminPerformanceCache::class)->remember(AdminPerformanceCache::ActiveCategoryOptions, AdminPerformanceCache::OptionsTtl, fn() => Category::query()->with('translations')->where('is_active', true)->orderBy('id')->get());
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use Livewire\Attributes\Title;
|
|||
use Livewire\Volt\Component;
|
||||
|
||||
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component {
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
|
|
@ -398,50 +399,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
: null;
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
if ($companyId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Contact>
|
||||
*/
|
||||
private function companyContacts(int $companyId): Collection
|
||||
{
|
||||
return Contact::withoutGlobalScopes()
|
||||
->where('company_id', $companyId)
|
||||
->orderBy('last_name')
|
||||
->orderBy('first_name')
|
||||
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
|
||||
}
|
||||
|
||||
private function companyContact(int $contactId, int $companyId): ?Contact
|
||||
{
|
||||
if ($contactId <= 0 || $companyId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Contact::withoutGlobalScopes()->where('company_id', $companyId)->whereKey($contactId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function tagSuggestionsFor(?Company $company): array
|
||||
{
|
||||
$defaults = [__('Mittelstand'), __('Unternehmen'), __('Eröffnung'), __('Innovation'), __('Nachhaltigkeit')];
|
||||
|
||||
if (!$company) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter([$company->portal?->label(), $company->country_code === 'DE' ? __('Deutschland') : null, ...$defaults])));
|
||||
}
|
||||
|
||||
private function categoryOptions(): Collection
|
||||
{
|
||||
return app(AdminPerformanceCache::class)->remember(AdminPerformanceCache::ActiveCategoryOptions, AdminPerformanceCache::OptionsTtl, fn() => Category::query()->with('translations')->where('is_active', true)->orderBy('id')->get());
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use App\Services\PressRelease\PressReleaseHtmlSanitizer;
|
|||
use App\Services\PressRelease\PressReleaseService;
|
||||
use App\Services\PressRelease\QuotaExceededException;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Computed;
|
||||
|
|
@ -25,6 +24,7 @@ use Livewire\Volt\Component;
|
|||
|
||||
new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class extends Component
|
||||
{
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
|
|
@ -415,25 +415,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
return $this->tagsArray();
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Contact>
|
||||
*/
|
||||
private function companyContacts(int $companyId): Collection
|
||||
{
|
||||
return Contact::forCompany($companyId)
|
||||
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
|
||||
}
|
||||
|
||||
private function companyContact(int $contactId, int $companyId): ?Contact
|
||||
{
|
||||
return Contact::forCompany($companyId)->whereKey($contactId)->first();
|
||||
}
|
||||
|
||||
private function selectedCompany(): ?Company
|
||||
{
|
||||
if (! $this->companyId) {
|
||||
|
|
@ -444,31 +425,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
->findFor(auth()->user(), (int) $this->companyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function tagSuggestionsFor(?Company $company): array
|
||||
{
|
||||
$defaults = [
|
||||
__('Mittelstand'),
|
||||
__('Unternehmen'),
|
||||
__('Eröffnung'),
|
||||
__('Innovation'),
|
||||
__('Nachhaltigkeit'),
|
||||
];
|
||||
|
||||
if (! $company) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
$portalLabel = $company->portal?->label();
|
||||
|
||||
return array_values(array_unique(array_filter([
|
||||
$portalLabel,
|
||||
$company->country_code === 'DE' ? __('Deutschland') : null,
|
||||
...$defaults,
|
||||
])));
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div class="space-y-8 pr-editor-shell" x-data="{ tagInput: '' }">
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use App\Services\PressRelease\PressReleaseHtmlSanitizer;
|
|||
use App\Services\PressRelease\PressReleaseService;
|
||||
use App\Services\PressRelease\QuotaExceededException;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Locked;
|
||||
|
|
@ -25,6 +24,7 @@ use Livewire\Volt\Component;
|
|||
|
||||
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component
|
||||
{
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
|
|
@ -398,25 +398,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
return $this->tagsArray();
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Contact>
|
||||
*/
|
||||
private function companyContacts(int $companyId): Collection
|
||||
{
|
||||
return Contact::forCompany($companyId)
|
||||
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
|
||||
}
|
||||
|
||||
private function companyContact(int $contactId, int $companyId): ?Contact
|
||||
{
|
||||
return Contact::forCompany($companyId)->whereKey($contactId)->first();
|
||||
}
|
||||
|
||||
private function getMyPR(): PressRelease
|
||||
{
|
||||
// Pro Livewire-Request memoisiert: mount(), with() und save() greifen
|
||||
|
|
@ -435,31 +416,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
->findFor(auth()->user(), (int) $this->companyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function tagSuggestionsFor(?Company $company): array
|
||||
{
|
||||
$defaults = [
|
||||
__('Mittelstand'),
|
||||
__('Unternehmen'),
|
||||
__('Eröffnung'),
|
||||
__('Innovation'),
|
||||
__('Nachhaltigkeit'),
|
||||
];
|
||||
|
||||
if (! $company) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
$portalLabel = $company->portal?->label();
|
||||
|
||||
return array_values(array_unique(array_filter([
|
||||
$portalLabel,
|
||||
$company->country_code === 'DE' ? __('Deutschland') : null,
|
||||
...$defaults,
|
||||
])));
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div class="space-y-8 pr-editor-shell" x-data="{ tagInput: '' }">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue