Commit 395a1748 authored by Regis's avatar Regis
Browse files

Merge branch '#86' into 'master'

82+85

See merge request a_boiteau/site-vikazimut-stage!47
parents de736897 8bfac424
......@@ -51,6 +51,15 @@ class CourseController extends AbstractController
} else {
$courses = $allCourses;
}
foreach ($courses as $course){
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
if ($dateDiff->invert === 1) {
unset($courses[array_search($course, $courses)]);
}
}
}
return $this->render(
'course/index.html.twig',
......@@ -65,11 +74,25 @@ class CourseController extends AbstractController
*/
public function tracks($id, TrackStatistics $statistics, Request $request): Response
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
if ($dateDiff->invert === 1) {
return $this->render(
'course/notPublished.html.twig',
[
'name' => $course->getName(),
'dayLeft' => $dateDiff->format("%a"),
'timeLeft' => $dateDiff->format("%hh %im %ss"),
]
);
}
}
$importTab = 0;
$success = "";
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
throw $this->createNotFoundException("Ce parcours n'existe pas : ".$id);
throw $this->createNotFoundException("Ce parcours n'existe pas : " . $id);
}
$xml = $course->getXml();
$simplexml = simplexml_load_string($xml);
......@@ -118,8 +141,22 @@ class CourseController extends AbstractController
public function courseInfo($id, TrackStatistics $statistics): Response
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
if ($dateDiff->invert === 1) {
return $this->render(
'course/notPublished.html.twig',
[
'name' => $course->getName(),
'dayLeft' => $dateDiff->format("%a"),
'timeLeft' => $dateDiff->format("%hh %im %ss"),
]
);
}
}
if (!$course) {
throw $this->createNotFoundException('Ce parcours n\'existe pas : '.$id);
throw $this->createNotFoundException('Ce parcours n\'existe pas : ' . $id);
}
$xml = $course->getXml();
$simplexml = simplexml_load_string($xml);
......@@ -153,7 +190,7 @@ class CourseController extends AbstractController
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if ($course == null) {
throw $this->createNotFoundException('Ce parcours n\'existe pas : '.$id);
throw $this->createNotFoundException('Ce parcours n\'existe pas : ' . $id);
}
return new JsonResponse(
......@@ -219,6 +256,15 @@ class CourseController extends AbstractController
public function worldMap(): Response
{
$courses = $this->getDoctrine()->getRepository(Course::class)->findAll();
foreach ($courses as $course){
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
if ($dateDiff->invert === 1) {
unset($courses[array_search($course, $courses)]);
}
}
}
return $this->render(
'course/worldmap.html.twig',
......
......@@ -3,6 +3,8 @@
namespace App\Controller;
use App\Entity\Event;
use App\Entity\EventCourse;
use App\Entity\Participant;
use App\Entity\ParticipantMakeEventCourse;
use App\Entity\Track;
use PHPUnit\Util\Exception;
......@@ -26,6 +28,24 @@ class DataController extends AbstractController
public function get_courses(): JsonResponse
{
$courses = $this->getDoctrine()->getRepository(Course::class)->findAll();
foreach ($courses as $course) {
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
if ($dateDiff->invert === 1) {
unset($courses[array_search($course, $courses)]);
}
}
}
foreach ($courses as $course) {
$courseDate = $course->getEndDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
if ($dateDiff->invert === 0) {
unset($courses[array_search($course, $courses)]);
}
}
}
$dataCourses = [];
foreach ($courses as $course) {
$info = array(
......@@ -57,7 +77,7 @@ class DataController extends AbstractController
$response = new Response($fileContent);
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$id."."."xml"
$id . "." . "xml"
);
$response->headers->set('Content-Disposition', $disposition);
......@@ -97,7 +117,7 @@ class DataController extends AbstractController
return $this->json(["error" => "invalid id"]);
}
$encryptVariables = json_decode(file_get_contents((dirname(__DIR__, 2).'/config/secret/.image.keys')), true);
$encryptVariables = json_decode(file_get_contents((dirname(__DIR__, 2) . '/config/secret/.image.keys')), true);
$key = $encryptVariables["image_file_key"];
$initializationVector = $encryptVariables["image_file_iv"];
$data = $this->encryptFile($key, $initializationVector, $course->getImage());
......@@ -105,7 +125,7 @@ class DataController extends AbstractController
$gzData = gzencode($data);
$response = new Response($gzData);
$compressedFilename = $id.".bin".".gz";
$compressedFilename = $id . ".bin" . ".gz";
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/octet-stream');
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $compressedFilename);
......@@ -128,7 +148,7 @@ class DataController extends AbstractController
$response = new Response($fileContent);
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$id."."."kml"
$id . "." . "kml"
);
$response->headers->set('Content-Disposition', $disposition);
......
......@@ -9,9 +9,11 @@ use App\Entity\ParticipantMakeEventCourse;
use App\Entity\User;
use App\Form\EventType;
use App\Form\EventCourseType;
use App\Form\ManuallySetPenaltyOfParticipantMakeEventCourseType;
use App\Form\ModifyEventCourseType;
use App\Form\ModifyParticipantMakeEventCourseType;
use App\Form\ParticipantType;
use App\Model\ManuallySetPenaltyOfParticipantMakeEventCourse;
use App\Model\ModifyEventCourse;
use App\Model\ModifyParticipantMakeEventCourse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
......@@ -116,6 +118,16 @@ class EventController extends AbstractController
}
}
$manuallySetPenaltyOfParticipantMakeEventCourse = new ManuallySetPenaltyOfParticipantMakeEventCourse();
$manuallySetPenaltyOfParticipantMakeEventCourseForm = $this->createForm(ManuallySetPenaltyOfParticipantMakeEventCourseType::class, $manuallySetPenaltyOfParticipantMakeEventCourse, ['event' => $event]);
$manuallySetPenaltyOfParticipantMakeEventCourseForm->handleRequest($request);
if ($manuallySetPenaltyOfParticipantMakeEventCourseForm->isSubmitted()) {
if ($manuallySetPenaltyOfParticipantMakeEventCourse->getEventCourse() !== null && $manuallySetPenaltyOfParticipantMakeEventCourse->getParticipant() !== null) {
$manuallySetPenaltyOfParticipantMakeEventCourse->modify($this->getDoctrine()->getManager(), $participantMakeEventCourseRepository);
return $this->redirect($request->getUri());
}
}
if (in_array($event, $user->getEvents()->toArray()) || in_array('ROLE_ADMIN', $user->getRoles())) {
return $this->render(
......@@ -126,6 +138,7 @@ class EventController extends AbstractController
'participants' => $event->getParticipants(),
'ranking' => $event->extractRanking($this->getDoctrine()->getRepository(ParticipantMakeEventCourse::class)),
'forms' => $formsView,
'manuallySetPenaltyFormView' => $manuallySetPenaltyOfParticipantMakeEventCourseForm->createView(),
]
);
} else {
......@@ -270,13 +283,13 @@ class EventController extends AbstractController
$eventCourse->generateParticipantMakeEventCourse($entityManager);
return $this->redirect($request->getUri());
}
$modifyFormsView=[];
foreach ($this->getDoctrine()->getRepository(Event::class)->find($id)->getEventCourses() as $eventCourse){
$modifyFormsView = [];
foreach ($this->getDoctrine()->getRepository(Event::class)->find($id)->getEventCourses() as $eventCourse) {
$modifyEventCourse = new ModifyEventCourse($eventCourse);
$modifyEventCourseForm = $this->createForm(ModifyEventCourseType::class, $modifyEventCourse,);
$modifyFormsView[$eventCourse->getId()] = $modifyEventCourseForm->createView();
$modifyEventCourseForm->handleRequest($request);
if ($modifyEventCourseForm->isSubmitted() && $modifyEventCourseForm->isValid() && $modifyEventCourse->getId()===$eventCourse->getId()) {
if ($modifyEventCourseForm->isSubmitted() && $modifyEventCourseForm->isValid() && $modifyEventCourse->getId() === $eventCourse->getId()) {
$modifyEventCourse->modify($this->getDoctrine()->getRepository(EventCourse::class), $this->getDoctrine()->getManager());
return $this->redirect($request->getUri());
}
......@@ -349,6 +362,7 @@ class EventController extends AbstractController
if ($error == "") {
$success = "success";
}
return $this->redirect($request->getUri());
}
return $this->render('event/event_info.html.twig',
......
......@@ -98,6 +98,16 @@ class Course
*/
private $eventCourses;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $startDate=null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $endDate=null;
public function __construct()
{
$this->orienteer = new ArrayCollection();
......@@ -326,4 +336,30 @@ class Course
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(?\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(?\DateTimeInterface $endDate): self
{
$this->endDate = $endDate;
return $this;
}
}
......@@ -122,9 +122,9 @@ class Event
$participantMakeEventCourse = $participantMakeEventCourseRepository->find(array("eventCourse" => $eventCourse, "participant" => $participant));
if ($participantMakeEventCourse->getTrack() !== null) {
$participantMakeEventCourse->extractFromTrack();
$time = $participantMakeEventCourse->getTrack()->getTotalTime() + ($participantMakeEventCourse->getNbMissingPunchPenalty() * $participantMakeEventCourse->getEventCourse()->getMissingPunchPenalty() * 60000);
$time = $participantMakeEventCourse->getTrack()->getTotalTime() + ($participantMakeEventCourse->getNbMissingPunchPenalty() * $participantMakeEventCourse->getEventCourse()->getMissingPunchPenalty() * 1000);
if ($participantMakeEventCourse->getEventCourse()->getOverTimePenalty() === 0) {
$time += ($participantMakeEventCourse->getNbOverTimePenalty() * $participantMakeEventCourse->getEventCourse()->getOverTimePenalty() * 60000);
$time += ($participantMakeEventCourse->getNbOverTimePenalty() * $participantMakeEventCourse->getEventCourse()->getOverTimePenalty() * 1000);
}
if ($minTime > $time) {
$minTime = $time;
......@@ -134,9 +134,9 @@ class Event
foreach ($this->participant as $participant) {
$participantMakeEventCourse = $participantMakeEventCourseRepository->find(array("eventCourse" => $eventCourse, "participant" => $participant));
if ($participantMakeEventCourse->getTrack() !== null) {
$time = $participantMakeEventCourse->getTrack()->getTotalTime() + ($participantMakeEventCourse->getNbMissingPunchPenalty() * $participantMakeEventCourse->getEventCourse()->getMissingPunchPenalty() * 60000);
$time = $participantMakeEventCourse->getTrack()->getTotalTime() + ($participantMakeEventCourse->getNbMissingPunchPenalty() * $participantMakeEventCourse->getEventCourse()->getMissingPunchPenalty() * 1000);
if ($participantMakeEventCourse->getEventCourse()->getOverTimePenalty() === 0) {
$time += ($participantMakeEventCourse->getNbOverTimePenalty() * $participantMakeEventCourse->getEventCourse()->getOverTimePenalty() * 60000);
$time += ($participantMakeEventCourse->getNbOverTimePenalty() * $participantMakeEventCourse->getEventCourse()->getOverTimePenalty() * 1000);
}
$participantMakeEventCourse->setScore(1000 * (($minTime * 1000) / ($time * 1000)));
}
......
......@@ -49,6 +49,16 @@ class ParticipantMakeEventCourse
*/
private bool $modified = false;
/**
* @ORM\Column(type="boolean")
*/
private bool $pmPenaltyManuallySet = false;
/**
* @ORM\Column(type="boolean")
*/
private bool $otPenaltyManuallySet = false;
public function getEventCourse(): ?EventCourse
{
return $this->eventCourse;
......@@ -137,6 +147,38 @@ class ParticipantMakeEventCourse
$this->modified = $modified;
}
/**
* @return bool
*/
public function isPmPenaltyManuallySet(): bool
{
return $this->pmPenaltyManuallySet;
}
/**
* @param bool $pmPenaltyManuallySet
*/
public function setPmPenaltyManuallySet(bool $pmPenaltyManuallySet): void
{
$this->pmPenaltyManuallySet = $pmPenaltyManuallySet;
}
/**
* @return bool
*/
public function isOtPenaltyManuallySet(): bool
{
return $this->otPenaltyManuallySet;
}
/**
* @param bool $otPenaltyManuallySet
*/
public function setOtPenaltyManuallySet(bool $otPenaltyManuallySet): void
{
$this->otPenaltyManuallySet = $otPenaltyManuallySet;
}
public function remove(ObjectManager $entityManager)
{
$entityManager->remove($this);
......@@ -145,26 +187,30 @@ class ParticipantMakeEventCourse
public function extractFromTrack()
{
$this->nbOverTimePenalty = 0;
$this->nbMissingPunchPenalty = 0;
$this->score = 0;
if ($this->track !== null) {
if ($this->eventCourse->getMaxTime() !== 0) {
$overTime = $this->track->getTotalTime() - $this->eventCourse->getMaxTime();
if ($this->eventCourse->getMaxTime() !== 0 && $overTime > 0) {
if ($overTime / 1000 >= 60) {
$this->nbOverTimePenalty = floor(($overTime / 1000) / 60);
$overTime = ($overTime / 1000) % $this->nbOverTimePenalty;
}
if ($overTime = !0) {
$this->nbOverTimePenalty += 1;
if ($this->otPenaltyManuallySet === false) {
$this->nbOverTimePenalty = 0;
if ($this->eventCourse->getMaxTime() !== 0) {
$overTime = $this->track->getTotalTime() - $this->eventCourse->getMaxTime();
if ($this->eventCourse->getMaxTime() !== 0 && $overTime > 0) {
if ($overTime / 1000 >= 60) {
$this->nbOverTimePenalty = floor(($overTime / 1000) / 60);
$overTime = ($overTime / 1000) % $this->nbOverTimePenalty;
}
if ($overTime = !0) {
$this->nbOverTimePenalty += 1;
}
}
}
}
foreach ($this->track->getControlPoints() as $controlPoint) {
if ($controlPoint->punchTime === 0 and $controlPoint->controlPoint !== 0) {
$this->nbMissingPunchPenalty += 1;
if ($this->pmPenaltyManuallySet === false) {
$this->nbMissingPunchPenalty = 0;
foreach ($this->track->getControlPoints() as $controlPoint) {
if ($controlPoint->punchTime === 0 and $controlPoint->controlPoint !== 0) {
$this->nbMissingPunchPenalty += 1;
}
}
}
......
<?php
namespace App\Form;
use App\Entity\Event;
use App\Model\ManuallySetPenaltyOfParticipantMakeEventCourse;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class ManuallySetPenaltyOfParticipantMakeEventCourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$event = $options['event'];
$participants = [];
$participants["-"] = null;
foreach ($options['event']->getParticipants() as $participant) {
$participants[$participant->getNickName()] = $participant;
}
$eventCourses = [];
$eventCourses["-"] = null;
foreach ($options['event']->getEventCourses() as $eventCourse) {
$eventCourses[$eventCourse->getCourse()->getName()] = $eventCourse;
}
$builder
->add('participant', ChoiceType::class,
[
'label' => "form.ManuallySetPenalty.participant",
'choices' => $participants,
]
)
->add('eventCourse', ChoiceType::class,
[
'label' => "form.ManuallySetPenalty.eventCourse",
'choices' => $eventCourses,
]
)
->add('nbPM', TextType::class, ['required' => false, 'label' => "form.ManuallySetPenalty.nbPM",])
->add('nbOT', TextType::class, ['required' => false, 'label' => "form.ManuallySetPenalty.nbOT",]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'manuallySetPenaltyOfParticipantMakeEventCourse' => ManuallySetPenaltyOfParticipantMakeEventCourse::class,
'event' => Event::class,
]
);
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210525131038 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE course ADD start_date DATETIME DEFAULT NULL, ADD end_date DATETIME DEFAULT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE course DROP start_date, DROP end_date');
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210527125129 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE participant_make_event_course ADD pm_penalty_manually_set TINYINT(1) DEFAULT \'0\' NOT NULL, ADD ot_penalty_manually_set TINYINT(1) DEFAULT \'0\' NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE participant_make_event_course DROP pm_penalty_manually_set, DROP ot_penalty_manually_set');
}
}
......@@ -48,13 +48,19 @@ class CreateCourse
$data["link"] = $this->router->generate("upload_course", ["id" => $this->id]);
if ($this->id != -1) {
$data["title"] = $this->translator->trans("course.modify");
$data["modify"] = true;
$data["name"] = $this->course->getName();
$data["club"] = $this->course->getClub();
$startDate = $this->course->getStartDate();
$data["startDate"] = $startDate === null ? null : $startDate->format('Y-m-d H:i:s') ;
$endDate = $this->course->getEndDate();
$data["endDate"] = $endDate === null ? null : $endDate->format('Y-m-d H:i:s') ;
$data["isPrintable"] = $this->course->getPrintable();
$data["modify"] = true;
} else {
$data["title"] = $this->translator->trans("course.add");
$data["modify"] = false;
$data["startDate"] = null;
$data["endDate"] = null;
$data["isPrintable"] = false;
}
......@@ -193,6 +199,8 @@ class CreateCourse
$kml = FileUploader::getFile($this->user->getId(), "kml");
$image = FileUploader::getFile($this->user->getId(), "image");
$name = $post->get("name");
$startingTime = $post->get("startingTime");
$endingTime = $post->get("endingTime");
$printable = $post->get("printable");
$club = $post->get("club");
$this->course->setUpdateAt(new DateTime('NOW'));
......@@ -225,6 +233,16 @@ class CreateCourse
return $data;
}
try {
$startingTime !== " :00" ? $this->course->setStartDate(new DateTime($startingTime)) : $this->course->setStartDate(null);
} catch (Exception $e) {
$data["error"] = 'Erreur : contrainte horaire incompatible';
}
try {
$endingTime !== " :00" ? $this->course->setEndDate(new DateTime($endingTime)) : $this->course->setEndDate(null);
} catch (Exception $e) {
$data["error"] = 'Erreur : contrainte horaire incompatible';
}
$this->course->setLatitude($latitude);
$this->course->setLongitude($longitude);
$this->course->setLength($length);
......@@ -266,6 +284,16 @@ class CreateCourse
if ($kml != null) {
$this->course->setKml(file_get_contents($kml));
}
try {
$startingTime !== " :00" ? $this->course->setStartDate(new DateTime($startingTime)) : $this->course->setStartDate(null);
} catch (Exception $e) {
$data["error"] = 'Erreur : contrainte horaire incompatible';
}
try {
$endingTime !== " :00" ? $this->course->setEndDate(new DateTime($endingTime)) : $this->course->setEndDate(null);
} catch (Exception $e) {
$data["error"] = 'Erreur : contrainte horaire incompatible';
}
if ($printable != null){
$this->course->setPrintable($printable);
}
......