Neustrukturierung Customer / Lead / Booking Phase 2
This commit is contained in:
parent
313f0dbf4e
commit
6df9c401af
69 changed files with 3809 additions and 374 deletions
|
|
@ -8,32 +8,36 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Datei-Anhang einer Angebotsversion (Modul 6).
|
||||
* Datei-Anhang einer Angebotsversion.
|
||||
*
|
||||
* Struktur ist bewusst an {@see BookingFile} angelehnt (identifier,
|
||||
* filename, dir, original_name, ext, mine, size), damit der vorhandene
|
||||
* `FileRepository::store()` 1:1 wiederverwendet werden kann. `mine`
|
||||
* bleibt so geschrieben (statt `mime`) zur Konsistenz mit der
|
||||
* booking_files-Konvention.
|
||||
* Bewusst API-kompatibel mit {@see BookingFile} gehalten (gleiche
|
||||
* Method-Signaturen für `getURL()`, `getIconExt()`, `formatBytes()`,
|
||||
* `getPath()`), damit Blade-Partials wie `booking/modal-new-booking-files`
|
||||
* und die Dropzone-JS-Helfer direkt wiederverwendet werden können.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $offer_version_id
|
||||
* Speichert in disk `offer` (Konvention: `storage/app/offer/YYYY/MM/…`).
|
||||
* Die Spalten-Schreibweise `mine` (statt `mime`) wurde aus BookingFile
|
||||
* übernommen, damit Frontend-Code identisch funktioniert.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $offer_version_id
|
||||
* @property string|null $identifier
|
||||
* @property string $filename
|
||||
* @property string $dir
|
||||
* @property string $original_name
|
||||
* @property string $ext
|
||||
* @property string $mine
|
||||
* @property int $size
|
||||
* @property bool $include_in_pdf
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property-read OfferVersion $version
|
||||
* @property string $filename
|
||||
* @property string $dir
|
||||
* @property string $original_name
|
||||
* @property string $ext
|
||||
* @property string $mine
|
||||
* @property int $size
|
||||
* @property bool $include_in_pdf
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property-read OfferVersion $offerVersion
|
||||
*/
|
||||
class OfferFile extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $connection = 'mysql';
|
||||
protected $table = 'offer_files';
|
||||
|
||||
protected $fillable = [
|
||||
|
|
@ -54,7 +58,11 @@ class OfferFile extends Model
|
|||
'include_in_pdf' => 'bool',
|
||||
];
|
||||
|
||||
public static array $iconExt = [
|
||||
/**
|
||||
* Icon-Klassen nach Extension (kompatibel zu BookingFile::$icon_ext).
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public static $icon_ext = [
|
||||
'default' => 'fa fa-file',
|
||||
'pdf' => 'fa fa-file-pdf',
|
||||
'jpg' => 'fa fa-file-image',
|
||||
|
|
@ -64,36 +72,45 @@ class OfferFile extends Model
|
|||
'docx' => 'fa fa-file-word',
|
||||
];
|
||||
|
||||
public function version(): BelongsTo
|
||||
public function offerVersion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(OfferVersion::class, 'offer_version_id');
|
||||
}
|
||||
|
||||
public function getIconExt(): string
|
||||
{
|
||||
return self::$iconExt[$this->ext] ?? self::$iconExt['default'];
|
||||
return self::$icon_ext[$this->ext] ?? self::$icon_ext['default'];
|
||||
}
|
||||
|
||||
public function getURL(bool|string $do = false): string
|
||||
/**
|
||||
* Download/Preview-URL. Der zweite Parameter der Storage-Route (`offer`)
|
||||
* wird vom `storage_file`-Controller für Disk-Auswahl ausgewertet —
|
||||
* muss serverseitig freigeschaltet sein (siehe Ticket B4 / StorageController).
|
||||
*
|
||||
* @param bool|string $download false = inline, 'download' = Attachment
|
||||
*/
|
||||
public function getURL($download = false): string
|
||||
{
|
||||
return route('storage_file', [$this->id, 'offer', $do]);
|
||||
return route('storage_file', [$this->id, 'offer', $download]);
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
// gleiches Idiom wie BookingFile::getPath() — Intelephense sieht
|
||||
// path() im Filesystem-Contract in diesem Kontext nicht zuverlässig,
|
||||
// php -l ist sauber; Methode ist Teil der Laravel-Filesystem-API seit 9.x.
|
||||
/** @phpstan-ignore-next-line */
|
||||
return \Storage::disk('offer')->path($this->dir . $this->filename);
|
||||
}
|
||||
|
||||
public function formatBytes(int $precision = 2): string
|
||||
{
|
||||
$size = $this->size;
|
||||
$size = (int) $this->size;
|
||||
if ($size <= 0) {
|
||||
return (string) $size;
|
||||
return '0 bytes';
|
||||
}
|
||||
|
||||
$base = log($size) / log(1024);
|
||||
$base = log($size) / log(1024);
|
||||
$suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB'];
|
||||
|
||||
return round(1024 ** ($base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int) floor($base)];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue