- Regel je Angebot auf Abruf: alle Mitglieder, nur freigeschaltete Konten, wer einen Artikel besitzt - Freigaben je Angebot und Konto (offer_releases), nie geloescht, nur entzogen; Pflege im Angebot - Pruefung serverseitig in GrantIssuer::claim; Angebote bei Registrierung bleiben regelfrei - Mitgliederseite Angebote: Neu fuer dich (neue Staende besessener Artikel), Zum Uebernehmen, Shop - Migration 2026_12_01_110000, ADR-56, DEPLOYMENT.md Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
63 lines
2.4 KiB
PHP
63 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Entitlement;
|
|
|
|
use App\Domain\Catalog\ArticleRelease;
|
|
use App\Domain\Commerce\ProductOptions;
|
|
use App\Models\User;
|
|
use Carbon\CarbonInterface;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* Neue Stände zu Artikeln, die das Konto bereits besitzt („Neu für dich“, ADR-56).
|
|
*
|
|
* Nach der Updatepolitik (ADR-09, OPEN-01) stehen alle später veröffentlichten Stände desselben Artikels dem Inhaber
|
|
* ohne Aufpreis zu, solange die Lizenz gilt. Sie erscheinen von selbst in der Bibliothek; diese Liste macht sie nur
|
|
* sichtbar. Es wird nichts vergeben und nichts übernommen.
|
|
*/
|
|
class NewStands
|
|
{
|
|
/** So lange (in Tagen) nach der Veröffentlichung erscheint ein neuer Stand in der Liste. */
|
|
public const DAYS = 90;
|
|
|
|
/**
|
|
* @return Collection<int, array{grant: Grant, title: string, number: int, since: CarbonInterface}>
|
|
*/
|
|
public function forUser(User $user): Collection
|
|
{
|
|
if ($user->party_id === null) {
|
|
return collect();
|
|
}
|
|
|
|
$limit = now()->subDays(self::DAYS);
|
|
$titles = app(ProductOptions::class);
|
|
|
|
return Grant::query()
|
|
->with(['article.currentRelease', 'releaseAtGrant'])
|
|
->where('status', GrantStatus::Aktiv)
|
|
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', now()))
|
|
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
|
->whereHas('article', fn ($query) => $query->whereNull('archived_at'))
|
|
->orderByDesc('id')
|
|
->get()
|
|
->filter(function (Grant $grant) use ($limit): bool {
|
|
$current = $grant->article?->currentRelease;
|
|
$had = $grant->releaseAtGrant;
|
|
|
|
return $current instanceof ArticleRelease
|
|
&& $had instanceof ArticleRelease
|
|
&& (int) $current->number > (int) $had->number
|
|
&& $current->created_at !== null
|
|
&& $current->created_at->greaterThanOrEqualTo($limit);
|
|
})
|
|
->unique('license_article_id')
|
|
->map(fn (Grant $grant): array => [
|
|
'grant' => $grant,
|
|
'title' => $titles->articleTitle($grant->article),
|
|
'number' => (int) $grant->article->currentRelease->number,
|
|
'since' => $grant->article->currentRelease->created_at,
|
|
])
|
|
->values();
|
|
}
|
|
}
|