Changeset View
Changeset View
Standalone View
Standalone View
src/app/SharedFolder.php
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
'type', | 'type', | ||||
]; | ]; | ||||
/** @var ?string Domain name for a shared folder to be created */ | /** @var ?string Domain name for a shared folder to be created */ | ||||
public $domain; | public $domain; | ||||
/** | /** | ||||
* Assign the folder to a wallet. | |||||
* | |||||
* @param \App\Wallet $wallet The wallet | |||||
* | |||||
* @return \App\SharedFolder Self | |||||
* @throws \Exception | |||||
*/ | |||||
public function assignToWallet(Wallet $wallet): SharedFolder | |||||
{ | |||||
if (empty($this->id)) { | |||||
throw new \Exception("Shared folder not yet exists"); | |||||
} | |||||
if ($this->entitlements()->count()) { | |||||
throw new \Exception("Shared folder already assigned to a wallet"); | |||||
} | |||||
$sku = \App\Sku::withObjectTenantContext($this)->where('title', 'shared-folder')->first(); | |||||
$exists = $wallet->entitlements()->where('sku_id', $sku->id)->count(); | |||||
\App\Entitlement::create([ | |||||
'wallet_id' => $wallet->id, | |||||
'sku_id' => $sku->id, | |||||
'cost' => $exists >= $sku->units_free ? $sku->cost : 0, | |||||
'fee' => $exists >= $sku->units_free ? $sku->fee : 0, | |||||
'entitleable_id' => $this->id, | |||||
'entitleable_type' => SharedFolder::class | |||||
]); | |||||
return $this; | |||||
} | |||||
/** | |||||
* Returns the shared folder domain. | * Returns the shared folder domain. | ||||
* | * | ||||
* @return ?\App\Domain The domain to which the folder belongs to, NULL if it does not exist | * @return ?\App\Domain The domain to which the folder belongs to, NULL if it does not exist | ||||
*/ | */ | ||||
public function domain(): ?Domain | public function domain(): ?Domain | ||||
{ | { | ||||
if (isset($this->domain)) { | if (isset($this->domain)) { | ||||
$domainName = $this->domain; | $domainName = $this->domain; | ||||
▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines |