parent
f65450427f
commit
04d571cc88
@ -1,45 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue