ajout bibliothèque méditation et changement de test
This commit is contained in:
@@ -12,7 +12,22 @@ class DiagnosticController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$events = StressEvent::all();
|
||||
return view('diagnostics.index', compact('events'));
|
||||
$history = [];
|
||||
if (Auth::check()) {
|
||||
$history = \App\Models\ResultatDiag::where('id_user', Auth::id())
|
||||
->orderBy('date_passage', 'desc')
|
||||
->take(5)
|
||||
->get();
|
||||
}
|
||||
return view('diagnostics.index', compact('events', 'history'));
|
||||
}
|
||||
|
||||
public function history()
|
||||
{
|
||||
$history = \App\Models\ResultatDiag::where('id_user', Auth::id())
|
||||
->orderBy('date_passage', 'desc')
|
||||
->get();
|
||||
return view('diagnostics.history', compact('history'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
@@ -23,8 +38,24 @@ class DiagnosticController extends Controller
|
||||
$totalPoints = StressEvent::whereIn('id', $request->events)->sum('points');
|
||||
}
|
||||
|
||||
// Ici on pourrait enregistrer le résultat dans une table 'diagnostic_results'
|
||||
// Pour l'instant on redirige avec le score
|
||||
$niveauStress = 'Faible';
|
||||
if ($totalPoints >= 300) {
|
||||
$niveauStress = 'Élevé';
|
||||
} elseif ($totalPoints >= 150) {
|
||||
$niveauStress = 'Modéré';
|
||||
}
|
||||
|
||||
// Enregistrement si l'utilisateur est connecté
|
||||
if (Auth::check()) {
|
||||
\App\Models\ResultatDiag::create([
|
||||
'id_user' => Auth::id(),
|
||||
'score_total' => $totalPoints,
|
||||
'niveau_stress' => $niveauStress,
|
||||
'event_ids' => $request->has('events') ? implode(';', $request->events) : null,
|
||||
'date_passage' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('score', $totalPoints);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,26 +13,13 @@ class RelaxationController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$activities = RelaxationActivity::all();
|
||||
$favorites = Auth::check() ? Auth::user()->favoritedBy->pluck('id')->toArray() : [];
|
||||
$favorites = [];
|
||||
return view('relaxation.index', compact('activities', 'favorites'));
|
||||
}
|
||||
|
||||
public function toggleFavorite($id)
|
||||
{
|
||||
$userId = Auth::id();
|
||||
$favorite = Favorite::where('user_id', $userId)
|
||||
->where('relaxation_activity_id', $id)
|
||||
->first();
|
||||
|
||||
if ($favorite) {
|
||||
$favorite->delete();
|
||||
return response()->json(['status' => 'removed']);
|
||||
} else {
|
||||
Favorite::create([
|
||||
'user_id' => $userId,
|
||||
'relaxation_activity_id' => $id
|
||||
]);
|
||||
return response()->json(['status' => 'added']);
|
||||
}
|
||||
// Fonctionnalité désactivée pour le moment
|
||||
return response()->json(['status' => 'disabled']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,32 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ResultatDiag extends Model
|
||||
{
|
||||
//
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'resultat_diags';
|
||||
|
||||
protected $fillable = [
|
||||
'id_user',
|
||||
'date_passage',
|
||||
'score_total',
|
||||
'niveau_stress',
|
||||
'event_ids'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'id_user');
|
||||
}
|
||||
|
||||
public function getEventsAttribute()
|
||||
{
|
||||
if (!$this->event_ids) return collect();
|
||||
$ids = explode(';', $this->event_ids);
|
||||
return StressEvent::whereIn('id', $ids)->get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user