Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

added logs when registering to a perm or quitting a perm #312

Merged
merged 8 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions app/Http/Controllers/Admin/PermController.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ public function import()
public function shotgun() {
$perms = Perm::orderby('start')->get();
$user = Auth::user(); // user that make the request
if (!array_key_exists('day', Request::query())) {
return redirect(route('dashboard.perm.shotgun', ['day' => 1]));
}
$day = Request::query()['day'];
if (!$day || $day < 1 || $day > 7) {
return redirect(route('dashboard.perm.shotgun', ['day' => 1]));
}
$perms = $perms->filter(function ($perm) use ($day) {
return date('N', $perm->start) == $day;
});
foreach ($perms as $perm) {
$found = false;
foreach ($perm->permanenciers as $permanencier) {
Expand All @@ -336,11 +346,19 @@ public function shotgun() {
$perm->isOpen = $open < new \DateTime('now');
}
setlocale(LC_TIME, 'fr_FR.utf8');
return view('dashboard.perms.shotgun', compact('perms'));
return view('dashboard.perms.shotgun', compact('perms', 'day'));
}

public function doShotgun($id) {
$redirection = redirect(route('dashboard.perm.shotgun'));
if (!array_key_exists('day', Request::query())) {
$day = 1;
} else {
$day = Request::query()['day'];
if (!$day || $day < 1 || $day > 7) {
$day = 1;
}
}
$redirection = redirect(route('dashboard.perm.shotgun', ['day' => $day]));
$user = Auth::user();
$perm = Perm::find($id);
if ($user->is_newcomer) {
Expand Down Expand Up @@ -379,14 +397,23 @@ public function doShotgun($id) {

if($perm->nbr_permanenciers > $perm->permanenciers()->count()){
$perm->permanenciers()->attach($user->id, ['respo' => false]);
file_put_contents('./logs.log', '['.date('j/n/o H:i:s').']'.' '.$user->id.' vient de shotgun la perm '.$id."\n", FILE_APPEND);
return $redirection->withSuccess('Tu as bien été ajouté à la perm !');
} else {
return $redirection->withError('Cette perm est complète !');
}
}

public function doUnshotgun($id) {
$redirection = redirect(route('dashboard.perm.shotgun'));
if (!array_key_exists('day', Request::query())) {
$day = 1;
} else {
$day = Request::query()['day'];
if (!$day || $day < 1 || $day > 7) {
$day = 1;
}
}
$redirection = redirect(route('dashboard.perm.shotgun', ['day' => $day]));
$user = Auth::user();
$perm = Perm::find($id);
$found = false;
Expand All @@ -410,6 +437,7 @@ public function doUnshotgun($id) {
return $redirection->withError('Trop tard, tu ne peux pas quitter une perm moins de 48 heure avant le début.');
}
$perm->permanenciers()->detach($user->id);
file_put_contents('./logs.log', '['.date('j/n/o H:i:s').']'.' '.$user->id.' vient de quitter la perm '.$id."\n", FILE_APPEND);
return $redirection->withSuccess('Tu as bien quitté la perm.');
}

Expand Down
Empty file added public/logs.log
Empty file.
22 changes: 17 additions & 5 deletions resources/views/dashboard/perms/shotgun.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,47 @@
<div class="callout callout-info">
<h4>Shotgun des permanences</h4>
</div>
<div class="box-body">
<a href="{{ route('dashboard.perm.shotgun', ['day' => 1]) }}">
<button class="btn btn-primary" {{ $day == 1 ? 'disabled' : '' }}>Lundi</button>
</a>
<a href="{{ route('dashboard.perm.shotgun', ['day' => 2]) }}">
<button class="btn btn-primary" {{ $day == 2 ? 'disabled' : '' }}>Mardi</button>
</a>
<a href="{{ route('dashboard.perm.shotgun', ['day' => 3]) }}">
<button class="btn btn-primary" {{ $day == 3 ? 'disabled' : '' }}>Mercredi</button>
</a>
<a href="{{ route('dashboard.perm.shotgun', ['day' => 4]) }}">
<button class="btn btn-primary" {{ $day == 4 ? 'disabled' : '' }}>Jeudi</button>
</a>
</div>
<div class="box box-default">
<div class="box-body table-responsive no-padding">
<table class="table table-hover align-middle text-center">
<tbody>
<tr>
<th>Rejoindre</th>
<th>Nom</th>
<th>Description</th>
<th>Lieu</th>
<th>Jour</th>
<th>Début</th>
<th>Fin</th>
<th>Permanenciers</th>
<th>Description</th>
<th>Points</th>
</tr>
@foreach ($perms as $perm)
<tr class="align-middle">
<td>
<form action="{{ url('dashboard/perm/'.($perm->isAlreadyIn ? 'unshotgun' : 'shotgun').'/'.$perm->id) }}" method="post">
<form action="{{ url('dashboard/perm/'.($perm->isAlreadyIn ? 'unshotgun' : 'shotgun').'/'.$perm->id.'?day='.$day) }}" method="post">
<button class="btn btn-xl {{ $perm->isAlreadyIn ? 'btn-danger' : 'btn-success' }}" {{ $perm->isOpen ? '' : 'disabled' }} type="submit">{{ $perm->isAlreadyIn ? 'Quitter' : "S'inscrire" }}</button>
</form>
</td>
<td>{{ $perm->type->name }}</td>
<td>{{ $perm->description }}</td>
<td>{{ $perm->place }}</td>
<td>{{ strftime('%A', $perm->start) }}</td>
<td>{{ date('G\\Hi', $perm->start) }}</td>
<td>{{ date('G\\Hi', $perm->end) }}</td>
<td>{{ $perm->permanenciers->count().'/'.$perm->nbr_permanenciers }}</td>
<td>{{ $perm->description }}</td>
<td>{{ $perm->type->points }}</td>
</tr>
@endforeach
Expand Down
4 changes: 2 additions & 2 deletions resources/views/dashboard/perms/shotguned.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@
<tbody>
<tr>
<th>Nom</th>
<th>Description</th>
<th>Lieu</th>
<th>Date</th>
<th>Début</th>
<th>Fin</th>
<th>Permanenciers</th>
<th>Description</th>
<th>Points</th>
<th>Quitter</th>
</tr>
@foreach ($perms as $perm)
<tr class="align-middle">
<td>{{ $perm->type->name }}</td>
<td>{{ $perm->description }}</td>
<td>{{ $perm->place }}</td>
<td>{{ date('j/n/y', $perm->start) }}</td>
<td>{{ date('G\\Hi', $perm->start) }}</td>
<td>{{ date('G\\Hi', $perm->end) }}</td>
<td>{{ $perm->permanenciers->count().'/'.$perm->nbr_permanenciers }}</td>
<td>{{ $perm->description }}</td>
<td>{{ $perm->type->points }}</td>
<td>
<form action="{{ url('dashboard/perm/unshotgun/'.$perm->id) }}" method="post">
Expand Down
Loading