Use an i18n tool

This commit is contained in:
Gregory Trolliet 2020-11-23 11:01:37 +01:00
parent e487438606
commit 16dec853f9
12 changed files with 662 additions and 97 deletions

47
db.php
View file

@ -7,9 +7,10 @@ class DataBase
const OPTIONS_DURATION = array(
'day' => '+1 day',
'week' => '+7 day',
'2week' => '+14 day',
'week2' => '+14 day',
'month' => '+1 month'
);
const DEFAULT_SIZE = 3;
private $db;
@ -123,12 +124,22 @@ class DataBase
");
$stmt->bindValue(':id', $id);
$stmt->execute();
$words = [];
$words = [];
$values = [];
$total = 0;
$max = 0;
while ($data = $stmt->fetch()) {
$words[] = array($data['word'], $data['count']);
$words[] = array(
'word' => $data['word'],
'count' => $data['count'],
);
$values[] = $data['count'];
$total += $data['count'];
$max = max($max, $data['count']);
}
foreach ($words as $key => $word) {
$words[$key]['relative'] = $word['count'] / $max;
$words[$key]['percent'] = $word['count'] / $total * 100;
}
array_multisort($values, SORT_DESC, $words);
@ -152,15 +163,12 @@ class DataBase
public function getWordsRelative(string $id)
{
$words = $this->getWordsList($id);
$max = 0;
foreach ($words as $word) {
$max = max($max, $word[1]);
}
$wordsClean = [];
foreach ($words as $key => $word) {
$words[$key] = array($word[0], $word[1] / $max);
$wordsClean[] = array($word['word'], $word['relative']);
}
return $words;
return $wordsClean;
}
public function createCloud(
@ -206,7 +214,7 @@ class DataBase
if ($data = $stmt->fetch()) {
return $data['size'];
}
return null;
return 0;
}
public function getCloudText(string $ref)
@ -214,7 +222,7 @@ class DataBase
$stmt = $this->db->prepare("
SELECT *
FROM clouds
WHERE code= :code;
WHERE code = :code;
");
$stmt->bindValue(':code', $ref, PDO::PARAM_STR);
$stmt->execute();
@ -224,6 +232,23 @@ class DataBase
return null;
}
public function countWords(string $cloud)
{
$stmt = $this->db->prepare("
SELECT count(*) as count
FROM clouds
JOIN words
ON id_cloud = cloud_id
WHERE code = :code;
");
$stmt->bindValue(':code', $cloud, PDO::PARAM_STR);
$stmt->execute();
if ($data = $stmt->fetch()) {
return $data['count'];
}
return null;
}
public function cleanCloud()
{
$stmt = $this->db->prepare("