Lehrplan: 4 Modul-Detailseiten + lehrplan.php + simulationen.php + 78 Anker
- Gemeinsamer Partial App/pages/_partials/modul_detail.php - modul-klima/fluss/heli/stadt als 3-Zeilen-Wrapper - lehrplan.php: Filter Land/Thema/Typ, TOC, URL-Persistenz - simulationen.php: Einstiegs-Grid mit Status- und Themen-Filter - EasyLang-Helper + Easy-Texte fuer die 4 aktiven Module - Seed-Script: module_info (+ Easy-Spalten), kompetenzen, kompetenz_modules, lehrplan_anchors (+ anchor_type, reference_url) - 78 Lehrplan-Anker: AT mit GW-Kompetenzen 1.9/2.1/4.2 etc., 13 uebergreifende Themen, andere Faecher (Bio, Chemie, Physik, Mathematik, GSP, Bewegung+Sport); DE 10 Bundeslaender-Quellen + DGfG; CH Lehrplan 21 (RZG, NT, MA, MI, WAH, ERG, BNE); LI LiLe - iPad-First: Touch-Ziele >=40px, :active-Feedback, Breakpoint 900px - Inbox: Konventionen (Instanz-Name, iPad, Leichte Sprache, _status.md, Git-Commits) umgesetzt Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* EasyLang — Hilfsklasse für Leichte Sprache
|
||||
* ------------------------------------------
|
||||
* Liest pro eingeloggtem Schüler, ob der Flag "Leichte Sprache" (students.easy_language)
|
||||
* aktiv ist, und liefert im Zweifel die Easy-Variante eines Textes; sonst die Normalform.
|
||||
*
|
||||
* Verwendung in Modul-Detailseiten:
|
||||
*
|
||||
* require_once __DIR__ . '/../php/lib/EasyLang.php';
|
||||
* $shortDesc = EasyLang::pick($m['short_desc'], $m['short_desc_easy']);
|
||||
*
|
||||
* `isActive()` cached das Resultat pro Request. Kein DB-Call pro `pick()`.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../config/db.php';
|
||||
|
||||
class EasyLang
|
||||
{
|
||||
private static ?bool $active = null;
|
||||
|
||||
/**
|
||||
* True, wenn der aktuelle Besucher die Easy-Sprache aktiviert hat.
|
||||
* - Eingeloggter Schüler: `students.easy_language`
|
||||
* - Gast / Lehrperson: false (Lehrpersonen sehen die Normalform)
|
||||
*/
|
||||
public static function isActive(): bool
|
||||
{
|
||||
if (self::$active !== null) return self::$active;
|
||||
|
||||
// Session ggf. starten
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
@session_start();
|
||||
}
|
||||
|
||||
$studentId = $_SESSION['student_id'] ?? null;
|
||||
if (!$studentId) return self::$active = false;
|
||||
|
||||
try {
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare('SELECT easy_language FROM students WHERE id = ? AND deleted_at IS NULL');
|
||||
$stmt->execute([$studentId]);
|
||||
$flag = $stmt->fetchColumn();
|
||||
self::$active = ($flag === 1 || $flag === '1' || $flag === true);
|
||||
} catch (Throwable $e) {
|
||||
self::$active = false; // DB-Fehler → Normalform
|
||||
}
|
||||
return self::$active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert `$easy`, wenn Easy-Modus aktiv und `$easy` nicht leer — sonst `$normal`.
|
||||
* Für Strings, JSON-Arrays und beliebige Textfelder.
|
||||
*/
|
||||
public static function pick(?string $normal, ?string $easy): ?string
|
||||
{
|
||||
if (self::isActive() && $easy !== null && $easy !== '') {
|
||||
return $easy;
|
||||
}
|
||||
return $normal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Für Tests / UI-Zwecke: erlaubt das manuelle Setzen (z.B. Vorschau-Modus
|
||||
* für Lehrpersonen). Kein Persistieren — nur für den aktuellen Request.
|
||||
*/
|
||||
public static function override(?bool $active): void
|
||||
{
|
||||
self::$active = $active;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user