Verleih 1.0.0: Verleihsystem für Inhaus
Übersicht mit Status und Standort, Anfragen im Portal (Benachrichtigung + E-Mail ans Team), Zusagen/Absagen mit automatischem Eintrag, Zurücknehmen, Recht „Verleih verwalten“, einstellbare Bezeichnungen und Übernahme aus dem WordPress-Plugin „FL-Verleihsystem“ (WXR mit Bildern). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
14aaa16b30
47 changed files with 4208 additions and 0 deletions
67
src/Photos.php
Normal file
67
src/Photos.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Verleih;
|
||||
|
||||
use App\Support\Images;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inhaus\Plugins\Verleih\Models\Item;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Foto eines Objekts: verkleinert (max. 2000 px) und als Vorschau, beides ohne Zuschnitt –
|
||||
* bei Kunstwerken soll nichts abgeschnitten werden. Nur für angemeldete Personen abrufbar.
|
||||
*/
|
||||
class Photos
|
||||
{
|
||||
public const DISK = 'local';
|
||||
|
||||
public function store(Item $item, UploadedFile $file): void
|
||||
{
|
||||
try {
|
||||
Images::withLocalCopy($file, fn (string $local) => $this->storeLocal($item, $local));
|
||||
} catch (ValidationException $e) {
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
|
||||
throw ValidationException::withMessages(['image' => "„{$file->getClientOriginalName()}“ ließ sich nicht als Bild lesen."]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Aus einer lokalen Datei (Import) */
|
||||
public function storeLocal(Item $item, string $local): void
|
||||
{
|
||||
Images::raiseMemoryLimitFor($local);
|
||||
$manager = ImageManager::usingDriver(Driver::class);
|
||||
$image = $manager->decodePath($local)->scaleDown(2000, 2000);
|
||||
$base = 'verleih/'.$item->id.'/'.Str::random(24);
|
||||
$disk = Storage::disk(self::DISK);
|
||||
$disk->put("{$base}.webp", $image->encode(new WebpEncoder(quality: 84))->toString());
|
||||
$width = $image->width();
|
||||
$height = $image->height();
|
||||
$disk->put("{$base}-thumb.webp", $image->scaleDown(720, 720)->encode(new WebpEncoder(quality: 80))->toString());
|
||||
|
||||
$this->delete($item);
|
||||
$item->forceFill(['image_path' => "{$base}.webp", 'thumb_path' => "{$base}-thumb.webp", 'image_width' => $width, 'image_height' => $height])->save();
|
||||
}
|
||||
|
||||
public function delete(Item $item): void
|
||||
{
|
||||
if ($item->image_path) {
|
||||
Storage::disk(self::DISK)->delete([$item->image_path, (string) $item->thumb_path]);
|
||||
}
|
||||
|
||||
$item->forceFill(['image_path' => null, 'thumb_path' => null, 'image_width' => null, 'image_height' => null])->save();
|
||||
}
|
||||
|
||||
public function deleteAll(Item $item): void
|
||||
{
|
||||
Storage::disk(self::DISK)->deleteDirectory('verleih/'.$item->id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue