From 0f425bb06a1517e782a1367b8d481f69aec57b58 Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Fri, 29 Oct 2021 15:11:09 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Introduced=20big=20DB=20(~500=20000?= =?UTF-8?q?=20results)=20and=20multiple=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + ProjetProgWeb/api.php | 9 ++------- ProjetProgWeb/app.js | 26 ++++++++++++++++++++++++++ ProjetProgWeb/class/dump.php | 4 +++- ProjetProgWeb/index.php | 24 ++++++++---------------- ProjetProgWeb/scripts/extract.php | 16 +++++++++++++--- ProjetProgWeb/stylesheet.css | 19 ++++++++++++++++++- 7 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 ProjetProgWeb/app.js diff --git a/.gitignore b/.gitignore index 2f6719b..3d7b7f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /ProjetProgWeb/.env +/scripts/*.csv diff --git a/ProjetProgWeb/api.php b/ProjetProgWeb/api.php index 3c140d3..b203e00 100644 --- a/ProjetProgWeb/api.php +++ b/ProjetProgWeb/api.php @@ -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 '
';
-var_dump($json);
-echo '
'; +$json = json_encode($these_array); +print_r($json); diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js new file mode 100644 index 0000000..659e99a --- /dev/null +++ b/ProjetProgWeb/app.js @@ -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) + + }) +} \ No newline at end of file diff --git a/ProjetProgWeb/class/dump.php b/ProjetProgWeb/class/dump.php index c110700..45cd44c 100644 --- a/ProjetProgWeb/class/dump.php +++ b/ProjetProgWeb/class/dump.php @@ -1,5 +1,7 @@ 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(); diff --git a/ProjetProgWeb/index.php b/ProjetProgWeb/index.php index 3a562b6..2d6894e 100644 --- a/ProjetProgWeb/index.php +++ b/ProjetProgWeb/index.php @@ -5,29 +5,21 @@ + Document Veuillez entrer 3 caractères minimum.

"; + } else { + echo ""; + } } - - require_once("class/dump.php"); - - $author_name = $_POST['author']; - - $these_array = dump::getTheseByAuthor($author_name); - - $json = json_encode($these_array, JSON_PRETTY_PRINT); - - echo '
';
-            var_dump($json);
-            echo '
'; - ?> +
diff --git a/ProjetProgWeb/scripts/extract.php b/ProjetProgWeb/scripts/extract.php index 71808e8..9252255 100644 --- a/ProjetProgWeb/scripts/extract.php +++ b/ProjetProgWeb/scripts/extract.php @@ -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 "

Failed on (" . $row .") :
"; + var_dump($new_these); + } } $row++; } fclose($handle); - echo "CSV file imported into DB."; + echo "

CSV file imported into DB. (" . $row . " results)"; } diff --git a/ProjetProgWeb/stylesheet.css b/ProjetProgWeb/stylesheet.css index 758fede..51781b9 100644 --- a/ProjetProgWeb/stylesheet.css +++ b/ProjetProgWeb/stylesheet.css @@ -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) {