Commit 082c320e authored by Regis's avatar Regis
Browse files

Merge branch '#88' into 'master'

#88 fix multiple track with same name in event manualy sselection

See merge request a_boiteau/site-vikazimut-stage!49
parents 8d628c93 cf7cb3ed
......@@ -91,6 +91,34 @@ class Track
return $this->totalTime;
}
public function getTotalTimeInHMS(): string
{
$sec = (int)($this->totalTime / 1000);
$hou = 0;
$min = 0;
if ($sec >= 3600) {
$hou = floor($sec / 3600);
$sec = $sec % 3600;
}
if ($sec >= 60) {
$min = floor($sec / 60);
$sec = $sec % 60;
}
if (strlen((string)$hou) === 1) {
$hou = "0".$hou;
}
if (strlen((string)$min) === 1) {
$min = "0".$min;
}
if (strlen((string)$sec) === 1) {
$sec = "0".$sec;
}
return $hou.":".$min.":".$sec;
}
public function setTotalTime(int $totalTime): self
{
$this->totalTime = $totalTime;
......
......@@ -19,9 +19,24 @@ class ModifyParticipantMakeEventCourseType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$tracks = [];
$tracksSimple = [];
$duplicates = [];
$tracks["-"] = null;
foreach ($options['course']->getOrienteer() as $track){
$tracks[$track->getName()] = $track;
foreach ($options['course']->getOrienteer() as $track) {
if (array_key_exists($track->getName(), $duplicates)) {
if ($duplicates[$track->getName()] === 1) {
$timeOfTheTrack = $tracksSimple[$track->getName()]->getTotalTimeInHMS();
$tracks[$track->getName() . " [1] (" . $timeOfTheTrack . ")"] = $tracks[$track->getName() . " (" . $timeOfTheTrack . ")"];
unset($tracks[$track->getName() . " (" . $timeOfTheTrack . ")"]);
}
$duplicates[$track->getName()] += 1;
$tracks[$track->getName() . " [" . $duplicates[$track->getName()] . "] (" . $track->getTotalTimeInHMS() . ")"] = $track;
} else {
$tracks[$track->getName() . " (" . $track->getTotalTimeInHMS() . ")"] = $track;
$tracksSimple[$track->getName()] = $track;
$duplicates[$track->getName()] = 1;
}
}
$builder
->add(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment