mirror of
https://github.com/Floriansylvain/projet_programmation_web.git
synced 2026-08-19 11:43:16 +02:00
✨ Introduced big DB (~500 000 results) and multiple improvements
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
/ProjetProgWeb/.env
|
/ProjetProgWeb/.env
|
||||||
|
/scripts/*.csv
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
require_once("class/dump.php");
|
require_once("class/dump.php");
|
||||||
|
|
||||||
$author_name = $_GET['author'];
|
$author_name = $_GET['author'];
|
||||||
|
|
||||||
$these_array = dump::getTheseByAuthor($author_name);
|
$these_array = dump::getTheseByAuthor($author_name);
|
||||||
|
$json = json_encode($these_array);
|
||||||
$json = json_encode($these_array, JSON_PRETTY_PRINT);
|
print_r($json);
|
||||||
|
|
||||||
echo '<pre>';
|
|
||||||
var_dump($json);
|
|
||||||
echo '</pre>';
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
function requestToApi(author) {
|
||||||
|
fetch(`api.php?author=${author}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => displayResults(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayResults(results) {
|
||||||
|
results.forEach(function(elem) {
|
||||||
|
|
||||||
|
let result = document.createElement('div')
|
||||||
|
result.classList.add('result-element')
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
|
||||||
|
elem.forEach(function(e) {
|
||||||
|
let child = document.createElement(i === 0 ? 'h1' : 'p')
|
||||||
|
child.innerText = e
|
||||||
|
result.appendChild(child)
|
||||||
|
i += 1
|
||||||
|
})
|
||||||
|
|
||||||
|
document.getElementById('results').appendChild(result)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
ini_set('max_execution_time', 0);
|
||||||
|
|
||||||
require_once("these.php");
|
require_once("these.php");
|
||||||
require_once("conf.php");
|
require_once("conf.php");
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ class dump {
|
|||||||
|
|
||||||
$pdo_obj = new conf();
|
$pdo_obj = new conf();
|
||||||
$pdo = $pdo_obj->getPDO();
|
$pdo = $pdo_obj->getPDO();
|
||||||
$stmt = $pdo->query("SELECT * FROM theses WHERE author = '$author';");
|
$stmt = $pdo->query("SELECT * FROM theses WHERE author LIKE '%$author%';");
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($obj = $stmt->fetchObject()) {
|
while ($obj = $stmt->fetchObject()) {
|
||||||
$theses_array[$i] = array();
|
$theses_array[$i] = array();
|
||||||
|
|||||||
+8
-16
@@ -5,29 +5,21 @@
|
|||||||
<meta name="viewport"
|
<meta name="viewport"
|
||||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<script src="app.js"></script>
|
||||||
<link rel="stylesheet" href="stylesheet.css">
|
<link rel="stylesheet" href="stylesheet.css">
|
||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
include("navbar.php");
|
include("navbar.php");
|
||||||
|
if (isset($_POST['author'])) {
|
||||||
if (!isset($_POST['author'])) {
|
if (strlen($_POST['author']) < 3) {
|
||||||
exit();
|
echo "<p class='error'>Veuillez entrer 3 caractères minimum.</p>";
|
||||||
|
} else {
|
||||||
|
echo "<script>requestToApi('" . $_POST['author'] . "')</script>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once("class/dump.php");
|
|
||||||
|
|
||||||
$author_name = $_POST['author'];
|
|
||||||
|
|
||||||
$these_array = dump::getTheseByAuthor($author_name);
|
|
||||||
|
|
||||||
$json = json_encode($these_array, JSON_PRETTY_PRINT);
|
|
||||||
|
|
||||||
echo '<pre>';
|
|
||||||
var_dump($json);
|
|
||||||
echo '</pre>';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
<div id="results"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -2,9 +2,14 @@
|
|||||||
|
|
||||||
require_once("../class/these.php");
|
require_once("../class/these.php");
|
||||||
require_once("../class/dump.php");
|
require_once("../class/dump.php");
|
||||||
|
require_once("../class/conf.php");
|
||||||
|
|
||||||
|
if (($handle = fopen("2021-09-15-theses.csv", "r")) !== FALSE) {
|
||||||
|
|
||||||
|
$pdo_obj = new conf();
|
||||||
|
$pdo = $pdo_obj->getPDO();
|
||||||
|
$stmt = $pdo->query("TRUNCATE `projet_prog_web`.`theses`");
|
||||||
|
|
||||||
if (($handle = fopen("dump_abes_thesesfr.csv", "r")) !== FALSE) {
|
|
||||||
$row = 1;
|
$row = 1;
|
||||||
$new_these = these::emptyThese();
|
$new_these = these::emptyThese();
|
||||||
while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) {
|
while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) {
|
||||||
@@ -14,9 +19,14 @@ if (($handle = fopen("dump_abes_thesesfr.csv", "r")) !== FALSE) {
|
|||||||
$new_these->insertField($data[$c], $c);
|
$new_these->insertField($data[$c], $c);
|
||||||
}
|
}
|
||||||
$dump = new dump($new_these);
|
$dump = new dump($new_these);
|
||||||
|
try {
|
||||||
$dump->sendThese();
|
$dump->sendThese();
|
||||||
|
} catch (Exception) {
|
||||||
|
echo "<br><br>Failed on (" . $row .") :<br>";
|
||||||
|
var_dump($new_these);
|
||||||
|
}
|
||||||
} $row++;
|
} $row++;
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
echo "CSV file imported into DB.";
|
echo "<br><br>CSV file imported into DB. (" . $row . " results)";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,10 +64,27 @@ body {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
#results {
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 10px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 15px;
|
||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.result-element {
|
||||||
|
box-shadow: rgba(0, 0, 0, 0.10) 2px 2px 8px;
|
||||||
|
background-color: rgba(250, 250, 250, 0.5);
|
||||||
|
border-radius: 3px;
|
||||||
|
margin: 0 5px 5px 5px;
|
||||||
|
padding: 5px 10px 10px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
/* Small */
|
/* Small */
|
||||||
@media (min-width: 576px) {
|
@media (min-width: 576px) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user