From 4728d47502ad491f16027508d303ee08e7eac793 Mon Sep 17 00:00:00 2001
From: SofianeLasri <alasri250@gmail.com>
Date: Sat, 9 Apr 2022 19:09:21 +0200
Subject: [PATCH] Fin de la refacto.

---
 .idea/SL-Craft-Website.iml                   |  2 ++
 .idea/inspectionProfiles/Project_Default.xml | 11 ++++++
 pages/client/includes/dependencies.php       |  2 +-
 pages/client/shops.php                       | 35 ++++++++++----------
 pages/client/vitrine.php                     | 28 ++++++++--------
 5 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/.idea/SL-Craft-Website.iml b/.idea/SL-Craft-Website.iml
index c956989b..8eb05ba8 100644
--- a/.idea/SL-Craft-Website.iml
+++ b/.idea/SL-Craft-Website.iml
@@ -4,5 +4,7 @@
     <content url="file://$MODULE_DIR$" />
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="jquery-3.6.0" level="application" />
+    <orderEntry type="library" name="bootstrap" level="application" />
   </component>
 </module>
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 57baa960..7e29deb1 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -6,6 +6,16 @@
       <option name="m_minLength" value="4" />
       <option name="m_maxLength" value="32" />
     </inspection_tool>
+    <inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="myValues">
+        <value>
+          <list size="1">
+            <item index="0" class="java.lang.String" itemvalue="bgimageurl" />
+          </list>
+        </value>
+      </option>
+      <option name="myCustomValuesEnabled" value="true" />
+    </inspection_tool>
     <inspection_tool class="JSClassNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
     <inspection_tool class="LocalVariableNamingConventionJS" enabled="true" level="WARNING" enabled_by_default="true">
       <option name="m_regex" value="[a-z][A-Za-z]*" />
@@ -32,6 +42,7 @@
     </inspection_tool>
     <inspection_tool class="PhpVariableNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true">
       <option name="m_regex" value="[a-z][A-Za-z\d]*" />
+      <option name="m_minLength" value="4" />
     </inspection_tool>
   </profile>
 </component>
\ No newline at end of file
diff --git a/pages/client/includes/dependencies.php b/pages/client/includes/dependencies.php
index 7985a34b..9df78a05 100644
--- a/pages/client/includes/dependencies.php
+++ b/pages/client/includes/dependencies.php
@@ -8,7 +8,7 @@
 <link rel="mask-icon" href="<?=getWebsiteSetting("websiteUrl")?>data/images/logo/favicon-blanc.svg" color="#ffffff">
 
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
-<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
+<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
 <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
 
 <!-- Polices d'écriture -->
diff --git a/pages/client/shops.php b/pages/client/shops.php
index 4088540d..fdf1f647 100644
--- a/pages/client/shops.php
+++ b/pages/client/shops.php
@@ -3,7 +3,7 @@
 <head>
     <meta charset="UTF-8">
     <!-- Dépendances -->
-    <?=Client::getDependencies()?>
+    <?php Client::getDependencies(); ?>
     <title><?=getWebsiteSetting("websiteName")?> | Magasins</title>
     
     <!-- Embed -->
@@ -22,7 +22,7 @@
 </head>
 <body>
     <!-- Inclusion dynamique de la navbar -->
-    <?=Client::getNavbar()?>
+    <?php Client::getNavbar(); ?>
     <div id="navbarReplacement" style="z-index:-1;"></div>
     
     <!-- Contenu -->
@@ -32,18 +32,18 @@
                 <h3>Filtres</h3>
                 <form method="get" name="filterForm">
                     <div class="form-group">
-                        <label>Trier par entité/bloc</label>
-                        <select multiple class="form-control" name="blocs[]">
+                        <label for="blockFilter">Trier par entité/bloc</label>
+                        <select id="blockFilter" multiple class="form-control" name="blocs[]">
                             <option value="">Aucune</option>
                             <?php
