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 App\Traits\UuidIntKeyTrait; | |||||
use App\Traits\BelongsToTenantTrait; | use App\Traits\BelongsToTenantTrait; | ||||
use App\Traits\DomainConfigTrait; | use App\Traits\DomainConfigTrait; | ||||
use App\Traits\EntitleableTrait; | |||||
use App\Traits\SettingsTrait; | use App\Traits\SettingsTrait; | ||||
use App\Traits\UuidIntKeyTrait; | |||||
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 $status | ||||
* @property int $tenant_id | * @property int $tenant_id | ||||
* @property int $type | * @property int $type | ||||
*/ | */ | ||||
class Domain extends Model | class Domain extends Model | ||||
{ | { | ||||
use UuidIntKeyTrait; | |||||
use BelongsToTenantTrait; | use BelongsToTenantTrait; | ||||
use DomainConfigTrait; | use DomainConfigTrait; | ||||
use EntitleableTrait; | |||||
use SettingsTrait; | use SettingsTrait; | ||||
use SoftDeletes; | use SoftDeletes; | ||||
use UuidIntKeyTrait; | |||||
// 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 | ||||
public const STATUS_ACTIVE = 1 << 1; | public const STATUS_ACTIVE = 1 << 1; | ||||
// domain has been suspended. | // domain has been suspended. | ||||
public const STATUS_SUSPENDED = 1 << 2; | public const STATUS_SUSPENDED = 1 << 2; | ||||
// domain has been deleted | // domain has been deleted | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public function assignPackage($package, $user) | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
* The domain entitlement. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\MorphOne | |||||
*/ | |||||
public function entitlement() | |||||
{ | |||||
return $this->morphOne('App\Entitlement', 'entitleable'); | |||||
} | |||||
/** | |||||
* Entitlements for this domain. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |||||
*/ | |||||
public function entitlements() | |||||
{ | |||||
return $this->hasMany('App\Entitlement', 'entitleable_id', 'id') | |||||
->where('entitleable_type', Domain::class); | |||||
} | |||||
/** | |||||
* Return list of public+active domain names (for current tenant) | * Return list of public+active domain names (for current tenant) | ||||
*/ | */ | ||||
public static function getPublicDomains(): array | public static function getPublicDomains(): array | ||||
{ | { | ||||
return self::withEnvTenantContext() | return self::withEnvTenantContext() | ||||
->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | ->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | ||||
->get(['namespace'])->pluck('namespace')->toArray(); | ->get(['namespace'])->pluck('namespace')->toArray(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 384 Lines • ▼ Show 20 Lines | public function verify(): bool | ||||
$this->status |= Domain::STATUS_VERIFIED; | $this->status |= Domain::STATUS_VERIFIED; | ||||
$this->save(); | $this->save(); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | |||||
* Returns the wallet by which the domain is controlled | |||||
* | |||||
* @return \App\Wallet A wallet object | |||||
*/ | |||||
public function wallet(): ?Wallet | |||||
{ | |||||
// Note: Not all domains have a entitlement/wallet | |||||
$entitlement = $this->entitlement()->withTrashed()->orderBy('created_at', 'desc')->first(); | |||||
return $entitlement ? $entitlement->wallet : null; | |||||
} | |||||
} | } |