importation de la map

This commit is contained in:
Baptiste Rebillard 2022-01-20 21:49:52 +01:00
parent f1548fd5ea
commit 35d3dc3b97
7 changed files with 190 additions and 41 deletions

38
assets/map/map.php Normal file
View file

@ -0,0 +1,38 @@
<div id="maps_button">
<button onclick="enable3DMap()" class="main-button">Map 3D</button>
<button onclick="enable2DMap()" class="main-button">Map 2D</button>
</div>
<section id="loading-screen">
<div class="loader"></div>
</section>
<div id="maps" class="">
<script src="assets/map/map3d.js" type="module"></script>
<div id="map" class="hidden">
<?php echo file_get_contents("assets/map/map.svg"); ?>
<canvas id="canvasID"></canvas>
</div>
</div>
<script>
function enable3DMap() {
var map3d = document.querySelector('#maps #map3d');
var map = document.querySelector('#maps #map');
map3d.classList.add("hidden");
map.classList.add("hidden");
map3d.classList.remove("hidden");
}
function enable2DMap() {
var map3d = document.querySelector('#maps #map3d');
var map = document.querySelector('#maps #map');
map.classList.add("hidden");
map3d.classList.add("hidden");
map.classList.remove("hidden");
}
</script>
<script type='text/javascript' src='map.js'></script>

View file

Before

Width:  |  Height:  |  Size: 565 KiB

After

Width:  |  Height:  |  Size: 565 KiB

View file

@ -84,7 +84,7 @@ function init() {
//
var loader = new GLTFLoader(loadingManager);
loader.load('assets/img/map/map3D.glb', function(gltf) {
loader.load('assets/map/map3D.glb', function(gltf) {
var object = gltf.scene;
gltf.scene.scale.set( 2, 2, 2 );
gltf.scene.position.x = 0; //Position (x = right+ left-)

147
dao.php Normal file
View file

@ -0,0 +1,147 @@
<?php
class Dao
{
private $conn;
public function __construct()
{
$username = 'root';
$password = "";
$dsn = 'mysql:dbname=accueil_insa;host=127.0.0.1';
try {
$this->conn = new PDO($dsn, $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
} catch (PDOException $e) {
echo $e;
}
}
private function read_password()
{
$real_path = __DIR__.DIRECTORY_SEPARATOR.".htpassdb";
$file = fopen($real_path, "r") or die("Unable to open DB password file!");;
$password = fgets($file);
fclose($file);
return trim($password);
}
public function get_score_team($team)
{
$sql = 'SELECT text, points FROM scores WHERE team = ?';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$team]);
return $cursor->fetchAll(PDO::FETCH_ASSOC);
}
public function add_score($score_data) {
$sql = 'INSERT INTO scores (text, points, team) VALUES (?, ?, ?)';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$score_data['text'], $score_data['points'], $score_data['team']]);
}
public function save_scores($scores_json, $team)
{
$sql = 'DELETE FROM scores WHERE team = ?';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$team]);
foreach ($scores_json as $value) {
$sql = 'INSERT INTO scores (text, points, team) VALUES (?, ?, ?)';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$value['text'], $value['points'], $team]);
}
}
public function get_map_info($selector)
{
$sql = 'SELECT title, description FROM map_insa WHERE selector = ?';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$selector]);
return $cursor->fetchAll(PDO::FETCH_ASSOC);
}
public function get_map_selectors()
{
$sql = 'SELECT selector FROM map_insa';
$cursor = $this->conn->prepare($sql);
$cursor->execute();
return $cursor->fetchAll(PDO::FETCH_ASSOC);
}
public function save_map_info($selector, $info_json)
{
$sql = 'DELETE FROM map_insa WHERE selector = ?';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$selector]);
$sql = 'INSERT INTO map_insa (title, description, selector) VALUES (?, ?, ?)';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$info_json['title'], $info_json['description'], $selector]);
}
public function is_in_map($selector) {
$sql = 'SELECT selector FROM map_insa WHERE selector = ?';
$query = $this->conn->prepare($sql);
$query->execute([$selector]);
return $query->fetchAll(PDO::FETCH_ASSOC);
}
public function get_activities_of_day($day)
{
$sql = 'SELECT * FROM planning_insa WHERE day = ?';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$day]);
return $cursor->fetchAll(PDO::FETCH_ASSOC);
}
public function save_day_activities($day, $info_json)
{
$sql = 'DELETE FROM planning_insa WHERE day = ?';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$day]);
foreach ($info_json as $value) {
$sql = 'INSERT INTO planning_insa (day, small_title, full_title, description, color, start, length) VALUES (?, ?, ?, ?, ?, ?, ?)';
$cursor = $this->conn->prepare($sql);
$cursor->execute([$value['day'], $value['small_title'], $value['full_title'], $value['description'], $value['color'], $value['start'], $value['length']]);
}
}
/**
* Add a building in the database
* @param String $title = Name of the building displayed
* @param String $description = Description of the building
* @param String $selector = Identifier of the building (unique)
* @return Mixed = if error : false
* else : Array of the row added as an array indexed by column name
*/
public function create_building($title, $description, $selector) {
$sql = 'INSERT INTO map_insa (title, description, selector) VALUES(:title, :description, :selector)';
$query = $this->conn->prepare($sql);
$query->execute(array(
':title' => $title,
':description' => $description,
':selector' => $selector,
));
return $query->fetch(PDO::FETCH_ASSOC);
}
/**
* Remove a building in the database
* @param String $selector = Identifier of the building (unique)
* @return Mixed = if error : false
* else : Array with the selector used to remove from the database
*/
public function delete_building($selector) {
$sql = 'DELETE FROM map_insa WHERE selector=?';
$query = $this->conn->prepare($sql);
$query->execute([$selector]);
return $query->fetch(PDO::FETCH_ASSOC);
}
}