-                            $items = Shop::getAllProducts();
-                            foreach($items as $item) {
-                                if(isset($_GET["blocs"]) && in_array($item->getType(), $_GET["blocs"])){
+                            $products = Shop::getAllProducts();
+                            foreach($products as $product) {
+                                if(isset($_GET["blocs"]) && in_array($product->getType(), $_GET["blocs"])){
                                     $selected = "selected";
                                 }else{
                                     $selected = "";
                                 }
-                                echo '<option value="'.$item->getType().'" '.$selected.'><i class="icon-minecraft '.$item->getCssClassName().'"></i> '.$item->getLabel().'</option>';
+                                echo '<option value="'.$product->getType().'" '.$selected.'><i class="icon-minecraft '.$product->getCssClassName().'"></i> '.$product->getLabel().'</option>';
                             }
                             ?>
                         </select>
@@ -221,23 +221,24 @@
     <script type="text/javascript">
         // On va définir la taille de la div derrière la navbar
         function goToShop(id){
+            let shopElem = $("#"+id);
             var shopItemDetail='<p>Type: <strong>'+$('#'+id).attr('type')+'</strong></p>';
-            if($("#"+id).attr("displayName") != ""){
-                shopItemDetail+='<p>Nom personnalisé: <strong>'+decodeURIComponent($("#"+id).attr("displayName"))+'</strong></p>';
+            if(shopElem.attr("displayName") !== ""){
+                shopItemDetail+='<p>Nom personnalisé: <strong>'+decodeURIComponent(shopElem.attr("displayName"))+'</strong></p>';
             }
-            if($("#"+id).attr("enchants") != "null"){
-                let enchants = JSON.parse(decodeURIComponent($("#"+id).attr("enchants")));
+            if(shopElem.attr("enchants") !== "null"){
+                let enchants = JSON.parse(decodeURIComponent(shopElem.attr("enchants")));
                 for(const [key, value] of Object.entries(enchants)){
                     shopItemDetail+='<p>Enchantement: <strong>'+key+'</strong> ('+value+')</p>';
                 }
             }
-            shopItemDetail+='<p>Prix: <strong>'+$("#"+id).attr("price")+'€</strong></p>';
+            shopItemDetail+='<p>Prix: <strong>'+shopElem.attr("price")+'€</strong></p>';
 
             $("#shopItemDetail").html(shopItemDetail);
-            $("#shopXPos").val($("#"+id).attr("x"));
-            $("#shopYPos").val($("#"+id).attr("y"));
-            $("#shopZPos").val($("#"+id).attr("z"));
-            $("#shopMapLink").attr("href", "https://live.mc.sl-projects.com/#"+$("#"+id).attr("world")+";flat;"+$("#"+id).attr("x")+","+$("#"+id).attr("y")+","+$("#"+id).attr("z")+";5");
+            $("#shopXPos").val(shopElem.attr("x"));
+            $("#shopYPos").val(shopElem.attr("y"));
+            $("#shopZPos").val(shopElem.attr("z"));
+            $("#shopMapLink").attr("href", "https://live.mc.sl-projects.com/#"+shopElem.attr("world")+";flat;"+shopElem.attr("x")+","+shopElem.attr("y")+","+shopElem.attr("z")+";5");
             $("#shopModal").modal("show");
         }
 
diff --git a/pages/client/vitrine.php b/pages/client/vitrine.php
index 90d6f401..28fd91bc 100644
--- a/pages/client/vitrine.php
+++ b/pages/client/vitrine.php
@@ -3,7 +3,7 @@
 <head>
     <meta charset="UTF-8">
     <!-- Dépendances -->
-    <?=Client::getDependencies()?>
+    <?php Client::getDependencies(); ?>
     <title><?=getWebsiteSetting("websiteName")?></title>
     
     <!-- Embed -->
@@ -18,7 +18,7 @@
 </head>
 <body>
     <!-- Inclusion dynamique de la navbar -->
-    <?=Client::getNavbar()?>
+    <?php Client::getNavbar(); ?>
 
     <!-- Intro -->
     <div id="intro">
@@ -40,7 +40,7 @@
     
     <!-- Fin de l'intro -->
 
-    <?=Client::getFooter()?>
+    <?php Client::getFooter(); ?>
 
     <!-- connectModal -->
     <div class="modal fade" id="connectModal">
@@ -51,12 +51,12 @@
                 </div>
                 <div class="modal-body">
                     <div class="form-group">
-                        <label>Minecraft Java Edition</label>
-                        <input type="text" class="form-control" value="play.sl-craft.fr" readonly>
+                        <label for="ipJava">Minecraft Java Edition</label>
+                        <input id="ipJava" type="text" class="form-control" value="play.sl-craft.fr" readonly>
                     </div>
                     <div class="form-group">
-                        <label>Minecraft Bedrock Edition</label>
-                        <input type="text" class="form-control" value="proxy.sl-craft.fr:19132" readonly>
+                        <label for="ipBedrock">Minecraft Bedrock Edition</label>
+                        <input id="ipBedrock" type="text" class="form-control" value="proxy.sl-craft.fr:19132" readonly>
                     </div>
                     <p>*Le serveur est cross-plateformes, vous jouez sur une unique map.</p>
                 </div>
@@ -74,7 +74,7 @@
         // On va définir la taille de l'intro
         setVitrineHeight();
         function setVitrineHeight() {
-            var vitrineHeight = window.innerHeight - document.getElementById("navbar").offsetHeight;
+            let vitrineHeight = window.innerHeight - document.getElementById("navbar").offsetHeight;
             $("#intro").css("height", vitrineHeight);
         }
         window.onresize = setVitrineHeight;
@@ -115,8 +115,9 @@ function setVitrineHeight() {
 
 
             // On va regarder si dans ce que l'on va afficher, il n'y a pas des images à charger
-            var imagesToLoad = [];
-            $(".intro-vitrine .presentation > *").each(async function() {
+            let imagesToLoad = [];
+            let presentationElems = $(".intro-vitrine .presentation > *");
+            presentationElems.each(async function() {
                 let hasABgImageToLoad = $(this).attr('bgImageUrl');
                 if (typeof hasABgImageToLoad !== 'undefined' && hasABgImageToLoad !== false) {
                     imagesToLoad.push(hasABgImageToLoad);
@@ -124,18 +125,19 @@ function setVitrineHeight() {
             });
             console.log("Images à charger:"+imagesToLoad);
             await loadImages(imagesToLoad);
-            $(".intro-vitrine .presentation > *").fadeIn(1000);
+            presentationElems.fadeIn(1000);
             $(".intro-vitrine .presentation .description").css("display", "flex"); // On a retiré la propriété flex pour faire le fadeIn
 
             imagesToLoad = [];
             setTimeout(async function(){
-                let hasABgImageToLoad = $("#vitrine-background-image:hidden").attr('bgImageUrl');
+                let hiddenVitrineBackground = $("#vitrine-background-image:hidden");
+                let hasABgImageToLoad = hiddenVitrineBackground.attr('bgImageUrl');
                 if (typeof hasABgImageToLoad !== 'undefined' && hasABgImageToLoad !== false) {
                     imagesToLoad.push(hasABgImageToLoad);
                 }
                 console.log("Images à charger:"+imagesToLoad);
                 await loadImages(imagesToLoad);
-                $("#vitrine-background-image:hidden").fadeIn(4000);
+                hiddenVitrineBackground.fadeIn(4000);
             }, 1000)
             
         });
-- 
GitLab