WIP: newssection index

This commit is contained in:
marko
2025-06-14 06:30:00 +02:00
parent 107bdf4fdb
commit 8848f95fe6
5 changed files with 108 additions and 59 deletions

View File

@@ -1,48 +1,72 @@
<?php <?php
/// Ausgabe einer newsTabelle /// Ausgabe einer newsTabelle
function echoNewsTableHtml($someOptions){ function echoNewsTableHtml($someOptions)
{
global $cwsvJudoConfig; global $cwsvJudoConfig;
global $basePath; global $basePath;
// Sammlung von Fehlermeldungen o.ä. // Sammlung von Fehlermeldungen o.ä.
$message = array(); $message = [];
$limit = is_positive_integer($someOptions['limit'])?$someOptions['limit']:1; $limit = is_positive_integer($someOptions["limit"])
? $someOptions["limit"]
: 1;
$headerRootLevel = is_positive_integer($someOptions['headerRootLevel'])?$someOptions['headerRootLevel']:1; $headerRootLevel = is_positive_integer($someOptions["headerRootLevel"])
? $someOptions["headerRootLevel"]
: 1;
/// Eine Datenbankverbindung (über pdo) erstellen /// Eine Datenbankverbindung (über pdo) erstellen
try { try {
$db_connection = new PDO( $db_connection = new PDO(
"mysql:host=".$cwsvJudoConfig["db"]["host"].";"."dbname=".$cwsvJudoConfig["db"]["name"], "mysql:host=" .
$cwsvJudoConfig["db"]["host"] .
";" .
"dbname=" .
$cwsvJudoConfig["db"]["name"],
$cwsvJudoConfig["db"]["user"], $cwsvJudoConfig["db"]["user"],
$cwsvJudoConfig["db"]["password"] $cwsvJudoConfig["db"]["password"]
); );
} } catch (PDOException $db_error) {
catch(PDOException $db_error){ $messages["errors"][] = "Error: " . $db_error->getMessage();
$messages['errors'][] = "Error: " . $db_error->getMessage();
} }
// News abfragen // News abfragen
// @todo: woher das limit nehmen? // @todo: woher das limit nehmen?
// $newsList = getNews($db_connection, array('limit'=>$limit)); // $newsList = getNews($db_connection, array('limit'=>$limit));
$newsList = getNews($db_connection, $someOptions); $newsList = getNews(aMysqlConn: $db_connection, optionsArray: $someOptions);
$newsHeading = "Aktuelle Meldungen"; $newsHeading = "Aktuelle Meldungen";
if($someOptions['newsId']??false) $newsHeading=$newsList[0]['betreff']; if ($someOptions["newsId"] ?? false) {
if($someOptions['jahr']??false) $newsHeading="Nachrichten des Jahres ".$someOptions['jahr']; $newsHeading = $newsList[0]["betreff"];
}
if ($someOptions["jahr"] ?? false) {
$newsHeading = "Nachrichten des Jahres " . $someOptions["jahr"];
}
echo("<h".strval($headerRootLevel).">".$newsHeading."</h".$headerRootLevel.">"); echo "<h" .
if( is_array( $newsList ) || is_object( $newsList ) ) strval($headerRootLevel) .
foreach($newsList as $news) ">" .
echo( getHtmlNews($news, "headingLevel=".strval($headerRootLevel+1))."<hr />" ); $newsHeading .
else "</h" .
$messages['errors'][] = "Fehler: Keine Neuigkeiten gefunden!"; $headerRootLevel .
">";
if (is_array($newsList) || is_object($newsList)) {
foreach ($newsList as $news) {
echo getHtmlNews(
$news,
"headingLevel=" . strval($headerRootLevel + 1)
) . "<hr />";
};
} else {
$messages["errors"][] = "Fehler: Keine Neuigkeiten gefunden!";
}
// @todo: besser machen! // @todo: besser machen!
if(!empty($messages)) if (!empty($messages)) {
var_dump($messages); var_dump($messages);
}
return; return;
} }

View File

@@ -1,4 +1,4 @@
<? <?php
/** /**
* home directory on the server * home directory on the server
* - meaning the users home directory (aka ~) in the environment, not the directory served via http * - meaning the users home directory (aka ~) in the environment, not the directory served via http

View File

@@ -153,18 +153,22 @@ function main($sections, $wallpapers)
<!-- - materialize framework --> <!-- - materialize framework -->
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
const elems = document.querySelectorAll('.parallax'); const instances = {
const instances = M.Parallax.init(elems, { parallax : M.Parallax.init(
document.querySelectorAll('.parallax'), {
// specify options here // specify options here
}); }
),
// const elems = document.querySelectorAll('.carousel'); carousels: M.Carousel.init(
// const instances = M.Carousel.init(elems, { document.querySelectorAll('.carousel'), {
// // fullWidth: true, dist: -50,
// // indicators: true, fullWidth: true,
// // noWrap: true, indicators: true,
// // numVisible: 6, noWrap: true,
// }); numVisible: 1,
}
),
} // end instances
}); });
</script> </script>
</body> </body>

View File

@@ -91,9 +91,20 @@ class PromoImage
return $data; return $data;
} }
public function as_html()
{
return '<img src="' .
$this->src .
'" width="' .
$this->width .
'" heigth="' .
$this->height .
'" >';
}
private string $src; private string $src;
private int $width; private ?int $width;
private int $height; private ?int $height;
public array $data; public array $data;
} }
@@ -110,13 +121,20 @@ class Entry
$this->title = $data["betreff"]; $this->title = $data["betreff"];
$this->content = $data["nachricht"]; $this->content = $data["nachricht"];
$this->author = $data["autor"]; $this->author = $data["autor"];
// $this->promo = new PromoImage( $this->promo = new PromoImage(
// json_encode($data["promoImg"])); json_decode($data["promoImg"], associative: true)
);
} }
function as_card(): string function as_card(): string
{ {
return '<div class="col s12 m6 l3"><div class="card">' . return '<div class="card horizontal">' .
'<div class="card-image">' .
'<span class="card-title">' .
$this->title .
"</span>" .
$this->promo->as_html() .
"</div>" .
'<div class="card-content">' . '<div class="card-content">' .
'<span class="card-title">' . '<span class="card-title">' .
$this->title . $this->title .
@@ -125,7 +143,7 @@ class Entry
$this->content . $this->content .
"</p>" . "</p>" .
"</div>" . "</div>" .
"</div></div>"; "</div>";
} }
// private // private
// - member variables // - member variables
@@ -207,15 +225,15 @@ function getNews(
function newsBoard(\CwsvJudo\Db\Connector $dbHandle, array $options): string function newsBoard(\CwsvJudo\Db\Connector $dbHandle, array $options): string
{ {
$boardHtml = '<div class="container"><div class="row">'; $boardHtml = '<div class=""><h2>Neuigkeiten</h2>';
$entries = getNews(dbHandle: $dbHandle, options: $options); $entries = getNews(dbHandle: $dbHandle, options: $options);
if (!is_null($entries)) { if (!is_null($entries)) {
foreach ($entries as $entryData) { foreach ($entries as $entryData) {
$entry = new \CwsvJudo\News\Entry($entryData); $entry = new \CwsvJudo\News\Entry($entryData);
$boardHtml .= $entry->as_card(); $boardHtml .= '<div class="">' . $entry->as_card() . "</div>";
} }
} }
$boardHtml .= "</div></div>"; $boardHtml .= "</div> ";
return $boardHtml; return $boardHtml;
} }

View File

@@ -0,0 +1,3 @@
<?php
namespace cwsvJudo\news;