Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers, retention controls, public landing pages, analytics, and Gitea deploy workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Transfer extends Model
|
|
{
|
|
public const STATUS_ACTIVE = 'active';
|
|
|
|
public const STATUS_EXPIRED = 'expired';
|
|
|
|
public const STATUS_DELETED = 'deleted';
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'qr_code_id',
|
|
'title',
|
|
'message',
|
|
'password_hash',
|
|
'retention_days',
|
|
'expires_at',
|
|
'status',
|
|
'downloads_total',
|
|
'storage_bytes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'retention_days' => 'integer',
|
|
'expires_at' => 'datetime',
|
|
'downloads_total' => 'integer',
|
|
'storage_bytes' => 'integer',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function qrCode(): BelongsTo
|
|
{
|
|
return $this->belongsTo(QrCode::class);
|
|
}
|
|
|
|
public function files(): HasMany
|
|
{
|
|
return $this->hasMany(TransferFile::class);
|
|
}
|
|
|
|
public function downloadEvents(): HasMany
|
|
{
|
|
return $this->hasMany(TransferDownloadEvent::class);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
if ($this->status !== self::STATUS_ACTIVE) {
|
|
return false;
|
|
}
|
|
|
|
if ($this->expires_at && $this->expires_at->isPast()) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function isPasswordProtected(): bool
|
|
{
|
|
return $this->password_hash !== null && $this->password_hash !== '';
|
|
}
|
|
|
|
public function storageGb(): float
|
|
{
|
|
return round($this->storage_bytes / (1024 * 1024 * 1024), 3);
|
|
}
|
|
|
|
public function monthlyCostGhs(): float
|
|
{
|
|
return round($this->storageGb() * (float) config('transfer.price_per_gb_month', 1.0), 2);
|
|
}
|
|
}
|