From b2862d8450f81d19d7adae6b183035fbaa3f9be7 Mon Sep 17 00:00:00 2001 From: marcogermani87 Date: Mon, 26 Aug 2024 20:30:55 +0000 Subject: [PATCH] Fix styling --- src/Models/Email.php | 258 +++++++++++++++++++++---------------------- 1 file changed, 129 insertions(+), 129 deletions(-) diff --git a/src/Models/Email.php b/src/Models/Email.php index bb2e800..1b8d416 100644 --- a/src/Models/Email.php +++ b/src/Models/Email.php @@ -1,129 +1,129 @@ - 'json', - ]; - - public function team(): BelongsTo - { - return $this->belongsTo(config('filament-email.tenant_model'), 'team_id', 'id'); - } - - protected static function booted(): void - { - static::addGlobalScope('teams', function (Builder $query) { - if (auth()->check() && Filament::getTenant()) { - $query->whereBelongsTo(auth()->user()?->teams); - } else { - $query->whereTeamId(null); - } - }); - } - - public static function boot() - { - parent::boot(); - - self::deleting(function ($record) { - $storageDisk = config('filament-email.attachments_disk', 'local'); - $folderPath = null; - if (! empty($record->attachments)) { - foreach ($record->attachments as $attachment) { - $filePath = Storage::disk($storageDisk)->path($attachment['path']); - if (empty($folderPath)) { - $parts = explode(DIRECTORY_SEPARATOR, $attachment['path']); - array_pop($parts); - $folderPath = implode(DIRECTORY_SEPARATOR, $parts); - } - if (! Storage::directoryExists($folderPath) && Storage::disk($storageDisk)->exists($attachment['path'])) { - Storage::disk($storageDisk)->delete($attachment['path']); - } - } - } - - if (! empty($record->raw_body) && count(explode(DIRECTORY_SEPARATOR, $record->raw_body)) === 3) { - if (! Storage::disk($storageDisk)->directoryExists($record->raw_body) && Storage::disk($storageDisk)->exists($record->raw_body)) { - if (empty($folderPath)) { - $parts = explode(DIRECTORY_SEPARATOR, $record->raw_body); - array_pop($parts); - $folderPath = implode(DIRECTORY_SEPARATOR, $parts); - } - Storage::disk($storageDisk)->delete($record->raw_body); - } - if (Storage::disk($storageDisk)->directoryExists($folderPath)) { - Storage::disk($storageDisk)->deleteDirectory($folderPath); - } - } - }); - } - - public function prunable() - { - return static::where('created_at', '<=', now()->subDays(config('filament-email.keep_email_for_days', 60))); - } - - private function getTableColumns() - { - return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable()); - } - - private function getSearchableFields() - { - $columns = $this->getTableColumns(); - $fields = config('filament-email.resource.table_search_fields', $this->defaultSearchFields); - - return Arr::where($fields, function ($value) use ($columns) { - return in_array($value, $columns); - }); - } - - public function scopeFilter($query, array $filters) - { - $query->when($filters['search'] ?? null, function ($query, $search) { - foreach ($this->getSearchableFields() as $key => $field) { - $query->{$key > 0 ? 'orWhere' : 'where'}($field, 'LIKE', "%{$search}%"); - } - }); - } -} + 'json', + ]; + + public function team(): BelongsTo + { + return $this->belongsTo(config('filament-email.tenant_model'), 'team_id', 'id'); + } + + protected static function booted(): void + { + static::addGlobalScope('teams', function (Builder $query) { + if (auth()->check() && Filament::getTenant()) { + $query->whereBelongsTo(auth()->user()?->teams); + } else { + $query->whereTeamId(null); + } + }); + } + + public static function boot() + { + parent::boot(); + + self::deleting(function ($record) { + $storageDisk = config('filament-email.attachments_disk', 'local'); + $folderPath = null; + if (! empty($record->attachments)) { + foreach ($record->attachments as $attachment) { + $filePath = Storage::disk($storageDisk)->path($attachment['path']); + if (empty($folderPath)) { + $parts = explode(DIRECTORY_SEPARATOR, $attachment['path']); + array_pop($parts); + $folderPath = implode(DIRECTORY_SEPARATOR, $parts); + } + if (! Storage::directoryExists($folderPath) && Storage::disk($storageDisk)->exists($attachment['path'])) { + Storage::disk($storageDisk)->delete($attachment['path']); + } + } + } + + if (! empty($record->raw_body) && count(explode(DIRECTORY_SEPARATOR, $record->raw_body)) === 3) { + if (! Storage::disk($storageDisk)->directoryExists($record->raw_body) && Storage::disk($storageDisk)->exists($record->raw_body)) { + if (empty($folderPath)) { + $parts = explode(DIRECTORY_SEPARATOR, $record->raw_body); + array_pop($parts); + $folderPath = implode(DIRECTORY_SEPARATOR, $parts); + } + Storage::disk($storageDisk)->delete($record->raw_body); + } + if (Storage::disk($storageDisk)->directoryExists($folderPath)) { + Storage::disk($storageDisk)->deleteDirectory($folderPath); + } + } + }); + } + + public function prunable() + { + return static::where('created_at', '<=', now()->subDays(config('filament-email.keep_email_for_days', 60))); + } + + private function getTableColumns() + { + return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable()); + } + + private function getSearchableFields() + { + $columns = $this->getTableColumns(); + $fields = config('filament-email.resource.table_search_fields', $this->defaultSearchFields); + + return Arr::where($fields, function ($value) use ($columns) { + return in_array($value, $columns); + }); + } + + public function scopeFilter($query, array $filters) + { + $query->when($filters['search'] ?? null, function ($query, $search) { + foreach ($this->getSearchableFields() as $key => $field) { + $query->{$key > 0 ? 'orWhere' : 'where'}($field, 'LIKE', "%{$search}%"); + } + }); + } +}