pvv/side: format long queries

This commit is contained in:
2026-01-13 11:15:37 +09:00
parent e84236c84b
commit 5279c588d5
3 changed files with 69 additions and 12 deletions

View File

@@ -56,15 +56,41 @@ class DBActivity implements Activity {
}
public function getNextEventFrom(\DateTimeImmutable $date): ?Event {
$query
= 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1';
$query = '
SELECT
id,
name,
start,
stop,
organiser,
location,
description
FROM events
WHERE
start > :date
ORDER BY start ASC
LIMIT 1
';
return $this->retrieve($date, $query);
}
public function getPreviousEventFrom(\DateTimeImmutable $date): ?Event {
$query
= 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start < :date ORDER BY start DESC LIMIT 1';
$query = '
SELECT
id,
name,
start,
stop,
organiser,
location,
description
FROM events
WHERE
start < :date
ORDER BY start DESC
LIMIT 1
';
return $this->retrieve($date, $query);
}

View File

@@ -19,7 +19,13 @@ class Door {
* @return array{time: DateTimeImmutable, open: bool}[]
*/
public function getAll(): array {
$query = 'SELECT time, open FROM door ORDER BY time DESC';
$query = '
SELECT
time,
open
FROM door
ORDER BY time DESC
';
$statement = $this->pdo->prepare($query);
$statement->execute();
@@ -40,8 +46,14 @@ class Door {
public function getEntriesAfter(\DateTimeImmutable $startTime): array {
$timestamp = $startTime->getTimestamp();
$query
= 'SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC';
$query = '
SELECT
time,
open
FROM door
WHERE time > :startTime
ORDER BY time DESC
';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':startTime', $timestamp, \PDO::PARAM_INT);
$statement->execute();
@@ -61,7 +73,14 @@ class Door {
* @return array{time: DateTimeImmutable, open: bool}
*/
public function getCurrent(): array {
$query = 'SELECT time, open FROM door ORDER BY time DESC LIMIT 1';
$query = '
SELECT
time,
open
FROM door
ORDER BY time DESC
LIMIT 1
';
$statement = $this->pdo->prepare($query);
$statement->execute();
$row = $statement->fetch();

View File

@@ -28,8 +28,14 @@ class MOTD {
* @return array{title: string, content: string[]}
*/
public function getMOTD(): array {
$query
= 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1';
$query = '
SELECT
title,
content
FROM motd
ORDER BY id DESC
LIMIT 1
';
$statement = $this->pdo->prepare($query);
$statement->execute();
@@ -42,8 +48,14 @@ class MOTD {
* @return array{title: string, content: string[]}
*/
public function getMOTD_history(int $limit = 5): array {
$query
= 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit';
$query = '
SELECT
title,
content
FROM motd
ORDER BY id DESC
LIMIT :limit
';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':limit', $limit, \PDO::PARAM_STR);
$statement->execute();