hier der code (erklärungen weiter unten):
Code: Alles auswählen
<?php
/**
* $Revision: 1.10 $
* $Source: D:/cvs/cvsrepo/test/PPI_Nade/module/articleList/output.php,v $
* $Date: 2005/11/28 10:42:26 $
*/
/**
* articleList
* @author Andreas Kummer
* @copyright Copyright © 2005 w3concepts AG
*/
class articleList {
/**
* Konstruktor der Klasse.
* @param Integer Primärschlüssel der Artikelkategorie.
*/
function articleList($myIdCat) {
global $client, $lang, $idcat;
$this->myIdCat = $myIdCat;
$this->client = $client;
$this->lang = $lang;
$this->idcat = $idcat;
$this->db = new DB_Contenido();
}
/**
* Setzt den vor der Artikelliste auszugebenden HTML-Code.
* @param String HTML-Code, der vor der Artikelliste ausgegeben werden
* soll.
*/
function setBefore($before) {
$this->before = $before;
}
/**
* Setzt den nach der Artikelliste auszugebenden HTML-Code.
* @param String HTML-Code, der nach der Artikelliste ausgegeben werden
* soll.
*/
function setAfter($after) {
$this->after = $after;
}
/**
* Setzt das Template (respektive die Maske) für die Ausgabe eines Teasers.
* Für die Ausgabe wird der Titel sowie die Artikelbeschreibung verwendet.
* @param String Template für die Asugabe des Teasers. Folgende Platzhalter
* sind vorgesehen {title} für den Titel, {teaser} für die
* Artikelbeschreibung, {idcat} für die Artikelkategorie sowie {idart} für
* die Artikelidentifikation, {link} für die Artikelreferenzierung und
* {created} für das Erstellungsdatum.
*/
function setTeaserMask($mask) {
$this->mask = $mask;
}
/**
* Gibt die Artikelliste zurück. Die Ausgabe an den Browser muss dann über
* ein echo oder ein print erfolgen.
* @param String Sortierkriterium. Zur Auswahl stehen: 'created'
* (Erstellungsdatum), 'modified' (Aktualisierungsdatum), 'sorted'
* (Contenido-Sortierkriterium), 'alphabetical' (alphabetisch nach Titel).
* @param Boolean True für aufsteigende Sortierung, false für absteigend.
* @param Integer Maximale Anzahl Artikel, die angezeigt werden sollen.
* Wird 0 angegeben, werden alle Artikel ausgegeben.
*/
function getArticleList($sortOrder, $asc, $maxArticles = 0) {
/*
* Ordnungsprinzip fest legen
*/
$order = ($asc) ? ('ASC') : ('DESC');
/*
* Sortierkriterium fest legen
*/
switch ($sortOrder) {
case 'created':
$sortCriteria = 'b.created '.$order;
break;
case 'modified':
$sortCriteria = 'b.lastmodified '.$order;
break;
case 'sorted':
$sortCriteria = 'b.artsort '.$order.', b.title '.$order;
break;
case 'alphabetical':
$sortCriteria = 'b.title '.$order;
break;
default:
$sortCriteria = 'b.created '.$order;
}
/*
* Artikel aus der Datenbank lesen
*/
$articles = $this->getArticles($this->myIdCat, $this->lang, $sortCriteria, $maxArticles);
/*
* Rückgabewert initialisieren
*/
$returnValue = '';
if (!empty($articles)) {
$returnValue = $this->before;
foreach ($articles as $article) {
if ($article['online'] == 1) {
$mask = $this->mask;
if ($article['redirect'] != '0') {
$article['link'] = $article['redirect'];
}
foreach ($article as $part => $content) {
$mask = str_replace('{'.$part.'}',$content,$mask);
}
$returnValue .= $mask;
}
}
$returnValue .= $this->after;
}
return $returnValue;
}
function getArticles($idcat, $idlang, $sortCriteria, $limit) {
global $cfg;
/*
* Initialisierung des Rückgabewertes
*/
$returnValue = array();
/*
* Setzen der Abfragelimiten
*/
if ($limit != 0) {
$limit = "LIMIT 0, $limit";
} else {
$limit = '';
}
/*
* Absetzen des Queries.
*/
$this->db->query("" .
"SELECT " .
" b.idart, " .
" b.title, " .
" b.summary, " .
" b.created, " .
" b.lastmodified, " .
" b.artsort, " .
" b.redirect_url, " .
" b.online, " .
" DATE_FORMAT(b.created, '%d.%m.%y') as erstellungsdatum, " .
" DATE_FORMAT(b.lastmodified, '%d.%m.%y') as aktualisierungsdatum " .
"FROM {$cfg['tab']['cat_art']} as a " .
"LEFT JOIN {$cfg['tab']['art_lang']} as b ON a.idart = b.idart " .
"LEFT JOIN {$cfg['tab']['cat_lang']} as c ON a.idcat = c.idcat " .
"WHERE " .
" a.idcat = $idcat " .
" AND b.idlang = {$this->lang} " .
" AND c.startidartlang != b.idartlang " .
"ORDER BY " .
" $sortCriteria " .
"$limit" .
"");
while ($this->db->next_record()) {
$returnValue[] = array(
'teasertitle'=>$this->db->f('title'),
'teaser'=>$this->db->f('summary'),
'idcat'=>$idcat,
'idart'=>$this->db->f('idart'),
'link'=>'front_content.php?idcat='.$idcat.'&idart='.$this->db->f('idart'),
'redirect'=>$this->db->f('redirect_url'),
'online'=>$this->db->f('online'),
'created'=>$this->db->f('erstellungsdatum'));
}
return $returnValue;
}
}
$articleList = new articleList("CMS_VALUE[1]");
$articleList->setBefore('');
$articleList->setAfter('');
$articleList->setTeaserMask('
<div class="teaserBlock">
<div class="teaserBlockLink">
<a href="{link}">
<img src="images/templateImages/buchWeissAufOrange.png" alt="Erfahren Sie mehr..."/>
</a>
</div>
<div class="teaserBlockTitle">{teasertitle}</div>
<div class="teaserBlockContent">{created}_ {teaser}</div>
</div>
');
echo $articleList->getArticleList('created', false);
?>
mit der methode setTeaserMask wird die maske für die ausgabe eines teaser gesetzt. als platzhalter dienen: teasertitle, created, teaser, idart, idcat und link (jeweils in geschweiften klammern, vgl. beispiel).
der teasertitle entspricht dem titel (achtung: nicht seitentitel, sondern titel) des artikels. der teaser selber wird aus dem summary genommen (zusammenfassung).
für die konfiguration wird die klasse chooseTree verwendet:
Code: Alles auswählen
?><?
/**
* $Revision: 1.7 $
* $Source: D:/cvs/cvsrepo/test/PPI_Nade/module/articleList/input.php,v $
* $Date: 2005/11/25 17:41:12 $
*/
/**
* chooseTree
* @author Andreas Kummer
* @copyright Copyright © 2005 w3concepts AG
*/
if (!class_exists('chooseTree')) {
class chooseTree {
function chooseTree($selected, $index) {
global $lang, $client;
$this->selected = $selected;
$this->index = $index;
$this->lang = $lang;
$this->client = $client;
$this->db = new DB_Contenido();
$this->queryStructure();
$this->outputInterface();
}
function queryStructure() {
global $cfg;
$this->db->query("" .
"SELECT " .
" a.idcat, " .
" a.level, " .
" c.name " .
"FROM {$cfg['tab']['cat_tree']} AS a, " .
"{$cfg['tab']['cat']} AS b, " .
"{$cfg['tab']['cat_lang']} AS c " .
"WHERE " .
" a.idcat = b.idcat " .
" AND b.idcat = c.idcat " .
" AND c.idlang = '{$this->lang}' " .
" AND b.idclient = '{$this->client}' " .
" AND c.visible=1 " .
"ORDER BY " .
" a.idtree" .
"");
$this->structure = array();
while ($this->db->next_record()) {
$this->structure[$this->db->f('idcat')] = array('level'=>$this->db->f('level'), 'name'=>$this->db->f('name'));
}
}
function outputInterface() {
/*
* Tabellenanfang ausgeben
*/
echo "<table cellspacing=\"0\" cellpadding=\"10\" border=\"0\">";
/*
* Zeilenanfang ausgeben
*/
echo "<tr><td>Baum wählen:</td><td>";
/*
* Select-Feld ausgeben
*/
echo $this->getSelect($this->structure, $this->index);
/*
* Zeilenende ausgeben
*/
echo "</td></tr>";
/*
* Tabellenende ausgeben
*/
echo "</table>";
}
function getSelect($structure, $name) {
$returnValue = '<select size="1" name="'.$name.'" class="text_medium">'."\n";
foreach ($structure as $idcat => $item) {
if ($idcat == $this->selected) {
$selected = ' selected = "selected"';
} else {
$selected = '';
}
$spaces = "|";
for ($i = 0; $i < $item['level']; $i ++) {
$spaces = $spaces . "--";
}
$spaces .= ">";
$returnValue .= '<option value="'.$idcat.'"'.$selected.'>'.$spaces.$item['name'].'</option>';
}
$returnValue .= '</select>'."\n";
return $returnValue;
}
}
}
$chooseTree = new chooseTree("CMS_VALUE[1]", "CMS_VAR[1]");
regards,
andreas