Save
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources;
|
||||
|
||||
use App\Filament\Admin\Resources\InformationResource\Pages;
|
||||
use App\Models\Information;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class InformationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Information::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-information-circle';
|
||||
|
||||
protected static ?string $navigationLabel = 'Informations';
|
||||
|
||||
protected static ?string $modelLabel = 'Information';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label('Titre')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('category')
|
||||
->label('Catégorie')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->default('Général'),
|
||||
Forms\Components\RichEditor::make('content')
|
||||
->label('Contenu')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Forms\Components\FileUpload::make('image_url')
|
||||
->label('Image')
|
||||
->image()
|
||||
->directory('informations'),
|
||||
Forms\Components\Toggle::make('is_published')
|
||||
->label('Publié')
|
||||
->default(true)
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->label('Titre')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('category')
|
||||
->label('Catégorie')
|
||||
->badge()
|
||||
->searchable(),
|
||||
Tables\Columns\IconColumn::make('is_published')
|
||||
->label('Publié')
|
||||
->boolean(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Créé le')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TernaryFilter::make('is_published')
|
||||
->label('Statut de publication')
|
||||
->boolean()
|
||||
->trueLabel('Publiés')
|
||||
->falseLabel('Brouillons')
|
||||
->native(false),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListInformation::route('/'),
|
||||
'create' => Pages\CreateInformation::route('/create'),
|
||||
'edit' => Pages\EditInformation::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\InformationResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\InformationResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateInformation extends CreateRecord
|
||||
{
|
||||
protected static string $resource = InformationResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\InformationResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\InformationResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditInformation extends EditRecord
|
||||
{
|
||||
protected static string $resource = InformationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\InformationResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\InformationResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListInformation extends ListRecords
|
||||
{
|
||||
protected static string $resource = InformationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources;
|
||||
|
||||
use App\Filament\Admin\Resources\RelaxationActivityResource\Pages;
|
||||
use App\Models\RelaxationActivity;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RelaxationActivityResource extends Resource
|
||||
{
|
||||
protected static ?string $model = RelaxationActivity::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-sparkles';
|
||||
|
||||
protected static ?string $navigationLabel = 'Activités de détente';
|
||||
|
||||
protected static ?string $modelLabel = 'Activité de détente';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label('Titre')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\Select::make('type')
|
||||
->options([
|
||||
'video' => 'Vidéo',
|
||||
'audio' => 'Audio',
|
||||
'article' => 'Article',
|
||||
'exercice' => 'Exercice',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('duration')
|
||||
->label('Durée (min)')
|
||||
->numeric(),
|
||||
Forms\Components\TextInput::make('url')
|
||||
->label('Lien / URL')
|
||||
->url()
|
||||
->maxLength(255),
|
||||
Forms\Components\Textarea::make('description')
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->label('Titre')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->badge(),
|
||||
Tables\Columns\TextColumn::make('duration')
|
||||
->label('Durée')
|
||||
->suffix(' min'),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('type')
|
||||
->options([
|
||||
'video' => 'Vidéo',
|
||||
'audio' => 'Audio',
|
||||
'article' => 'Article',
|
||||
'exercice' => 'Exercice',
|
||||
]),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListRelaxationActivities::route('/'),
|
||||
'create' => Pages\CreateRelaxationActivity::route('/create'),
|
||||
'edit' => Pages\EditRelaxationActivity::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\RelaxationActivityResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\RelaxationActivityResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRelaxationActivity extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RelaxationActivityResource::class;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\RelaxationActivityResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\RelaxationActivityResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRelaxationActivity extends EditRecord
|
||||
{
|
||||
protected static string $resource = RelaxationActivityResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\RelaxationActivityResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\RelaxationActivityResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRelaxationActivities extends ListRecords
|
||||
{
|
||||
protected static string $resource = RelaxationActivityResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources;
|
||||
|
||||
use App\Filament\Admin\Resources\StressEventResource\Pages;
|
||||
use App\Models\StressEvent;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class StressEventResource extends Resource
|
||||
{
|
||||
protected static ?string $model = StressEvent::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-bolt';
|
||||
|
||||
protected static ?string $navigationLabel = 'Événements de stress';
|
||||
|
||||
protected static ?string $modelLabel = 'Événement de stress';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Événements de stress';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('event_name')
|
||||
->label('Nom de l\'événement')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('points')
|
||||
->label('Points de stress')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(100),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('event_name')
|
||||
->label('Événement')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('points')
|
||||
->label('Points')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Dernière modification')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListStressEvents::route('/'),
|
||||
'create' => Pages\CreateStressEvent::route('/create'),
|
||||
'edit' => Pages\EditStressEvent::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\StressEventResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\StressEventResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateStressEvent extends CreateRecord
|
||||
{
|
||||
protected static string $resource = StressEventResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\StressEventResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\StressEventResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditStressEvent extends EditRecord
|
||||
{
|
||||
protected static string $resource = StressEventResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\StressEventResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\StressEventResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListStressEvents extends ListRecords
|
||||
{
|
||||
protected static string $resource = StressEventResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources;
|
||||
|
||||
use App\Filament\Admin\Resources\UserResource\Pages;
|
||||
use App\Models\User;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-users';
|
||||
|
||||
protected static ?string $navigationLabel = 'Utilisateurs';
|
||||
|
||||
protected static ?string $modelLabel = 'Utilisateur';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\Select::make('id_role')
|
||||
->relationship('role', 'libelle')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('password')
|
||||
->password()
|
||||
->dehydrated(fn ($state) => filled($state))
|
||||
->required(fn (string $context): bool => $context === 'create'),
|
||||
Forms\Components\Toggle::make('is_active')
|
||||
->label('Compte actif')
|
||||
->default(true)
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('email')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('role.libelle')
|
||||
->label('Rôle')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'Admin' => 'danger',
|
||||
'Utilisateur' => 'info',
|
||||
default => 'gray',
|
||||
}),
|
||||
Tables\Columns\ToggleColumn::make('is_active')
|
||||
->label('Actif'),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TernaryFilter::make('is_active')
|
||||
->label('Statut')
|
||||
->boolean()
|
||||
->trueLabel('Utilisateurs actifs')
|
||||
->falseLabel('Utilisateurs désactivés')
|
||||
->native(false),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListUsers::route('/'),
|
||||
'create' => Pages\CreateUser::route('/create'),
|
||||
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,14 @@ class AuthController extends Controller
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Vérification si le compte est actif
|
||||
if (!$user->is_active) {
|
||||
return response([
|
||||
'status' => 'error',
|
||||
'message' => 'Votre compte a été désactivé par un administrateur.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
// Log::info('Email reçu: ' . $request->email);
|
||||
// Log::info('Password saisi: ' . $request->password);
|
||||
// Log::info('Hachage en BDD: ' . $user->password);
|
||||
@@ -45,7 +53,7 @@ class AuthController extends Controller
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function register(Request $request)
|
||||
public function register(Request $request)
|
||||
{
|
||||
// 1. Validation des données (Standard Qualité)
|
||||
$validator = Validator::make($request->all(), [
|
||||
@@ -54,7 +62,7 @@ class AuthController extends Controller
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
]);
|
||||
|
||||
|
||||
|
||||
Log::info('Tentative de création', $request->all());
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -90,8 +98,8 @@ class AuthController extends Controller
|
||||
$request->validate([
|
||||
'current_password' => 'required',
|
||||
'email' => [
|
||||
'sometimes',
|
||||
'email',
|
||||
'sometimes',
|
||||
'email',
|
||||
Rule::unique('users')->ignore($user->id) // Empêche les doublons en BDD
|
||||
],
|
||||
]);
|
||||
@@ -99,7 +107,7 @@ class AuthController extends Controller
|
||||
// 2. Vérification de sécurité (RGPD/Confidentialité)
|
||||
if (!Hash::check($request->current_password, $user->password)) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'status' => 'error',
|
||||
'message' => 'Le mot de passe actuel est incorrect'
|
||||
], 403);
|
||||
}
|
||||
@@ -114,4 +122,4 @@ class AuthController extends Controller
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Information;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InformationController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$informations = Information::where('is_published', true)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $informations
|
||||
]);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$information = Information::where('is_published', true)->find($id);
|
||||
|
||||
if (!$information) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Information non trouvée'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $information
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -30,20 +30,16 @@ class DiagnosticController extends Controller
|
||||
return view('diagnostics.history', compact('history'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
public function store(Request $request, \App\Services\StressCalculator $calculator)
|
||||
{
|
||||
// Logique pour calculer le score Holmes-Rahe
|
||||
$totalPoints = 0;
|
||||
if ($request->has('events')) {
|
||||
$totalPoints = StressEvent::whereIn('id', $request->events)->sum('points');
|
||||
$points = StressEvent::whereIn('id', $request->events)->pluck('points')->toArray();
|
||||
$totalPoints = $calculator->calculateScore($points);
|
||||
}
|
||||
|
||||
$niveauStress = 'Faible';
|
||||
if ($totalPoints >= 300) {
|
||||
$niveauStress = 'Élevé';
|
||||
} elseif ($totalPoints >= 150) {
|
||||
$niveauStress = 'Modéré';
|
||||
}
|
||||
$niveauStress = $calculator->determineLevel($totalPoints);
|
||||
|
||||
// Enregistrement si l'utilisateur est connecté
|
||||
if (Auth::check()) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Information;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InformationController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$informations = Information::where('is_published', true)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(6);
|
||||
|
||||
return view('informations.index', compact('informations'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$information = Information::where('is_published', true)->findOrFail($id);
|
||||
|
||||
return view('informations.show', compact('information'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Information extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'information';
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'content',
|
||||
'category',
|
||||
'image_url',
|
||||
'is_published',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
}
|
||||
@@ -2,9 +2,15 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StressEvent extends Model
|
||||
{
|
||||
//
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'event_name',
|
||||
'points',
|
||||
];
|
||||
}
|
||||
|
||||
+22
-23
@@ -2,61 +2,60 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'id_role',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function emotionRecords()
|
||||
public function role(): BelongsTo
|
||||
{
|
||||
return $this->hasMany(EmotionRecord::class);
|
||||
return $this->belongsTo(Role::class, 'id_role');
|
||||
}
|
||||
|
||||
public function favoritedBy()
|
||||
public function emotionRecords(): HasMany
|
||||
{
|
||||
return $this->hasMany(EmotionRecord::class, 'user_id');
|
||||
}
|
||||
|
||||
public function favoritedActivities(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(RelaxationActivity::class, 'favorites', 'id_user', 'id_activite');
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
// Autorise l'accès si l'utilisateur est actif et a le rôle 'Admin'
|
||||
return $this->is_active && $this->role && $this->role->libelle === 'Admin';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
if (config('app.env') === 'production' || config('app.env') === 'local') {
|
||||
\Illuminate\Support\Facades\URL::forceScheme('https');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\AuthenticateSession;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
use Filament\Pages;
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Widgets;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
->id('admin')
|
||||
->path('admin')
|
||||
->brandName('CESIZen')
|
||||
->homeUrl('/')
|
||||
->colors([
|
||||
'primary' => Color::Amber,
|
||||
])
|
||||
->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\\Filament\\Admin\\Resources')
|
||||
->discoverPages(in: app_path('Filament/Admin/Pages'), for: 'App\\Filament\\Admin\\Pages')
|
||||
->pages([
|
||||
Pages\Dashboard::class,
|
||||
])
|
||||
->discoverWidgets(in: app_path('Filament/Admin/Widgets'), for: 'App\\Filament\\Admin\\Widgets')
|
||||
->widgets([
|
||||
Widgets\AccountWidget::class,
|
||||
Widgets\FilamentInfoWidget::class,
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
AuthenticateSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
DisableBladeIconComponents::class,
|
||||
DispatchServingFilamentEvent::class,
|
||||
])
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class StressCalculator
|
||||
{
|
||||
public const LEVEL_HIGH = 'Élevé';
|
||||
public const LEVEL_MODERATE = 'Modéré';
|
||||
public const LEVEL_LOW = 'Faible';
|
||||
|
||||
public function calculateScore(array $points): int
|
||||
{
|
||||
return array_sum($points);
|
||||
}
|
||||
|
||||
public function determineLevel(int $score): string
|
||||
{
|
||||
if ($score >= 300) {
|
||||
return self::LEVEL_HIGH;
|
||||
}
|
||||
|
||||
if ($score >= 150) {
|
||||
return self::LEVEL_MODERATE;
|
||||
}
|
||||
|
||||
return self::LEVEL_LOW;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user