- lang/fa: add validation/auth/passwords/pagination translations so admin and API validation errors are in Persian - templates: soft-delete instead of cascade-deleting their generations; keep resolving trashed template on generations (labels/downloads) - templates: add TemplateInfolist with a real thumbnail ImageEntry - generations: auto-name template-based generations and use that name for the download file and as a searchable column - admin: show all dates as Jalali via ->jalaliDate()/->jalaliDateTime() Filament macros (App\Support\Jalali) - wallets: harden the deposit/withdraw action to surface the exact error instead of a 500 - profile: normalize Iranian mobile numbers (App\Support\Mobile), add social_links, coerce notification-preference booleans, require the current password to delete an account Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013P66ea1dC5CVM9t29496t5
83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\TemplateGenerationSource;
|
|
use App\Enums\TemplateGenerationStatus;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable([
|
|
'template_id',
|
|
'uuid',
|
|
'source',
|
|
'title',
|
|
'language',
|
|
'slide_count',
|
|
'source_text',
|
|
'status',
|
|
'values',
|
|
'output_path',
|
|
'error_message',
|
|
'requested_by',
|
|
])]
|
|
class TemplateGeneration extends Model
|
|
{
|
|
/**
|
|
* @return BelongsTo<Template, $this>
|
|
*/
|
|
public function template(): BelongsTo
|
|
{
|
|
// Keep resolving the template even after it has been soft-deleted, so past
|
|
// generations stay downloadable and keep their labels.
|
|
return $this->belongsTo(Template::class)->withTrashed();
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function requester(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'requested_by');
|
|
}
|
|
|
|
/**
|
|
* A human-friendly name for this generation, used in the admin panel and as the
|
|
* downloaded file name. Falls back to the template title plus a short id.
|
|
*/
|
|
public function displayName(): string
|
|
{
|
|
$base = $this->title ?: $this->template?->title ?: 'presentation';
|
|
|
|
return trim($base).' - '.$this->uuid;
|
|
}
|
|
|
|
/**
|
|
* Sanitized file name (without extension) for downloads. Keeps Persian characters
|
|
* but drops anything a filesystem or HTTP header would choke on.
|
|
*/
|
|
public function downloadFilename(): string
|
|
{
|
|
$base = $this->title ?: $this->template?->title ?: $this->template?->slug ?: 'presentation';
|
|
|
|
$clean = preg_replace('/[\/\\\\?%*:|"<>\r\n]+/u', ' ', (string) $base) ?? '';
|
|
$clean = trim(preg_replace('/\s+/u', ' ', $clean) ?? '');
|
|
|
|
return ($clean !== '' ? $clean : 'presentation').' - '.substr($this->uuid, 0, 8);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'source' => TemplateGenerationSource::class,
|
|
'status' => TemplateGenerationStatus::class,
|
|
'values' => 'array',
|
|
'slide_count' => 'integer',
|
|
];
|
|
}
|
|
}
|