presseportale/app/Livewire/Concerns/InteractsWithPressReleaseContacts.php
Kevin Adametz 64b16cd93e 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>
2026-06-19 08:59:38 +00:00

47 lines
1.2 KiB
PHP

<?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;
}
}