feat: Lernapp mit Mathe/Deutsch/Englisch, Münzsystem und Belohnungen
This commit is contained in:
+26
-23
@@ -1,32 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
class User extends Authenticatable {
|
||||
use HasFactory, Notifiable;
|
||||
protected $fillable = ['name','email','password','role','points'];
|
||||
protected $hidden = ['password','remember_token'];
|
||||
protected $casts = ['email_verified_at' => 'datetime', 'password' => 'hashed'];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
public function isAdmin(): bool { return $this->role === 'admin'; }
|
||||
public function isChild(): bool { return $this->role === 'child'; }
|
||||
|
||||
public function attempts() { return $this->hasMany(QuestionAttempt::class); }
|
||||
public function redemptions() { return $this->hasMany(RewardRedemption::class); }
|
||||
|
||||
public function level(): array {
|
||||
$p = $this->points;
|
||||
if ($p >= 600) return ['label' => 'Meister', 'icon' => '👑', 'color' => 'text-yellow-500', 'next' => null, 'progress' => 100];
|
||||
if ($p >= 300) return ['label' => 'Wissensprofi', 'icon' => '🌟', 'color' => 'text-purple-500', 'next' => 600, 'progress' => (int)(($p-300)/3)];
|
||||
if ($p >= 100) return ['label' => 'Lernstar', 'icon' => '⭐', 'color' => 'text-blue-500', 'next' => 300, 'progress' => (int)(($p-100)/2)];
|
||||
return ['label' => 'Anfänger', 'icon' => '🌱', 'color' => 'text-green-500', 'next' => 100, 'progress' => $p];
|
||||
}
|
||||
|
||||
public function currentStreak(): int {
|
||||
$last = $this->attempts()->latest('id')->take(10)->get();
|
||||
$streak = 0;
|
||||
foreach ($last as $a) {
|
||||
if (!$a->is_correct) break;
|
||||
$streak++;
|
||||
}
|
||||
return $streak;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user