- Medium anlegen: Pflichtfeld Fachliche Materialart (serverseitig geprüft) - Materialart Übungsabschnitt (automatisch) für Abschnitte im Übungseditor und aus Shinkan, mit Verweis auf die Übung - Medienmanager: Checkboxen statt Dropdown, Start ohne Übungsabschnitte, persönlicher Standard je Konto - Zuordnung des Bestands nur bei belegter Herkunft; Übungsabschnitte nie öffentlich Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Persönlicher Standard der Filter einer Verwaltungsansicht, je Konto und Ansicht (zum Beispiel `medien`). Er gilt
|
|
* nur für das eigene Konto und überdauert die Anmeldung.
|
|
*/
|
|
class UserViewDefault extends Model
|
|
{
|
|
public const MEDIA = 'medien';
|
|
|
|
protected $fillable = ['user_id', 'view', 'filters'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['filters' => 'array'];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>|null
|
|
*/
|
|
public static function filtersFor(?int $userId, string $view): ?array
|
|
{
|
|
if ($userId === null) {
|
|
return null;
|
|
}
|
|
|
|
$row = static::query()->where('user_id', $userId)->where('view', $view)->first();
|
|
|
|
return $row === null ? null : array_map('strval', (array) $row->filters);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, string> $filters
|
|
*/
|
|
public static function remember(int $userId, string $view, array $filters): void
|
|
{
|
|
static::query()->updateOrCreate(['user_id' => $userId, 'view' => $view], ['filters' => $filters]);
|
|
}
|
|
|
|
public static function forget(int $userId, string $view): void
|
|
{
|
|
static::query()->where('user_id', $userId)->where('view', $view)->delete();
|
|
}
|
|
}
|