feat: Lernapp mit Mathe/Deutsch/Englisch, Münzsystem und Belohnungen
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class AnswerOption extends Model {
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['question_id','text','is_correct','sort_order'];
|
||||
protected $casts = ['is_correct' => 'boolean'];
|
||||
public function question() { return $this->belongsTo(Question::class); }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class Question extends Model {
|
||||
protected $fillable = ['subject_id','question_text','type','difficulty','points_value','active'];
|
||||
protected $casts = ['active' => 'boolean'];
|
||||
public function subject() { return $this->belongsTo(Subject::class); }
|
||||
public function answerOptions() { return $this->hasMany(AnswerOption::class)->orderBy('sort_order'); }
|
||||
public function attempts() { return $this->hasMany(QuestionAttempt::class); }
|
||||
public function difficultyStars(): string {
|
||||
return str_repeat('⭐', $this->difficulty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class QuestionAttempt extends Model {
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['user_id','question_id','is_correct','points_earned'];
|
||||
protected $casts = ['is_correct' => 'boolean', 'created_at' => 'datetime'];
|
||||
public function user() { return $this->belongsTo(User::class); }
|
||||
public function question() { return $this->belongsTo(Question::class); }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class Reward extends Model {
|
||||
protected $fillable = ['name','description','icon','points_cost','minutes','active'];
|
||||
protected $casts = ['active' => 'boolean'];
|
||||
public function redemptions() { return $this->hasMany(RewardRedemption::class); }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class RewardRedemption extends Model {
|
||||
protected $fillable = ['user_id','reward_id','status','points_spent','note','resolved_at','resolved_by'];
|
||||
protected $casts = ['resolved_at' => 'datetime'];
|
||||
public function user() { return $this->belongsTo(User::class); }
|
||||
public function reward() { return $this->belongsTo(Reward::class); }
|
||||
public function resolver() { return $this->belongsTo(User::class, 'resolved_by'); }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class Subject extends Model {
|
||||
protected $fillable = ['name','slug','icon','color'];
|
||||
public function questions() { return $this->hasMany(Question::class); }
|
||||
public function activeQuestions() { return $this->questions()->where('active', true); }
|
||||
}
|
||||
+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