Commit b1087f4c authored by CLOUARD Regis's avatar CLOUARD Regis
Browse files

Merge branch 'Refactor' into 'master'

Refactor

See merge request !10
parents b44697dc 3fe05c9d
......@@ -3,11 +3,10 @@
/.env.local
/.env.local.php
/.env.*.local
/.idea
/config/secrets/prod/prod.decrypt.private.php
/public/bundles
/vendor
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
###> symfony/phpunit-bridge ###
......@@ -20,5 +19,4 @@ prototype-uml/*
/tmp_files/
/upload
/config/secret/.Halite.key
/var/
/config/secret/.image.keys
......@@ -13,7 +13,9 @@
Une fois le projet cloné, il faut :
- faire `composer install` pour installer tous les bundles.
- installer une base
symfony server:start --dir=site-vikazimut/public
```
symfony server:start --dir=site-vikazimut/public
```
### Installer la base de données mysql
......@@ -46,6 +48,15 @@ Le site suivant permet de personnaliser Bootstrap, puis de récupérer les css m
Vérifier la taille maximale des fichiers téléversables (eg. dans php.ini ou configuration apache)
### Mise à jour de la version de Symfony
Le fichier `composer.json` référence les paquets utilisés par le projet avec leur numéro de version.
Pour changer la version de Symfony, il faut mettre à jour la version des paquets Symfony, puis lancer la commande :
```
php7.4-cli composer.phar update –no-dev --with-all-dependencies
```
### Déploiement en production
#### Version avec Easy Deploy
......
{
"name": "ensicaen/vikazimut",
"description": "Website for the Vikazimut a mobile application",
"description": "Website for the Vikazimut mobile application",
"type": "project",
"license": "LGPL",
"require": {
......@@ -13,45 +13,46 @@
"ext-openssl": "*",
"ext-pdo": "*",
"ext-simplexml": "*",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/doctrine-bundle": "^2.4",
"michaeldegroot/doctrine-encrypt-bundle": "^4.0",
"paragonie/halite": "^4",
"sensio/framework-extra-bundle": "^5.6",
"symfony/asset": "5.*.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/expression-language": "5.1.*",
"symfony/flex": "^1.3.1",
"symfony/form": "5.1.*",
"symfony/framework-bundle": "5.1.*",
"symfony/http-client": "5.1.*",
"symfony/intl": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "5.1.*",
"symfony/orm-pack": "^1.0",
"symfony/process": "5.1.*",
"symfony/security-bundle": "5.1.*",
"symfony/serializer-pack": "*",
"symfony/string": "5.1.*",
"symfony/swiftmailer-bundle": "^3.4",
"symfony/translation": "5.1.*",
"symfony/twig-pack": "*",
"symfony/validator": "5.1.*",
"symfony/web-link": "5.1.*",
"symfony/yaml": "5.1.*",
"ext-zlib": "*"
"symfony/asset": "5.3.*",
"symfony/console": "5.3.*",
"symfony/dotenv": "5.3.*",
"symfony/expression-language": "5.3.*",
"symfony/flex": "^1.13",
"symfony/form": "5.3.*",
"symfony/framework-bundle": "5.3.*",
"symfony/http-client": "5.3.*",
"symfony/intl": "5.3.*",
"symfony/mailer": "5.3.*",
"symfony/monolog-bundle": "^3.7",
"symfony/notifier": "5.3.*",
"symfony/orm-pack": "^1.1",
"symfony/process": "5.3.*",
"symfony/security-bundle": "5.3.*",
"symfony/serializer-pack": "1.*",
"symfony/string": "5.3.*",
"symfony/swiftmailer-bundle": "^3.5",
"symfony/translation": "5.3.*",
"symfony/twig-pack": "^1.0",
"symfony/validator": "5.3.*",
"symfony/web-link": "5.3.*",
"symfony/yaml": "5.3.*",
"ext-zlib": "*",
"ext-zip": "*"
},
"require-dev": {
"dama/doctrine-test-bundle": "^6.3",
"doctrine/doctrine-fixtures-bundle": "^3.3",
"dama/doctrine-test-bundle": "^6.6",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"easycorp/easy-deploy-bundle": "^1.0",
"phpunit/phpunit": "^8",
"symfony/debug-pack": "*",
"symfony/maker-bundle": "^1.15",
"symfony/phpunit-bridge": "^5.1",
"symfony/debug-pack": "^1",
"symfony/maker-bundle": "^1.32",
"symfony/phpunit-bridge": "^5.3",
"symfony/profiler-pack": "^1.0",
"symfony/test-pack": "*"
"symfony/test-pack": "^1"
},
"config": {
"preferred-install": {
......@@ -70,7 +71,7 @@
}
},
"replace": {
"paragonie/random_compat": "2.*",
"paragonie/random_compat": "*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
......@@ -96,7 +97,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.1.*"
"require": "5.3.*"
}
}
}
This diff is collapsed.
security:
encoders:
password_hashers:
App\Entity\User:
algorithm: auto
......
......@@ -12,7 +12,7 @@ function removeTimeSheet(event, pseudo) {
showTimeSheet();
}
function clearTimeSheet(){
function clearTimeSheet() {
timeSheetData = [];
showTimeSheet();
}
......@@ -36,25 +36,19 @@ function convertTimeToString(time) {
}
}
function deltaDistanceCalculator(idealDistance,realDistance){
let distanceString = idealDistance.toString() + " m";
(idealDistance >+ realDistance) ? distanceString += " (+" : distanceString += " (";
distanceString += Math.round(((idealDistance/realDistance)-1)*100) + "%)";
function deltaDistanceCalculator(idealDistance, realDistance) {
let distanceString = idealDistance.toString();
(idealDistance > +realDistance) ? distanceString += " (+" : distanceString += " (";
distanceString += Math.round(((idealDistance / realDistance) - 1) * 100) + "%)";
return distanceString;
}
function RKCalculator(timeInMilliseconds,distanceInMeter){
let timeInS = timeInMilliseconds / 1000.0;
let mins = timeInS / 60;
let distInKm = distanceInMeter / 1000.0;
return (Math.round(mins / distInKm * 10)/10).toFixed(1);
function computePace(timeInMilliseconds, distanceInMeter) {
return ((timeInMilliseconds) / (60 * distanceInMeter)).toFixed(1);
}
function speedCalculator(timeInMilliseconds,distanceInMeter){
let timeInS = timeInMilliseconds / 1000.0;
let hrs = timeInS / 3600;
let distInKm = distanceInMeter / 1000.0;
return (Math.round(distInKm / hrs * 10)/10).toFixed(1);
function computeSpeed(timeInMilliseconds, distanceInMeter) {
return (3600 * distanceInMeter / timeInMilliseconds).toFixed(1);
}
function renderTimeSheet(distances) {
......@@ -73,7 +67,6 @@ function renderTimeSheet(distances) {
cell.setAttribute("scope", "col");
headRow1.appendChild(cell);
let headRow2 = document.createElement("tr");
cell = document.createElement("th");
cell.setAttribute("scope", "col");
......@@ -83,7 +76,7 @@ function renderTimeSheet(distances) {
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.length + " (m)";
cell.innerHTML = translations.length + " (m)";
headRow2.appendChild(cell);
let head = document.createElement("thead");
......@@ -94,7 +87,7 @@ function renderTimeSheet(distances) {
let body = document.createElement("tbody");
let rows = [];
let cps = timeSheetData[0][1];
let totalDistance = 0;
let totalTheoreticalDistance = 0;
for (let i = 0; i < cps.length; i++) {
const index = cps[i]["controlPoint"];
let controlCell = document.createElement("th");
......@@ -104,12 +97,12 @@ function renderTimeSheet(distances) {
controlCell.innerHTML = translations.start;
} else if (index === timeSheetData[0][1].length - 1) {
controlCell.innerHTML = translations.finish;
lengthCell.innerHTML = distances[i] + " m";
totalDistance += distances[i];
lengthCell.innerHTML = distances[i];
totalTheoreticalDistance += distances[i];
} else {
controlCell.innerHTML = index;
lengthCell.innerHTML = distances[i] + " m";
totalDistance += distances[i];
lengthCell.innerHTML = distances[i];
totalTheoreticalDistance += distances[i];
}
let row = document.createElement("tr");
row.appendChild(controlCell);
......@@ -118,9 +111,9 @@ function renderTimeSheet(distances) {
rows.push(row);
}
let totalTitleCell = document.createElement("th");
totalTitleCell.innerHTML = translations.totals;
totalTitleCell.innerHTML = translations.total;
let totalLengthCell = document.createElement("th");
totalLengthCell.innerHTML = totalDistance.toString() + " m";
totalLengthCell.innerHTML = totalTheoreticalDistance.toString();
let totalsRow = document.createElement("tr");
totalsRow.appendChild(totalTitleCell);
totalsRow.appendChild(totalLengthCell);
......@@ -142,17 +135,16 @@ function renderTimeSheet(distances) {
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.distance+ " (m)";
cell.innerHTML = translations.distance + " (m)";
headRow2.appendChild(cell);
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.RK + " (min/km) / <br>" + translations.speed + " (km/h)";
cell.innerHTML = translations.pace + " (min/km) / <br>" + translations.speed + " (km/h)";
headRow2.appendChild(cell);
let orienteerTotalDistance = 0;
let orienteerTotalTime = 0;
let time, orienteerDistance;
for (let i = 0; i < orienteerData[1].length; i++) {
let index = i;
......@@ -164,12 +156,12 @@ function renderTimeSheet(distances) {
let paceCell = document.createElement("td");
paceCell.setAttribute("scope", "col");
if (i > 0) {
time = orienteerData[2][i];
let time = orienteerData[2][i];
if (time > 0) {
orienteerDistance = orienteerData[3][i]
let orienteerDistance = orienteerData[3][i]
timeCell.innerHTML = convertTimeToString(time);
distanceCell.innerHTML = deltaDistanceCalculator(orienteerDistance,distances[i]);
paceCell.innerHTML = RKCalculator(time,distances[i]) + " / " + speedCalculator(time,orienteerDistance);
distanceCell.innerHTML = deltaDistanceCalculator(orienteerDistance, distances[i]);
paceCell.innerHTML = computePace(time, distances[i]) + " / " + computeSpeed(time, distances[i]);
orienteerTotalDistance += orienteerDistance;
orienteerTotalTime += time;
} else {
......@@ -181,7 +173,6 @@ function renderTimeSheet(distances) {
rows[index].appendChild(timeCell);
rows[index].appendChild(distanceCell);
rows[index].appendChild(paceCell);
}
let totalTimeCell = document.createElement("th");
......@@ -193,10 +184,10 @@ function renderTimeSheet(distances) {
speedMeanCell.setAttribute("scope", "col");
totalTimeCell.innerHTML = convertTimeToString(orienteerTotalTime);
totalDistanceCell.innerHTML = deltaDistanceCalculator(orienteerTotalDistance,totalDistance);
speedMeanCell.innerHTML = RKCalculator(orienteerTotalTime,totalDistance).toString() + " min/km"
+ "<br>"
+ speedCalculator(orienteerTotalTime,orienteerTotalDistance).toString() + " km/h";
totalDistanceCell.innerHTML = deltaDistanceCalculator(orienteerTotalDistance, totalTheoreticalDistance);
speedMeanCell.innerHTML = computePace(orienteerTotalTime, totalTheoreticalDistance).toString()
+ " / "
+ computeSpeed(orienteerTotalTime, totalTheoreticalDistance).toString();
totalsRow.appendChild(totalTimeCell);
totalsRow.appendChild(totalDistanceCell);
......
......@@ -142,7 +142,7 @@ function previewMap(data, divMap, divLeaflet, map, overlay, img) {
overlay.reposition(L.latLng(corner[0]), L.latLng(corner[1]), L.latLng(corner[3]));
map.fitBounds([corner[0], corner[2]]);
// Add recenter button
if (recenterButton != null){
if (recenterButton != null) {
recenterButton.remove();
}
recenterButton = L.easyButton('fa-map-marker', function (btn, map) {
......@@ -170,11 +170,10 @@ function addControlPointOnMap(data, map) {
usedControlPoints.push(value[0]);
}
for (let [key, value] of Object.entries(data.xml2)) {
if (usedControlPoints.includes(key)){
if (usedControlPoints.includes(key)) {
markerColor = '#ff0000';
markerOpacity = 0.8;
}
else {
} else {
markerColor = '#1f479f';
markerOpacity = 0.5;
}
......@@ -191,7 +190,7 @@ function addControlPointOnMap(data, map) {
}
function showPreview(data, divXml, divMap, divLeaflet, map, overlay, img) {
if (controlPointsMarkers == null){
if (controlPointsMarkers == null) {
controlPointsMarkers = L.layerGroup();
controlPointsMarkers.addTo(map);
}
......@@ -200,7 +199,7 @@ function showPreview(data, divXml, divMap, divLeaflet, map, overlay, img) {
addControlPointOnMap(data, map);
}
function downloadMap(imageURL){ //see library printJS for further print options.
function downloadMap(imageURL) { //see library printJS for further print options.
let printableMap = window.open(window.location.origin + "/" + imageURL);
printableMap.download();
}
......@@ -208,6 +207,14 @@ function downloadMap(imageURL){ //see library printJS for further print options.
function switchMapDisplay(overlay, overlayOpacity) {
let hideButton = document.getElementById("hide-map");
let showButton = document.getElementById("show-map");
overlayOpacity === 100 ? (overlayOpacity = 0, hideButton.style.display = "block", showButton.style.display = "none") : (overlayOpacity = 100, hideButton.style.display = "none", showButton.style.display = "block");
if (overlayOpacity === 100) {
overlayOpacity = 0;
hideButton.style.display = "block";
showButton.style.display = "none";
} else {
overlayOpacity = 100;
hideButton.style.display = "none";
showButton.style.display = "block";
}
overlay.setOpacity(overlayOpacity);
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use App\Form\PlannerType;
use App\Entity\User;
......@@ -47,7 +47,7 @@ class AdminController extends AbstractController
/**
* @Route("/admin/add_planner", name="add_planner")
*/
public function add_user(Request $request, TranslatorInterface $translator, UserPasswordEncoderInterface $encoder, Swift_Mailer $mailer): Response
public function add_user(Request $request, TranslatorInterface $translator, UserPasswordHasherInterface $encoder, Swift_Mailer $mailer): Response
{
$planner = new User();
$formBuilder = $this->createForm(PlannerType::class, $planner, ['password' => false]);
......@@ -81,10 +81,8 @@ class AdminController extends AbstractController
/**
* @Route("/admin/change_planner_password/{id}", name="change_planner_password")
* @param int $id
* @return RedirectResponse
*/
public function password_modification(int $id, UserPasswordEncoderInterface $encoder, TranslatorInterface $translator, Swift_Mailer $mailer): RedirectResponse
public function password_modification(int $id, UserPasswordHasherInterface $encoder, TranslatorInterface $translator, Swift_Mailer $mailer): RedirectResponse
{
$user = $this->getDoctrine()->getRepository(User::class)->find($id);
$creator = new CreateUser($user, $translator);
......
......@@ -14,11 +14,8 @@ class ChangeLocaleController extends AbstractController
*/
public function changeLocale($locale, Request $request): RedirectResponse
{
$newUrl = explode('/', $request->headers->get('referer'));
$prefixToBeRemoved = ($request->getLocale() === "fr") ? 0 : 1;
if ($locale === "fr") {
array_splice($newUrl, 3, $prefixToBeRemoved);
} else {
......@@ -28,5 +25,4 @@ class ChangeLocaleController extends AbstractController
return $this->redirect($newUrl);
}
}
<?php
namespace App\Controller;
use Swift_Mailer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\User;
use App\Model\CreateUser;
class ControllerIndex extends AbstractController // TODO Used ?
class ControllerIndex extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index()
public function index(): Response
{
return $this->render('home/index.html.twig');
}
// /**
// * @Route("/test")
// */
// public function test()
// {
// phpinfo();
// }
//
// /**
// * @Route("/init")
// */
// public function init(UserPasswordEncoderInterface $encoder, Swift_Mailer $mailer)
// {
// $user = new User();
// $user->setUsername("eric");
//
// $user->setEmail("mfmyradrian@gmail.com");
// $user->setRoles(["ROLE_ADMIN"]);
//
// $creator = new CreateUser($user, null);
// $creator->addUser($encoder, $this->getDoctrine()->getManager());
// $creator->sendEmail($mailer, true);
//
// return $this->render(
// 'profile/index.html.twig',
// [
// 'user' => $user,
// ]
// );
// }
}
......@@ -78,6 +78,9 @@ class CourseController extends AbstractController
public function tracks($id, TrackStatistics $statistics, Request $request): Response
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
throw $this->createNotFoundException("Ce parcours n'existe pas : ".$id);
}
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new DateTime('NOW'));
......@@ -94,9 +97,6 @@ class CourseController extends AbstractController
}
$importTab = 0;
$success = "";
if (!$course) { // TODO Warning
throw $this->createNotFoundException("Ce parcours n'existe pas : ".$id);
}
$xml = $course->getXml();
$simplexml = simplexml_load_string($xml);
$lengths = $statistics->computeLegLengths($simplexml);
......@@ -144,6 +144,9 @@ class CourseController extends AbstractController
public function courseInfo($id, TrackStatistics $statistics): Response
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
throw $this->createNotFoundException('Ce parcours n\'existe pas : '.$id);
}
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new DateTime('NOW'));
......@@ -158,9 +161,6 @@ class CourseController extends AbstractController
);
}
}
if (!$course) { // TODO Test inutile puisque deka passer par $course-> getStartDate()
throw $this->createNotFoundException('Ce parcours n\'existe pas : '.$id);
}
$xml = $course->getXml();
$simplexml = simplexml_load_string($xml);
$lengths = $statistics->computeLegLengths($simplexml);
......
......@@ -3,10 +3,9 @@
namespace App\Controller;
use App\Entity\Event;
use App\Entity\EventCourse;
use App\Entity\Participant;
use App\Entity\ParticipantMakeEventCourse;
use App\Entity\Track;
use DateTime;
use PHPUnit\Util\Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
......@@ -31,7 +30,7 @@ class DataController extends AbstractController
foreach ($courses as $course) {
$courseDate = $course->getStartDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
$dateDiff = $courseDate->diff(new DateTime('NOW'));
if ($dateDiff->invert === 1) {
unset($courses[array_search($course, $courses)]);
}
......@@ -40,7 +39,7 @@ class DataController extends AbstractController
foreach ($courses as $course) {
$courseDate = $course->getEndDate();
if ($courseDate !== null) {
$dateDiff = $courseDate->diff(new \DateTime('NOW'));
$dateDiff = $courseDate->diff(new DateTime('NOW'));
if ($dateDiff->invert === 0) {
unset($courses[array_search($course, $courses)]);
}
......@@ -77,7 +76,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);
......@@ -117,7 +116,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());
......@@ -125,7 +124,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);
......@@ -148,7 +147,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);
......
......@@ -88,14 +88,11 @@ class EventController extends AbstractController
/**
* @Route("/my_event/details/{id}", name="my_event_details")
* @param int $id
* @return Response
*/
public function details(int $id, Request $request): Response
{
$user = $this->security->getUser();
$event = $this->getDoctrine()->getRepository(Event::class)->find($id);
$formsView = [];
$participants = $event->getParticipants();
$eventCourses = $event->getEventCourses();
......@@ -148,7 +145,6 @@ class EventController extends AbstractController