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
|
||||
/scripts/*.csv
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
require_once("class/dump.php");
|
||||
|
||||
$author_name = $_GET['author'];
|
||||
|
||||
$these_array = dump::getTheseByAuthor($author_name);
|
||||
|
||||
$json = json_encode($these_array, JSON_PRETTY_PRINT);
|
||||
|
||||
echo '<pre>';
|
||||
var_dump($json);
|
||||
echo '</pre>';
|
||||
$json = json_encode($these_array);
|
||||
print_r($json);
|
||||
|
||||
@@ -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
|
||||
|
||||
ini_set('max_execution_time', 0);
|
||||
|
||||
require_once("these.php");
|
||||
require_once("conf.php");
|
||||
|
||||
@@ -22,7 +24,7 @@ class dump {
|
||||
|
||||
$pdo_obj = new conf();
|
||||
$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;
|
||||
while ($obj = $stmt->fetchObject()) {
|
||||
$theses_array[$i] = array();
|
||||
|
||||
+8
-16
@@ -5,29 +5,21 @@
|
||||
<meta name="viewport"
|
||||
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">
|
||||
<script src="app.js"></script>
|
||||
<link rel="stylesheet" href="stylesheet.css">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
include("navbar.php");
|
||||
|
||||
if (!isset($_POST['author'])) {
|
||||
exit();
|
||||
if (isset($_POST['author'])) {
|
||||
if (strlen($_POST['author']) < 3) {
|
||||
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>
|
||||
</html>
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
|
||||
require_once("../class/these.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;
|
||||
$new_these = these::emptyThese();
|
||||
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);
|
||||
}
|
||||
$dump = new dump($new_these);
|
||||
$dump->sendThese();
|
||||
try {
|
||||
$dump->sendThese();
|
||||
} catch (Exception) {
|
||||
echo "<br><br>Failed on (" . $row .") :<br>";
|
||||
var_dump($new_these);
|
||||
}
|
||||
} $row++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
pre {
|
||||
#results {
|
||||
font-family: sans-serif;
|
||||
margin: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
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 */
|
||||
@media (min-width: 576px) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user