You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
46 lines
1.4 KiB
<?php
|
|
|
|
class CitationModel {
|
|
|
|
private $filePath = __DIR__ . '/../citation.txt';
|
|
|
|
// Fonction pour obtenir la citation du jour
|
|
public function getCitationDuJour() {
|
|
if (!file_exists($this->filePath)) {
|
|
return null;
|
|
}
|
|
|
|
$citations = file($this->filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
foreach ($citations as $citation) {
|
|
$parts = explode(';', $citation);
|
|
// Vérifier si la citation commence par 'µ'
|
|
if (strpos(trim($parts[0]), 'µ') === 0) {
|
|
return $parts; // Retourne la citation du jour
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Fonction pour obtenir les suggestions de citations
|
|
public function getSuggestions($citationDuJour) {
|
|
if (!file_exists($this->filePath)) {
|
|
return [];
|
|
}
|
|
|
|
$citations = file($this->filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
$suggestions = [];
|
|
|
|
foreach ($citations as $citation) {
|
|
$parts = explode(';', $citation);
|
|
// On ajoute la citation si elle n'est pas la citation du jour
|
|
if (!($parts[0] === $citationDuJour[0])) {
|
|
$suggestions[] = $parts;
|
|
}
|
|
}
|
|
|
|
// Limiter à 10 suggestions
|
|
shuffle($suggestions);
|
|
return array_slice($suggestions, 0, 10);
|
|
}
|
|
}
|