Changeset View
Changeset View
Standalone View
Standalone View
src/app/Entitlement.php
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | public function entitleableTitle(): ?string | ||||
if ($this->entitleable instanceof \App\Domain) { | if ($this->entitleable instanceof \App\Domain) { | ||||
return $this->entitleable->namespace; | return $this->entitleable->namespace; | ||||
} | } | ||||
return $this->entitleable->email; | return $this->entitleable->email; | ||||
} | } | ||||
/** | /** | ||||
* Simplified Entitlement/SKU information for a specified entitleable object | |||||
* | |||||
* @param object $object Entitleable object | |||||
* | |||||
* @return array Skus list with some metadata | |||||
*/ | |||||
public static function objectEntitlementsSummary($object): array | |||||
{ | |||||
$skus = []; | |||||
// TODO: I agree this format may need to be extended in future | |||||
foreach ($object->entitlements as $ent) { | |||||
$sku = $ent->sku; | |||||
if (!isset($skus[$sku->id])) { | |||||
$skus[$sku->id] = ['costs' => [], 'count' => 0]; | |||||
} | |||||
$skus[$sku->id]['count']++; | |||||
$skus[$sku->id]['costs'][] = $ent->cost; | |||||
} | |||||
return $skus; | |||||
} | |||||
/** | |||||
* The SKU concerned. | * The SKU concerned. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
*/ | */ | ||||
public function sku() | public function sku() | ||||
{ | { | ||||
return $this->belongsTo('App\Sku'); | return $this->belongsTo('App\Sku'); | ||||
} | } | ||||
Show All 19 Lines |