Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Car management 🚗 #318

Merged
merged 5 commits into from
Dec 11, 2024
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
21 changes: 8 additions & 13 deletions app/pages/events/entry_list/entry_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

$event_id = get_route_param("event_id");
$event_infos = EventService::getEventInfos($event_id);
page($event_infos->name . " : Inscrits")->css("entry_list.css") ?>

<?= actions()
->back("/evenements/$event_id")
->if(
$event_infos->open && check_auth(Access::$ADD_EVENTS),
fn($a) => $a->button("Copier le tableau", attributes: ["onclick" => "selectTable()"])
) ?>
$is_simple = get_query_param("is_simple", false, false);
?>

<?php if ($event_infos->open && check_auth(Access::$ADD_EVENTS)): ?>
<div class="entries-header"><button onclick="selectTable()"> Copier le tableau</button></div>
<?php endif ?>
<?php if (!$event_infos->open): ?>
<p class="center">
<?php "L'évenement de cette course n'est pas encore ouvert 🙃" ?>
<?php "L'évenement n'est pas encore ouvert 🙃" ?>
</p>
<?php else: ?>
<div id="tabs" hx-target="#tabs" hx-swap="innerHTML">
<?= component(__DIR__ . "/entry_list_tabs.php")->render(["event_id" => $event_id]) ?>
<?= $is_simple ? component(__DIR__ . "/entry_list_tab_activity.php")->render(["activity_id" => EventService::getActivityIdList($event_id)[0]->id]) : component(__DIR__ . "/entry_list_tabs.php")->render(["event_id" => $event_id]) ?>
</div>
<script src="/assets/js/select-table.js"></script>
<?php endif ?>

<?= UserModal::renderRoot() ?>
<?php endif ?>
2 changes: 2 additions & 0 deletions app/pages/events/entry_list/entry_list_tab_activity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
include_once __DIR__ . "/TotalRow.php";

$activityId = Component::prop("activity_id");
$activityEntries = ActivityService::getActivityEntries($activityId);
?>
Expand Down
220 changes: 120 additions & 100 deletions app/pages/events/view/event_view.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
restrict_access();

include __DIR__ . "/../eventUtils.php";

$event = EventService::getEventWithAllData(get_route_param('event_id'), User::getCurrent()->id);
$user_id = User::getCurrent()->id;
$event = EventService::getEventWithAllData(get_route_param('event_id'), $user_id);
if (!$event->open) {
restrict_access(Access::$ADD_EVENTS);
}

$tab = get_query_param("tab", false, false);

$can_edit = check_auth(Access::$ADD_EVENTS);
$today_date = date_create("today");
$deadline_in_future = $event->deadline >= $today_date;
Expand All @@ -16,7 +17,7 @@
$totalEntryCount = EventService::getEntryCount($event->id);
$is_simple = $event->type == EventType::Simple;

page($event->name)->css("event_view.css");
page($event->name)->css("event_view.css")->css("entry_list.css");

?>

Expand All @@ -40,107 +41,126 @@

<?= $is_simple ? RenderActivityEntry($event->activities[0], $can_register) : RenderEventEntry($entry, $event, $can_edit) ?>

<?php if ($is_simple) {
require __DIR__ . "/ActivityView.php";
return;
}
<sl-tab-group>
<sl-tab slot="nav" panel="information" <?= $tab ? "" : "active" ?>>
Informations
</sl-tab>
<sl-tab slot="nav" panel="entry-list" hx-trigger="load"
hx-post="/evenements/<?= $event->id ?>/participants<?= $is_simple ? "?is_simple=true" : "" ?>"
hx-target="#entry-list" <?= ($tab == "participants") ? "active" : "" ?>>
Participants
</sl-tab>
<?php if (Feature::Carpooling->on()): ?>
<sl-tab slot="nav" panel="vehicles" hx-trigger="load" hx-post="/evenements/<?= $event->id ?>/vehicules"
hx-target="#vehicles" <?= ($tab == "vehicules") ? "active" : "" ?>>
Véhicules
</sl-tab>
<?php endif ?>

$deadline_class = $deadline_in_future ? "" : ($entry?->present ? "completed" : "missed");
$start_class = $event->start_date < $today_date ? $deadline_class : "";
$end_class = $event->end_date < $today_date ? $deadline_class : "";
<sl-tab-panel name="information">
<?php if ($is_simple) {
require __DIR__ . "/ActivityView.php";
} else {

?>
<article>
<header>
<div class="row g-2 center align-center">
<div class="col-12">
<?= RenderTimeline($event, !!$entry?->present) ?>
</div>
<div class="col-12">
<div class="row g-2 center">
<?php if ($event->bulletin_url): ?>
<div class="col-12 col-lg-auto">
<a role="button" href="<?= $event->bulletin_url ?>" target="_blank"> <i
class="fa fa-paperclip"></i>
Bulletin
<i class="fa fa-external-link"></i></a>
</div>
<?php endif ?>
<?php if ($event->open && $totalEntryCount): ?>
<div class="col-12 col-lg-auto">
<a role="button" href="/evenements/<?= $event->id ?>/participants" class="secondary">
<i class="fas fa-users"></i> Participants
<?= "($totalEntryCount)" ?>
</a>
$deadline_class = $deadline_in_future ? "" : ($entry?->present ? "completed" : "missed");
$start_class = $event->start_date < $today_date ? $deadline_class : "";
$end_class = $event->end_date < $today_date ? $deadline_class : "";

?>
<article>
<header>
<div class="row g-2 center align-center">
<div class="col-12">
<?= RenderTimeline($event, !!$entry?->present) ?>
</div>
<?php endif ?>
</div>
</div>
</div>
</header>
<section>
<?php if (count($event->activities)): ?>
<h3>Activités</h3>
<?php foreach ($event->activities as $i => $activity):
$activity_entry = $activity->entries[0] ?? null; ?>
<details>
<summary>
<?= ConditionalIcon($activity_entry && $activity_entry->present) . " " ?>
<?= $activity->name ?>
<i class="fa <?= $activity->type->toIcon() ?>" title=<?= $activity->type->toName() ?>></i>
</summary>
<?= RenderActivityEntry($activity) ?>
<p class="grid">
<span><i class="fa fa-calendar fa-fw"></i>
<?= format_date($activity->date) ?>
</span>
<?php if ($activity->location_label): ?>
<span>
<i class="fa fa-location-dot fa-fw"></i>
<?php if ($activity->location_url): ?>
<a href=<?= $activity->location_url ?> target="_blank"><?= $activity->location_label ?></a>
<?php else: ?>
<?= $activity->location_label ?>
<div class="col-12">
<div class="row g-2 center">
<?php if ($event->bulletin_url): ?>
<div class="col-12 col-lg-auto">
<a role="button" href="<?= $event->bulletin_url ?>" target="_blank"> <i
class="fa fa-paperclip"></i>
Bulletin
<i class="fa fa-external-link"></i></a>
</div>
<?php endif ?>
</span>
<?php endif ?>
</p>
<p>
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>'>
<i class="fa fa-circle-info"></i>
Détails</a>
<?php if ($can_edit): ?>
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/modifier'>
<i class="fa fa-pen"></i>
Modifier</a>
<a role="button" class="outline error"
href="/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/supprimer">
<i class="fa fa-trash"></i>
Supprimer
</a>
</div>
</div>
</div>
</header>
<section>
<?php if (count($event->activities)): ?>
<h3>Activités</h3>
<?php foreach ($event->activities as $i => $activity):
$activity_entry = $activity->entries[0] ?? null; ?>
<details>
<summary>
<?= ConditionalIcon($activity_entry && $activity_entry->present) . " " ?>
<?= $activity->name ?>
<i class="fa <?= $activity->type->toIcon() ?>" title=<?= $activity->type->toName() ?>></i>
</summary>
<?= RenderActivityEntry($activity) ?>
<p class="grid">
<span><i class="fa fa-calendar fa-fw"></i>
<?= format_date($activity->date) ?>
</span>
<?php if ($activity->location_label): ?>
<span>
<i class="fa fa-location-dot fa-fw"></i>
<?php if ($activity->location_url): ?>
<a href=<?= $activity->location_url ?> target="_blank"><?= $activity->location_label ?></a>
<?php else: ?>
<?= $activity->location_label ?>
<?php endif ?>
</span>
<?php endif ?>
</p>
<div class="buttons-grid">
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>'>
<i class="fa fa-circle-info"></i>
Détails</a>
<?php if ($can_edit): ?>
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/modifier'>
<i class="fa fa-pen"></i>
Modifier</a>
<a role="button" class="outline error"
href="/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/supprimer">
<i class="fa fa-trash"></i>
Supprimer
</a>

<?php endif ?>
</p>
</details>
<hr>
<?php endforeach; ?>
<?php endif; ?>
<?php endif ?>
</div>
</details>
<hr>
<?php endforeach; ?>
<?php endif; ?>


<?php if ($can_edit): ?>
<p>
<a role=button class="secondary" href="/evenements/<?= $event->id ?>/activite/nouveau">
<i class="fas fa-plus"></i> Ajouter une activité</a>
</p>
<?php endif ?>
</section>
<?php if ($event->description): ?>
<br>
<section>
<h3>Description</h3>
<?= (new Parsedown)->text($event->description) ?>
</section>
<?php if ($can_edit): ?>
<p>
<a role=button class="secondary" href="/evenements/<?= $event->id ?>/activite/nouveau">
<i class="fas fa-plus"></i> Ajouter une activité</a>
</p>
<?php endif ?>
<?php if ($event->description): ?>
<br>
<section>
<h3>Description</h3>
<?= (new Parsedown)->text($event->description) ?>
</section>
<?php else: ?>
Pas encore de description pour cet événement 🪶
<?php endif ?>
</section>
</article>
<?php } ?>
</sl-tab-panel>
<sl-tab-panel name="entry-list" id="entry-list"></sl-tab-panel>
<?php if (Feature::Carpooling->on()): ?>
<sl-tab-panel name="vehicles" id="vehicles"></sl-tab-panel>
<?php endif ?>
</article>
</sl-tab-group>

<?= UserModal::renderRoot() ?>
39 changes: 39 additions & 0 deletions app/pages/vehicle/vehicle_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
restrict_access();

$form = new Validator(action: "confirm-delete");

$event_id = get_route_param("event_id");
$vehicle_id = get_route_param("vehicle_id");
$event = em()->find(Event::class, $event_id);
$vehicle = em()->find(Vehicle::class, $vehicle_id);
if (!$event) {
force_404("the event of id $event_id doesn't exist");
}
if (!$vehicle) {
force_404("the vehicle of id $vehicle_id doesn't exist");
}
if ($form->valid()) {
logger()->info("Véhicule {vehicle_id} deleted by user {currentUserLogin}", ['vehicle_id' => $vehicle_id, 'currentUserLogin' => User::getCurrent()->login]);
em()->remove($vehicle);
em()->flush();
Toast::error("Véhicule supprimé");
redirect("/evenements/$event_id?tab=vehicules");
}

page("Confirmation de suppression");
?>
<form method="post">
<div class="row center">
<?= $form->render_validation() ?>
<p>Sûr de vouloir supprimer le véhicule
<?= "$vehicle->id" ?> ? Il sera définitivement supprimé!!
</p>
<div class="col-auto">
<a class="secondary" role="button" href="/evenements/<?= $event_id ?>?tab=vehicules">Annuler</a>
</div>
<div class="col-auto">
<button type="submit" name="delete" value="true" class="destructive">Supprimer</button>
</div>
</div>
</form>
Loading
Loading