44
map.php
View file

@ -1,5 +1,6 @@
<?php
ob_start(); // Start reading html
//include "dao.php";
?>
<main>
<h1>Le Plan</h1>
@ -9,23 +10,8 @@ ob_start(); // Start reading html
<p>
<strong>Clique sur un bâtiment pour voir les infos.</strong>
</p>
<div id="maps_button">
<button onclick="enable3DMap()" class="main-button">Map 3D</button>
<button onclick="enable2DMap()" class="main-button">Map 2D</button>
</div>
<section id="loading-screen">
<div class="loader"></div>
</section>
<div id="maps" class="">
<script src="assets/js/map3d.js" type="module"></script>
<div id="map" class="hidden">
<?php echo file_get_contents("assets/img/map/map.svg"); ?>
<canvas id="canvasID"></canvas>
</div>
</div>
<?php include "assets/map/map.php"; ?> <!-- affichage de la map -->
<p>
Une petite note sur le numéro des salles : sur ton emploi du temps, le bâtiment est marqué en premier, et
@ -40,29 +26,7 @@ ob_start(); // Start reading html
Map</a>.
</p>
</main>
<script>
function enable3DMap() {
var map3d = document.querySelector('#maps #map3d');
var map = document.querySelector('#maps #map');
map3d.classList.add("hidden");
map.classList.add("hidden");
map3d.classList.remove("hidden");
}
function enable2DMap() {
var map3d = document.querySelector('#maps #map3d');
var map = document.querySelector('#maps #map');
map.classList.add("hidden");
map3d.classList.add("hidden");
map.classList.remove("hidden");
}
</script>
<?php
$infopage = ["", "Plan", ob_get_clean(), "<script type='text/javascript' src='assets/js/map/map.js'></script>", "map"]; //relativepath, pagetitle, pagecontent, pagescript, pagename | cf structure/template.php ligne 2 à 6
$infopage = ["", "Plan", ob_get_clean(), "", "map"]; //relativepath, pagetitle, pagecontent, pagescript, pagename | cf structure/template.php ligne 2 à 6
include("structure/template.php");
?>