It now won't require there to be at least one entry in the motd table.
I also tidied up the motd class
This commit is contained in:
2018-08-06 23:26:29 +02:00
parent 29ac0ece7e
commit 32cc4ec27f
5 changed files with 40 additions and 12 deletions

View File

@@ -10,8 +10,21 @@ class MOTD{
$this->pdo = $pdo;
}
public function getMOTD(){
$query = 'SELECT * FROM motd LIMIT 1';
public function setMOTD($title, $content) {
if (is_array($content)) {
$content = implode("_", $content);
}
$query = 'INSERT INTO motd(title, content) VALUES (:title, :content);';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':title', $title, PDO::PARAM_STR);
$statement->bindParam(':content', $content, PDO::PARAM_STR);
$statement->execute();
}
public function getMOTD() {
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1';
$statement = $this->pdo->prepare($query);
$statement->execute();
@@ -20,4 +33,17 @@ class MOTD{
return $motd;
}
}
public function getMOTD_history($limit = 5) {
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':limit', $limit, PDO::PARAM_STR);
$statement->execute();
$data = $statement->fetch();
$motd = array("title" => $data[0], "content" => explode("\n", $data[1]));
return $motd;
}
}