Changeset View
Changeset View
Standalone View
Standalone View
src/app/SharedFolder.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Traits\BelongsToTenantTrait; | use App\Traits\BelongsToTenantTrait; | ||||
use App\Traits\EntitleableTrait; | use App\Traits\EntitleableTrait; | ||||
use App\Traits\SharedFolderConfigTrait; | use App\Traits\SharedFolderConfigTrait; | ||||
use App\Traits\SettingsTrait; | use App\Traits\SettingsTrait; | ||||
use App\Traits\StatusPropertyTrait; | |||||
use App\Traits\UuidIntKeyTrait; | use App\Traits\UuidIntKeyTrait; | ||||
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 SharedFolder. | * The eloquent definition of a SharedFolder. | ||||
* | * | ||||
* @property string $email An email address | * @property string $email An email address | ||||
* @property int $id The folder identifier | * @property int $id The folder identifier | ||||
* @property string $name The folder name | * @property string $name The folder name | ||||
* @property int $status The folder status | * @property int $status The folder status | ||||
* @property int $tenant_id Tenant identifier | * @property int $tenant_id Tenant identifier | ||||
* @property string $type The folder type | * @property string $type The folder type | ||||
*/ | */ | ||||
class SharedFolder extends Model | class SharedFolder extends Model | ||||
{ | { | ||||
use BelongsToTenantTrait; | use BelongsToTenantTrait; | ||||
use EntitleableTrait; | use EntitleableTrait; | ||||
use SharedFolderConfigTrait; | use SharedFolderConfigTrait; | ||||
use SettingsTrait; | use SettingsTrait; | ||||
use SoftDeletes; | use SoftDeletes; | ||||
use StatusPropertyTrait; | |||||
use UuidIntKeyTrait; | use UuidIntKeyTrait; | ||||
// we've simply never heard of this folder | // we've simply never heard of this folder | ||||
public const STATUS_NEW = 1 << 0; | public const STATUS_NEW = 1 << 0; | ||||
// folder has been activated | // folder has been activated | ||||
public const STATUS_ACTIVE = 1 << 1; | public const STATUS_ACTIVE = 1 << 1; | ||||
// folder has been suspended. | // folder has been suspended. | ||||
// public const STATUS_SUSPENDED = 1 << 2; | // public const STATUS_SUSPENDED = 1 << 2; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | public static function emailExists(string $email, bool $return_folder = false) | ||||
if ($folder) { | if ($folder) { | ||||
return $return_folder ? $folder : true; | return $return_folder ? $folder : true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Returns whether this folder is active. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isActive(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_ACTIVE) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this folder is deleted. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isDeleted(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_DELETED) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this folder exists in IMAP. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isImapReady(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_IMAP_READY) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this folder is registered in LDAP. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isLdapReady(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_LDAP_READY) > 0; | |||||
} | |||||
/** | |||||
* Returns whether this folder is new. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isNew(): bool | |||||
{ | |||||
return ($this->status & self::STATUS_NEW) > 0; | |||||
} | |||||
/** | |||||
* Folder status mutator | |||||
* | |||||
* @throws \Exception | |||||
*/ | |||||
public function setStatusAttribute($status) | |||||
{ | |||||
$new_status = 0; | |||||
$allowed_values = [ | |||||
self::STATUS_NEW, | |||||
self::STATUS_ACTIVE, | |||||
self::STATUS_DELETED, | |||||
self::STATUS_IMAP_READY, | |||||
self::STATUS_LDAP_READY, | |||||
]; | |||||
foreach ($allowed_values as $value) { | |||||
if ($status & $value) { | |||||
$new_status |= $value; | |||||
$status ^= $value; | |||||
} | |||||
} | |||||
if ($status > 0) { | |||||
throw new \Exception("Invalid shared folder status: {$status}"); | |||||
} | |||||
$this->attributes['status'] = $new_status; | |||||
} | |||||
/** | |||||
* Folder type mutator | * Folder type mutator | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
public function setTypeAttribute($type) | public function setTypeAttribute($type) | ||||
{ | { | ||||
if (!in_array($type, self::SUPPORTED_TYPES)) { | if (!in_array($type, self::SUPPORTED_TYPES)) { | ||||
throw new \Exception("Invalid shared folder type: {$type}"); | throw new \Exception("Invalid shared folder type: {$type}"); | ||||
} | } | ||||
$this->attributes['type'] = $type; | $this->attributes['type'] = $type; | ||||
} | } | ||||
} | } |