Changeset View
Changeset View
Standalone View
Standalone View
src/app/Group.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
/** | /** | ||||
* The eloquent definition of a Group. | * The eloquent definition of a Group. | ||||
* | * | ||||
* @property int $id The group identifier | * @property int $id The group identifier | ||||
* @property string $email An email address | * @property string $email An email address | ||||
* @property string $members A comma-separated list of email addresses | * @property string $members A comma-separated list of email addresses | ||||
* @property int $status The group status | * @property int $status The group status | ||||
* @property int $tenant_id Tenant identifier | |||||
*/ | */ | ||||
class Group extends Model | class Group extends Model | ||||
{ | { | ||||
use SoftDeletes; | use SoftDeletes; | ||||
// we've simply never heard of this domain | // we've simply never heard of this domain | ||||
public const STATUS_NEW = 1 << 0; | public const STATUS_NEW = 1 << 0; | ||||
// it's been activated | // it's been activated | ||||
Show All 35 Lines | public function assignToWallet(Wallet $wallet): Group | ||||
$sku = \App\Sku::where('title', 'group')->first(); | $sku = \App\Sku::where('title', 'group')->first(); | ||||
$exists = $wallet->entitlements()->where('sku_id', $sku->id)->count(); | $exists = $wallet->entitlements()->where('sku_id', $sku->id)->count(); | ||||
\App\Entitlement::create([ | \App\Entitlement::create([ | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => $exists >= $sku->units_free ? $sku->cost : 0, | 'cost' => $exists >= $sku->units_free ? $sku->cost : 0, | ||||
'fee' => $exists >= $sku->units_free ? $sku->fee : 0, | |||||
'entitleable_id' => $this->id, | 'entitleable_id' => $this->id, | ||||
'entitleable_type' => Group::class | 'entitleable_type' => Group::class | ||||
]); | ]); | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | public function suspend(): void | ||||
return; | return; | ||||
} | } | ||||
$this->status |= Group::STATUS_SUSPENDED; | $this->status |= Group::STATUS_SUSPENDED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* The tenant for this group. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function tenant() | |||||
{ | |||||
return $this->belongsTo('App\Tenant', 'tenant_id', 'id'); | |||||
} | |||||
/** | |||||
* Unsuspend this group. | * Unsuspend this group. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function unsuspend(): void | public function unsuspend(): void | ||||
{ | { | ||||
if (!$this->isSuspended()) { | if (!$this->isSuspended()) { | ||||
return; | return; | ||||
Show All 19 Lines |