Hallo,
mit dem folgenden Typoskript kann man eine "Menü" der Kategorien erstellen.
Das Menü funktioniert soweit wie es soll (ich weiss ist etwas ungewöhnlich).
Ich möchte jetzt nur noch Kategorien die keine News enthalten ausblenden.
Wie kann ich das am besten erreichen?
In der DB Tabelle tx_news_domain_model_news gibt es zwar das feld "categories" soweit ich das verstanden habe zählt das nur die Anzahl zugewiesener Kategorien.
lib.newsCats = COA_INT
lib.newsCats {
wrap = <ul>|</ul>
10 = CONTENT
10.table = tx_news_domain_model_category
10.select.pidInList = 18
10.select.andWhere = parentcategory=14
10.renderObj = COA
10.renderObj {
wrap = <li>|</li>
10 = TEXT
10.data = debug:data
10.field = title
10.dataWrap = <a id="cat{field:uid}" href="index.php?id=3&tx_news_pi1[overwriteDemand][categories][0]={field:uid}&tx_news_pi1[overwriteDemand][categoryConjunction]=or&tx_news_pi1[action]=list&tx_news_pi1[controller]=News">|</a>
50 = CONTENT
50 {
wrap = <ul>|</ul>
table = tx_news_domain_model_category
select.pidInList = 18
select.andWhere = parentcategory=14
renderObj = TEXT
renderObj.data = debug:data
renderObj.field = title
renderObj.dataWrap = <li class="sub"><a id="cat{field:uid}" href="index.php?id=3&tx_news_pi1[overwriteDemand][categories][0]={field:uid}&tx_news_pi1[overwriteDemand][categoryConjunction]=or&tx_news_pi1[action]=list&tx_news_pi1[controller]=News">|</a></li>
}
}
}
###HOME TRAVEL SEARCH
lib.newssearch = COA
lib.newssearch {
20 < lib.newsCatsReg
20.wrap = <div class="dropDown l"><div class="label">Angebote zu Reisearten</div><ul class="drop"><li>Bitte auswählen<div class="sprite arrowDown"></div><ul class="dropContent">|</ul></ul></div>
}
Danke!
Grüße,
jochen

Vielleicht hilfts ja jemandem.
Ich hab jetzt ne userfunc geschrieben die genau das tut.
Pro:
- Es tut was ich will bzw. der Kunde fordert
Contra:
- zu viele MySQL abfragen
- langsam wenn nicht gecached
- Es werden sachen nochmal abgefragt die tx_news eigentlich weiss ( ... glaub ich )
<?php
Jochen
class user_newsCatsMenu {
var $cObj; // BACK REFS UPPER cObj
/**
* CALL FUNCTION
*/
function main($content,$conf){
$res = mysql(TYPO3_db, 'SELECT * FROM tx_news_domain_model_category WHERE pid = ' . $conf['pidInList'] . ' AND parentcategory = ' . $conf['parentSub']);
// TYPE
$categories = '<ul>';
while($row = mysql_fetch_assoc($res)) {
$resReg = mysql(TYPO3_db, 'SELECT * FROM tx_news_domain_model_category WHERE pid = ' . $conf['pidInList'] . ' AND parentcategory = ' . $conf['parent']);
// GET TYPE RELATION QUERY
$newsMMtype = mysql(TYPO3_db, 'SELECT tx_news_domain_model_category.title, tx_news_domain_model_category.uid, tx_news_domain_model_news_category_mm.uid_local, tx_news_domain_model_news_category_mm.uid_foreign FROM tx_news_domain_model_category, tx_news_domain_model_news_category_mm WHERE tx_news_domain_model_category.uid = tx_news_domain_model_news_category_mm.uid_foreign AND uid_foreign = ' . $row['uid']);
// GET NEWS TYPE AND BUILD ARRAY
$newsArrayTyp = array();
while($newsTyp = mysql_fetch_assoc($newsMMtype)) {
$newsArrayTyp[] = $newsTyp['uid_local'];
}
$types = implode(",", $newsArrayTyp);
$catSubs = '<ul>';
while($region = mysql_fetch_assoc($resReg)) {
//GET REGION RELATION QUERY
$newsMMregion = mysql(TYPO3_db, 'SELECT tx_news_domain_model_category.title, tx_news_domain_model_category.uid, tx_news_domain_model_news_category_mm.uid_local, tx_news_domain_model_news_category_mm.uid_foreign FROM tx_news_domain_model_category, tx_news_domain_model_news_category_mm WHERE tx_news_domain_model_category.uid = tx_news_domain_model_news_category_mm.uid_foreign AND uid_foreign = ' . $region['uid']);
// GET NEWS REGION AND BUILD ARRAY
$newsArrayReg = array();
while($newsReg = mysql_fetch_assoc($newsMMregion)) {
$newsArrayReg[] = $newsReg['uid_local'];
}
//$regions = implode(",", $newsArrayReg);
// COMPARE F****** ARRAYS
$result = array_intersect($newsArrayTyp, $newsArrayReg);
if(!empty($result) ){
$catSubs .= '<li class="' . $region['uid'] . '">' . $region['title'] . '</li>';
}else{
}
}
// SPIT OUT SUBCATEGORIES
$catSubs .= '</ul>';
// SPIT IT OUT
$categories .= '<li class="' . $row['uid'] . '">' . '<a id="cat' . $row['uid'] . '" href="#">' . $row['title'] . $catSubs . '</a>' . '</li>';
}
$categories .= '</ul>';
$content.= $categories;
return $content;
}
}
?>