Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.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 Domain. | * The eloquent definition of a Domain. | ||||
* | * | ||||
* @property string $namespace | * @property string $namespace | ||||
* @property int $status | |||||
* @property int $tenant_id | |||||
* @property int $type | |||||
*/ | */ | ||||
class Domain extends Model | class Domain 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 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | public function assignPackage($package, $user) | ||||
foreach ($package->skus as $sku) { | foreach ($package->skus as $sku) { | ||||
for ($i = $sku->pivot->qty; $i > 0; $i--) { | for ($i = $sku->pivot->qty; $i > 0; $i--) { | ||||
\App\Entitlement::create( | \App\Entitlement::create( | ||||
[ | [ | ||||
'wallet_id' => $wallet_id, | 'wallet_id' => $wallet_id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => $sku->pivot->cost(), | 'cost' => $sku->pivot->cost(), | ||||
'fee' => $sku->pivot->fee(), | |||||
'entitleable_id' => $this->id, | 'entitleable_id' => $this->id, | ||||
'entitleable_type' => Domain::class | 'entitleable_type' => Domain::class | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
* The domain entitlement. | * The domain entitlement. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\MorphOne | * @return \Illuminate\Database\Eloquent\Relations\MorphOne | ||||
*/ | */ | ||||
public function entitlement() | public function entitlement() | ||||
{ | { | ||||
return $this->morphOne('App\Entitlement', 'entitleable'); | return $this->morphOne('App\Entitlement', 'entitleable'); | ||||
} | } | ||||
/** | /** | ||||
* Return list of public+active domain names | * Return list of public+active domain names (for current tenant) | ||||
*/ | */ | ||||
public static function getPublicDomains(): array | public static function getPublicDomains(): array | ||||
{ | { | ||||
$where = sprintf('(type & %s)', Domain::TYPE_PUBLIC); | return self::withEnvTenant() | ||||
->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | |||||
return self::whereRaw($where)->get(['namespace'])->pluck('namespace')->toArray(); | ->get(['namespace'])->pluck('namespace')->toArray(); | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is active. | * Returns whether this domain is active. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isActive(): bool | public function isActive(): bool | ||||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | public function suspend(): void | ||||
return; | return; | ||||
} | } | ||||
$this->status |= Domain::STATUS_SUSPENDED; | $this->status |= Domain::STATUS_SUSPENDED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* The tenant for this domain. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function tenant() | |||||
{ | |||||
return $this->belongsTo('App\Tenant', 'tenant_id', 'id'); | |||||
} | |||||
/** | |||||
* Unsuspend this domain. | * Unsuspend this domain. | ||||
* | * | ||||
* The domain is unsuspended through either of the following courses of actions; | * The domain is unsuspended through either of the following courses of actions; | ||||
* | * | ||||
* * The account balance has been topped up, or | * * The account balance has been topped up, or | ||||
* * a suspected spammer has resolved their issues, or | * * a suspected spammer has resolved their issues, or | ||||
* * the command-line is triggered. | * * the command-line is triggered. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |