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

Change races to activities #172

Merged
merged 2 commits into from
Apr 8, 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
6 changes: 6 additions & 0 deletions app/pages/dev/dev_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ function DevButton($href, $label)
<?= DevButton("/dev/toast", "Toasts") ?>
<?= DevButton("/dev/random", "Random") ?>
</ul>
</nav>
<b>Migrations</b>
<nav>
<ul>
<?= DevButton("/dev/migrate_activities", "Migration des course") ?>
</ul>
</nav>
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,102 @@
restrict_access(Access::$ADD_EVENTS);

$event_id = get_route_param("event_id");
$race_id = get_route_param("race_id", false);
$activity_id = get_route_param("activity_id", false);
$event = em()->find(Event::class, $event_id);
if (!$event) {
return "this event does not exist";
}
if ($race_id) {
$race = em()->find(Race::class, $race_id);
if ($activity_id) {
$activity = em()->find(Activity::class, $activity_id);
$form_values = [
"name" => $race->name,
"date" => date_format($race->date, "Y-m-d"),
"place" => $race->place
//TODO
"name" => $activity->name,
"date" => date_format($activity->date, "Y-m-d"),
"location_label" => $activity->location_label,
"location_url" => $activity->location_url
];
foreach ($race->categories as $index => $category) {
foreach ($activity->categories as $index => $category) {
$form_values["category_{$index}_name"] = $category->name;
$form_values["category_{$index}_toggle"] = $category->removed ? 0 : 1;
}
} else {
$race = new Race();
$activity = new Activity();
}

$type_array = ["RACE" => "Course", "TRAINING" => "Entraînement", "OTHER" => "Autre"];

$v = new Validator($form_values ?? ["date" => $event->start_date->format("Y-m-d")]);
$name = $v->text("name")->label("Nom de la course")->placeholder()->required();
$name = $v->text("name")->label("Nom de l'activité")->placeholder()->required();
$type = $v->select("type")->options($type_array)->label("Type d'activité");
$date = $v->date("date")
->label("Date")
->min($event->start_date->format("Y-m-d"), "Doit être après la date de début de l'événement")
->max($event->end_date->format("Y-m-d"), "Doit être avant la date de fin de l'événement")
->required();
$place = $v->text("place")->label("Lieu")->required();
$location_label = $v->text("location_label")->label("Nom du Lieu")->required();
$location_url = $v->url("location_url")->label("URL du lieu");
$description = $v->textarea("description")->label("Description de l'activité");

$category_rows = [];
foreach ($race->categories as $index => $category) {
foreach ($activity->categories as $index => $category) {
$category_rows[$index]['name'] = $v->text("category_{$index}_name")->required();
$category_rows[$index]['toggle'] = $v->switch("category_{$index}_toggle")->set_labels(" ", "Supprimer");
}


if ($v->valid()) {
$race->set($name->value, date_create($date->value), $place->value, $event);
foreach ($race->categories as $index => $category) {
$activity->set($name->value, date_create($date->value), $event, $location_label->value, $location_url->value, $description->value);
$activity->type = ActivityType::from($type->value);
foreach ($activity->categories as $index => $category) {
$category->name = $category_rows[$index]['name']->value;
$category->removed = !$category_rows[$index]['toggle']->value ?? 0;
// TODO change this later if we want to deal with soft delete
if ($category->removed /* && !count($category->entries)*/) {
em()->remove($category);
$race->categories->removeElement($category);
$activity->categories->removeElement($category);
}
}
$new_categories = $_POST["new_categories"] ?? [];
foreach ($new_categories as $category_name) {
if ($category_name) {
$category = new Category();
$category->name = $category_name;
$category->race = $race;
$race->categories[] = $category;
$category->activity = $activity;
$activity->categories[] = $category;
}
}
em()->persist($race);
em()->persist($activity);
em()->flush();
redirect("/evenements/$event->id");
}

page($race_id ? "{$race->name} : Modifier" : "Ajouter une course")->css("race_edit.css");
page($activity_id ? "{$activity->name} : Modifier" : "Ajouter une activité")->css("activity_edit.css");
?>
<form method="post">
<nav id="page-actions">
<a href="/evenements/<?= $event_id ?>" class="secondary">
<i class="fas fa-xmark"></i> Annuler
</a>
<button type="submit">
<?= $race_id ? "Modifier" : "Créer" ?>
<?= $activity_id ? "Modifier" : "Créer" ?>
</button>
</nav>
<article class="row">
<?= $v->render_validation() ?>
<?= $name->render() ?>
<div class="col-md-6">
<?= $type->render() ?>
</div>
<div class="col-md-6">
<?= $date->render() ?>
</div>
<div class="col-md-6">
<?= $place->render() ?>
<?= $location_label->render() ?>
</div>
<div class="col-md-6">
<?= $location_url->render() ?>
</div>
<?= $description->render() ?>
<div class="col-auto">
<h2>Catégories</h2>
</div>
Expand All @@ -93,8 +108,8 @@
Ajouter</button>
</div>
<div id="categories" class="col-12">
<?php if (count($race->categories)):
foreach ($race->categories as $index => $category):
<?php if (count($activity->categories)):
foreach ($activity->categories as $index => $category):
$entry_count = count($category->entries); ?>
<?= "$entry_count inscrits" ?>
<div class="category-row">
Expand Down
83 changes: 83 additions & 0 deletions app/pages/events/activity_view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
restrict_access();

$activity = em()->find(Activity::class, get_route_param("activity_id"));

if ($activity->type == ActivityType::RACE) {
$icon = "fa fa-stopwatch";
} elseif ($activity->type == ActivityType::TRAINING) {
$icon = "fa fa-dumbbell";
} else {
$icon = "fa fa-bowl-food";
}

page($activity->name)->css("event_view.css");
?>

<nav id="page-actions">
<?php $link = $activity->event ? "/evenements/{$activity->event->id}" : "/evenements" ?>
<a href="<?= $link ?>" class="secondary"><i class="fas fa-caret-left"></i> Retour</a>

</nav>

<article>
<header class="center">
<?php if ($activity->type == ActivityType::RACE) {
$type = "Course";
} elseif ($activity->type == ActivityType::TRAINING) {
$type = "Entrainement";
} else {
$type = "Autre";
} ?>

<p>
Type : <kbd>
<?= $type ?>
</kbd>
</p>
<div class="row">
<div>
<?php include app_path() . "/components/start_icon.php" ?>
<span>
<?= "Date : " . format_date($activity->date) ?>
</span>
</div>
</div>
</header>
<?php if ($activity->event->open): ?>
<div class="grid">
<?php $activity_entry = $activity->entries[0] ?? null; ?>
<ul class="fa-ul">
<?php if ($activity_entry?->present): ?>

<li><ins><span class="fa-li"><i class="fa fa-check"></i></span>Inscrit</ins></li>

<?php else: ?>
<del>
<li><span class="fa-li"><i class="fa fa-xmark"></i></span>
<?= $activity_entry ? "Je ne participe pas" : "Pas encore inscrit" ?>
</li>
</del>
<?php endif; ?>
</ul>
<?php if ($activity_entry?->category): ?>
<ul class="fa-ul">
<li><span class="fa-li"><abbr title="Catégorie"><i class="fa fa-person-running"></i></abbr></span>
<?= $activity_entry->category?->name ?>
</li>
</ul>
<?php endif ?>
</div>
<?php if ($activity_entry?->comment): ?>
<div>
<cite>Remarque : </cite>
<?= $activity_entry->comment ?>
</div>
<?php endif; ?>
<?php if ($activity->description): ?>
<h5>Description</h5>
<p>
<?= $activity->description ?>
</p>
<?php endif; ?>
<?php endif ?>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
$raceId = Component::prop("race_id");
$raceEntries = RaceService::getRaceEntries($raceId);
$activityId = Component::prop("activity_id");
$activityEntries = ActivityService::getActivityEntries($activityId);
?>
<?php if (!$raceEntries): ?>
<p style="padding: 1rem" class="center">Pas d'inscrits sur cette course</p>
<?php if (!$activityEntries): ?>
<p style="padding: 1rem" class="center">Pas d'inscrits sur cette activité</p>
<?php return;
endif ?>
<figure>
Expand All @@ -19,7 +19,7 @@
<?php
ob_start();
$totalEntries = 0;
foreach ($raceEntries as $entry): ?>
foreach ($activityEntries as $entry): ?>
<?php if ($entry->present):
$totalEntries++ ?>
<tr class="clickable" tabindex=0 <?= UserModal::props($entry->user->id) ?>>
Expand Down
18 changes: 9 additions & 9 deletions app/pages/events/entry_list/entry_list_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
include_once __DIR__ . "/TotalRow.php";

$eventId = Component::prop("event_id") ?? get_route_param("event_id") ?? throw new Exception("no event selected");
$selectedRaceId = Component::prop("race_id") ?? get_query_param("race_id", false) ?? null;
$races = EventService::getRaceIdList($eventId);
$selectedActivityId = Component::prop("activity_id") ?? get_query_param("activity_id", false) ?? null;
$activities = EventService::getActivityIdList($eventId);
$getProps = fn($isSelected) =>
'role="tab" aria-controls="tab-content" '
. ($isSelected ? 'aria-selected="true" class="contrast" autofocus' : 'class="secondary outline" aria-selected="false"');
?>

<div class="tab-list" role="tablist">
<button hx-get="<?= "/evenements/$eventId/participants/tabs" ?>" <?= $getProps(!$selectedRaceId) ?>>Déplacement</button>
<?php foreach ($races as $race): ?>
<button id="<?= "race$race->id" ?>" hx-swap="innerHTML show:#<?= "race$race->id" ?>:top"
hx-get="<?= "/evenements/$eventId/participants/tabs?race_id=$race->id" ?>"
<?= $getProps($selectedRaceId == $race->id) ?>>
<?= $race->name ?>
<button hx-get="<?= "/evenements/$eventId/participants/tabs" ?>" <?= $getProps(!$selectedActivityId) ?>>Déplacement</button>
<?php foreach ($activities as $activity): ?>
<button id="<?= "activity$activity->id" ?>" hx-swap="innerHTML show:#<?= "activity$activity->id" ?>:top"
hx-get="<?= "/evenements/$eventId/participants/tabs?activity_id=$activity->id" ?>"
<?= $getProps($selectedActivityId == $activity->id) ?>>
<?= $activity->name ?>
</button>
<?php endforeach ?>
</div>

<?= $selectedRaceId ? Component::render(__DIR__ . "/entry_list_tab_race.php", ["race_id" => $selectedRaceId])
<?= $selectedActivityId ? Component::render(__DIR__ . "/entry_list_tab_activity.php", ["activity_id" => $selectedActivityId])
: Component::render(__DIR__ . "/entry_list_tab_event.php", ["event_id" => $eventId]) ?>
2 changes: 1 addition & 1 deletion app/pages/events/event_delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<span>
<i class="fa fa-chevron-right"></i>
Courses:
<?= count($event->races) ?>
<?= count($event->activities) ?>
</span>
<span>
<i class="fa fa-chevron-right"></i>
Expand Down
9 changes: 5 additions & 4 deletions app/pages/events/event_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"end_date" => date_format($event->end_date, "Y-m-d"),
"limit_date" => date_format($event->deadline, "Y-m-d"),
"bulletin_url" => $event->bulletin_url,

"description" => $event->description
];
} else {
$event = new Event();
Expand All @@ -31,9 +31,11 @@
->label("Deadline")->required()
->max($start_date->value ? date_create($start_date->value)->sub(new DateInterval("PT23H59M59S"))->format("Y-m-d") : "", "Doit être avant le jour de départ");
$bulletin_url = $v->url("bulletin_url")->label("Lien vers le bulletin")->placeholder();
$description = $v->textarea("description")->label("Description");

if (!empty($_POST) && $v->valid()) {
$event->set($event_name->value, $start_date->value, $end_date->value, $limit_date->value, $bulletin_url->value ?? "");
$event->description = $description->value;
em()->persist($event);
em()->flush();
redirect("/evenements/$event->id");
Expand Down Expand Up @@ -63,9 +65,8 @@
<div class="col-lg-4">
<?= $limit_date->render() ?>
</div>
<div>
<?= $bulletin_url->render() ?>
</div>
<?= $bulletin_url->render() ?>
<?= $description->render() ?>
</div>
</article>
</form>
Loading
Loading