migration for news table in database, news now read from database
This commit is contained in:
44
migrations/003_news_table.sql
Normal file
44
migrations/003_news_table.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
-- =====================================================================
|
||||
-- Migration 004: Creates News Table for Municipality Announcements
|
||||
-- =====================================================================
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 1: Creates Table "news"
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS news (
|
||||
news_id SERIAL PRIMARY KEY,
|
||||
municipality_id INTEGER NOT NULL REFERENCES municipalities(municipality_id) ON DELETE CASCADE,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
author_name VARCHAR(100) NOT NULL DEFAULT 'Stadtverwaltung',
|
||||
published_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 2: Trigger Functions
|
||||
-- ---------------------------------------------------------------------
|
||||
|
||||
-- Automatically Refresh updated_at on every UPDATE.
|
||||
CREATE TRIGGER set_news_updated_at
|
||||
BEFORE UPDATE ON news
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION set_updated_at();
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 4: Indexes for fast Queries
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE INDEX idx_news_municipality ON news(municipality_id);
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Block 8: Seed Data — Initial News Article
|
||||
-- ---------------------------------------------------------------------
|
||||
INSERT INTO news (municipality_id, title, content)
|
||||
SELECT municipality_id, 'Mitmachkarte gestartet',
|
||||
'Die Mitmachkarte als Bürgerbeteiligungsportal der Stadt Lohne (Oldenburg) wird nun freigeschaltet. Wir freuen uns auf Ihre Hinweise und Vorschläge!'
|
||||
FROM municipalities WHERE slug = 'lohne';
|
||||
@@ -34,6 +34,11 @@ if (!$municipality) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Loads News for Sidebar
|
||||
$stmt = $pdo->prepare("SELECT * FROM news WHERE municipality_id = :mid ORDER BY published_at DESC LIMIT 10");
|
||||
$stmt->execute([':mid' => $municipality['municipality_id']]);
|
||||
$news_items = $stmt->fetchAll();
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
@@ -207,12 +212,17 @@ if (!$municipality) {
|
||||
<span class="leaflet-sidebar-close"><i class="fa-solid fa-xmark"></i></span>
|
||||
</h2>
|
||||
<div class="sidebar-body">
|
||||
<?php if (empty($news_items)): ?>
|
||||
<p style="text-align:center;color:#999;padding:20px;">Noch keine Neuigkeiten veröffentlicht.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($news_items as $news): ?>
|
||||
<div class="news-item">
|
||||
<span class="news-date">April 2026</span>
|
||||
<h3>Portal gestartet</h3>
|
||||
<p>Das Bürgerbeteiligungsportal für <?= htmlspecialchars($municipality['name']) ?> ist online. Wir freuen uns auf Ihre Hinweise und Vorschläge!</p>
|
||||
<span class="news-date"><?= date('d.m.Y', strtotime($news['published_at'])) ?></span>
|
||||
<h3><?= htmlspecialchars($news['title']) ?></h3>
|
||||
<p><?= nl2br(htmlspecialchars($news['content'])) ?></p>
|
||||
</div>
|
||||
<!-- News Items can be added or loaded from Database here -->
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user