Added back for disciplines and years charts

This commit is contained in:
Florian Sylvain
2022-01-08 18:54:04 +01:00
parent 80880dd377
commit ffffd33a82
4 changed files with 89 additions and 5 deletions
+1
View File
@@ -6,5 +6,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="highcharts.src" level="application" />
</component>
</module>
+2
View File
@@ -24,6 +24,8 @@ $json_object = match ($q) {
"theses" => dump::getTheses($search, $option, $offset),
"suggestion" => dump::getSuggestions($search, $option),
"count" => dump::getThesesCount($search, $option),
"years" => dump::getThesesYears($search, $option),
"disciplines" => dump::getThesesDisciplines($search, $option),
default => NULL,
};
+1 -1
View File
@@ -66,6 +66,7 @@ function apiRequestThese(search, offset) {
emptyResults(true)
pagesNumbers.innerHTML = ""
loader.style.display = "block"
pagesNumbersContainer.style.display = 'none'
searchString = sanitize(search)
fetch(`api.php?q=theses&search=${searchString}&option=${queryOption}&offset=${offset}`)
.then(response => response.json())
@@ -132,7 +133,6 @@ function displayResults(results, aCount) {
error.classList.remove("fade-out");
error.classList.add("fade-in");
errorMessage.innerHTML = results.message
pagesNumbersContainer.style.display = 'none'
} else if (results.status === 200) {
count = aCount
resultsArray = []
+84 -3
View File
@@ -49,7 +49,7 @@ class dump {
while ($obj = $stmt->fetchObject()) {
$theses_array[$i] = array();
foreach ($obj as $elem) {
array_push($theses_array[$i], empty($elem) ? "Non définit" : $elem);
$theses_array[$i][] = empty($elem) ? "Non définit" : $elem;
}
$i++;
}
@@ -81,7 +81,7 @@ class dump {
while ($obj = $stmt->fetchObject()) {
foreach ($obj as $elem) {
array_push($array, $elem);
$array[] = $elem;
}
}
@@ -116,13 +116,94 @@ class dump {
while ($obj = $stmt->fetchObject()) {
foreach ($obj as $elem) {
array_push($array, $elem);
$array[] = $elem;
}
}
return $array;
}
public static function getThesesYears(string $search, string $option) : array {
$years_array = [];
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$search = '%' . $search . '%';
$stmt = match ($option) {
'auto' => $pdo->prepare("
SELECT DATE_FORMAT(date_soutenance, '%Y') AS Date,
COUNT(DATE_FORMAT(date_soutenance, '%Y')) AS Number
FROM `theses`
WHERE author LIKE :search
OR title LIKE :search
OR these_director LIKE :search
OR soutenance_establishment LIKE :search
GROUP BY Date
ORDER BY Date;
"),
'author' => $pdo->prepare("SELECT DATE_FORMAT(date_soutenance, '%Y') AS Date, COUNT(DATE_FORMAT(date_soutenance, '%Y')) AS Number FROM `theses` WHERE author LIKE :search GROUP BY Date ORDER BY Date;"),
'title' => $pdo->prepare("SELECT DATE_FORMAT(date_soutenance, '%Y') AS Date, COUNT(DATE_FORMAT(date_soutenance, '%Y')) AS Number FROM `theses` WHERE title LIKE :search GROUP BY Date ORDER BY Date;"),
'director' => $pdo->prepare("SELECT DATE_FORMAT(date_soutenance, '%Y') AS Date, COUNT(DATE_FORMAT(date_soutenance, '%Y')) AS Number FROM `theses` WHERE these_director LIKE :search GROUP BY Date ORDER BY Date;"),
'establishment' => $pdo->prepare("SELECT DATE_FORMAT(date_soutenance, '%Y') AS Date, COUNT(DATE_FORMAT(date_soutenance, '%Y')) AS Number FROM `theses` WHERE soutenance_establishment LIKE :search GROUP BY Date ORDER BY Date;"),
default => "",
};
$stmt->bindParam(':search', $search, PDO::PARAM_STR, 100);
$stmt->execute();
$i = 0;
while ($obj = $stmt->fetchObject()) {
$years_array[$i] = array();
$years_array[$i][$obj->Date] = $obj->Number;
$i++;
}
return $years_array;
}
public static function getThesesDisciplines(string $search, string $option) : array {
$disciplines_array = [];
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$search = '%' . $search . '%';
$stmt = match ($option) {
'auto' => $pdo->prepare("
SELECT discipline AS Discipline,
COUNT(discipline) AS Number
FROM `theses`
WHERE author LIKE :search
OR title LIKE :search
OR these_director LIKE :search
OR soutenance_establishment LIKE :search
GROUP BY Discipline
ORDER BY `Number` DESC
LIMIT 10
"),
'author' => $pdo->prepare("SELECT discipline AS Discipline, COUNT(discipline) AS Number FROM `theses` WHERE author LIKE :search GROUP BY Discipline ORDER BY `Number` DESC LIMIT 10;"),
'title' => $pdo->prepare("SELECT discipline AS Discipline, COUNT(discipline) AS Number FROM `theses` WHERE title LIKE :search GROUP BY Discipline ORDER BY `Number` DESC LIMIT 10;"),
'director' => $pdo->prepare("SELECT discipline AS Discipline, COUNT(discipline) AS Number FROM `theses` WHERE these_director LIKE :search GROUP BY Discipline ORDER BY `Number` DESC LIMIT 10;"),
'establishment' => $pdo->prepare("SELECT discipline AS Discipline, COUNT(discipline) AS Number FROM `theses` WHERE soutenance_establishment LIKE :search GROUP BY Discipline ORDER BY `Number` DESC LIMIT 10;"),
default => "",
};
$stmt->bindParam(':search', $search, PDO::PARAM_STR, 100);
$stmt->execute();
$i = 0;
while ($obj = $stmt->fetchObject()) {
$disciplines_array[$i] = array();
$disciplines_array[$i][$obj->Discipline] = $obj->Number;
$i++;
}
return $disciplines_array;
}
public function sendThese($pdo) {
$data = [
'author' => $this->these->getAuthor(),