36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace IriksIT\Manager\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use IriksIT\Manager\Support\Names;
|
|
|
|
/** What one account chose for itself in the manager: its theme, which face of the manager it looks at, its language and where it stands with the tour. */
|
|
class UserSetting extends Model
|
|
{
|
|
protected $fillable = ['user_id', 'theme', 'view', 'locale', 'tutorial'];
|
|
|
|
/** The languages the screens come in. */
|
|
public const LOCALES = ['en', 'nl'];
|
|
|
|
/** Where an account stands with the tour: `pending` shows it at the next load; `done` and `skipped` never again until it is set to pending. */
|
|
public const TUTORIAL = ['pending', 'done', 'skipped'];
|
|
|
|
/** What this account chose (a row is made when it has none yet). */
|
|
public static function put(object $user, array $values): void
|
|
{
|
|
static::query()->updateOrCreate(['user_id' => $user->getKey()], $values);
|
|
}
|
|
|
|
/** One value of what this account chose, or null. */
|
|
public static function value(?object $user, string $column): ?string
|
|
{
|
|
return $user === null || $user->getKey() === null ? null : static::query()->where('user_id', $user->getKey())->value($column);
|
|
}
|
|
|
|
public function getTable(): string
|
|
{
|
|
return Names::table('user_settings');
|
|
}
|
|
}
|