Ich habe hier ein Modul, welches Katgorien ausliest und nach bestimte Kriterien sortiert.
Doch leider sortiert der diese nur in deutscher Sprache aber nicht in den 3 restlichen.
Wie könnte ich das beheben? Ich weiss das es daran liegt und das die sortierfunktion vor dem fallback gemacht werden sollte. Nur leider weiss ich nicht wie.
Über hilfe wäre ich echt dankbar.
Gruß Eru
Schnipsel worum es geht:
Code: Alles auswählen
if (count($article_list) > 0)
{
$c = 0;
foreach ($article_list as $article)
{
$fallback = OOArticle::getArticleById($article->getId(), 0);
$c++;
$name = '';
$name = $article->getValue('art_teaser_hdl');
if ($name == '')
$name = $fallback->getName();
$desc = $article->getValue('art_teaser_text');
if ($desc == '')
$desc = $fallback->getValue('art_teaser_text');
$file = $fallback->getValue('art_teaser_file');
$phone = $article->getValue('art_teaser_tel');
if ($phone == '')
$phone = $fallback->getValue('art_teaser_tel');
$star = $fallback->getValue('art_teaser_stern');
if ($star == '')
$star = '0';
Code: Alles auswählen
<?php
/*
Anwendung
$category = OOCategory::getCategoryById(5);
$articles = $category->getArticles();
if (count($articles) > 0) {
// Sortierfunktion aufrufen
usort($articles, "sortArticlesByPrio");
}
*/
//////////////////////////////////////////////////////// Artikel sortieren
// Nach Artikelnamen
if(!function_exists('sortArticlesByLocation')) {
function sortArticlesByLocation( $artA, $artB) {
$nameA = $artA->_art_teaser_text;
$nameB = $artB->_art_teaser_text;
if ( $nameA == $nameB) {
return 0;
}
$names = array($nameA,$nameB);
sort( $names, SORT_STRING);
return $names[0] == $nameA ? -1 : 1;
}
}
// Nach Prio
if (!function_exists('sortArticlesByPrio')) {
// Sortierfunktion
function sortArticlesByPrio( $artA, $artB) {
$prioA = $artA->getPriority();
$prioB = $artB->getPriority();
if ( $prioA == $prioB) {
return 0;
}
return $prioA > $prioB ? 1 : -1;
}
}
if (!function_exists('sortArticlesByPrioDesc')) {
// Sortierfunktion
function sortArticlesByPrioDesc( $artA, $artB) {
$prioA = $artA->getPriority();
$prioB = $artB->getPriority();
if ( $prioA == $prioB) {
return 0;
}
return $prioA > $prioB ? -1 : 1;
}
}
// Nach Create Date
if(!function_exists('sortArticlesByCreateDate')) {
function sortArticlesByCreateDate( $artA, $artB) {
$createA = $artA->getCreateDate();
$createB = $artB->getCreateDate();
if ( $createA == $createB) {
return 0;
}
return $createA > $createB ? -1 : 1;
}
}
// Nach Update Date
if(!function_exists('sortArticlesByUpdateDate')) {
function sortArticlesByUpdateDate( $artA, $artB) {
$updateA = $artA->getUpdateDate();
$updateB = $artB->getUpdateDate();
if ( $updateA == $updateB) {
return 0;
}
return $updateA > $updateB ? -1 : 1;
}
}
// Nach Online From Date
if(!function_exists('sortArticlesByOnlineFromDate')) {
function sortArticlesByOnlineFromDate( $artA, $artB) {
$ofromA = $artA->_art_online_from;
$ofromB = $artB->_art_online_from;
if ( $ofromA == $ofromB) {
return 0;
}
return $ofromA > $ofromB ? 1 : -1;
}
}
if(!function_exists('sortArticlesByOnlineFromDateDesc')) {
function sortArticlesByOnlineFromDateDesc( $artA, $artB) {
$ofromA = $artA->_art_online_from;
$ofromB = $artB->_art_online_from;
if ( $ofromA == $ofromB) {
return 0;
}
return $ofromA > $ofromB ? -1 : 1;
}
}
// Nach Online To Date
if(!function_exists('sortArticlesByOnlineToDate')) {
function sortArticlesByOnlineToDate( $artA, $artB) {
$otoA = $artA->_art_online_to;
$otoB = $artB->_art_online_to;
if ( $otoA == $otoB) {
return 0;
}
return $otoA > $otoB ? -1 : 1;
}
}
//////////////////////////////////////////////////////// Medien sortieren
// Nach Update Date
if(!function_exists('sortMediaByUpdateDate')) {
function sortMediaByUpdateDate( $artA, $artB) {
$updateA = $artA->getUpdateDate();
$updateB = $artB->getUpdateDate();
if ( $updateA == $updateB) {
return 0;
}
//return $updateA > $updateB ? -1 : 1;
return $updateA > $updateB ? 1 : -1;
}
}
?>
<?php
if (!function_exists('ep_checkOnlineDate'))
{
function ep_checkOnlineDate($date, $article_date)
{
if ($date > 0 && $article_date == '')
return false;
elseif ($date > 0 && $article_date < $date)
return false;
return true;
}
}
$out = '';
$article_total = 'REX_VALUE[6]';
$article_per_page = 'REX_VALUE[2]';
$mode = 'REX_VALUE[3]';
$sort = 'REX_VALUE[5]';
$date_start = 'REX_VALUE[8]';
$hdl_tag = 'REX_VALUE[7]';
if ($hdl_tag == '')
$hdl_tag = 'h3';
$cat_id = 0;
if ($mode == 't' || $mode == 'tf')
$cat_id = REX_CATEGORY_ID;
elseif ($mode == 'c' || $mode == 'cf')
$cat_id = 'REX_VALUE[4]';
$date_start_time = 0;
if ($date_start != '')
{
$date_start_arr = explode('|', $date_start);
$date_start_time = mktime('0', '0', '0', date('m'), date('d'), date('Y'));
$date_seconds = $date_start_arr[1] * 24 * 60 * 60;
switch ($date_start_arr)
{
case '-':
$date_start_time = $date_start_time - $date_seconds;
break;
case '+':
$date_start_time = $date_start_time + $date_seconds;
break;
}
// echo date('d.m.Y - H:i:s', $date_start_time);
}
$page = rex_request('page', 'int', '1');
$month_abbr = array();
$month_abbr[0][1] = 'Jan';
$month_abbr[0][2] = 'Feb';
$month_abbr[0][3] = 'Mrz';
$month_abbr[0][4] = 'Apr';
$month_abbr[0][5] = 'Mai';
$month_abbr[0][6] = 'Jun';
$month_abbr[0][7] = 'Jul';
$month_abbr[0][8] = 'Aug';
$month_abbr[0][9] = 'Sep';
$month_abbr[0][10] = 'Okt';
$month_abbr[0][11] = 'Nov';
$month_abbr[0][12] = 'Dez';
// OOArticel werden gespeichert
$article_list = array();
// Artikel holen fuer Modus
// -> seitenuebergreifend
if ($mode == 'p')
{
$sql = new rex_sql();
// $sql->debugsql = true;
$sql->setQuery('SELECT id FROM rex_article WHERE art_teaser = "|true|" AND status = "1" AND id != "REX_ARTICLE_ID"');
$rows = $sql->getRows();
if ($rows >= 1)
{
for ($i = 1; $i <= $rows; $i++, $sql->next())
{
$ooarticle = OOArticle::getArticleById($sql->getValue('id'));
if (ep_checkOnlineDate($date_start_time, $ooarticle->getValue('art_online_from')) )
$article_list[] = $ooarticle;
}
}
}
// Artikel holen fuer Modus
// -> Aktuelle Kategorie
// -> Kategorie wählen
if (($mode == 't' || $mode == 'c') && $cat_id > 0)
{
$articles = OOArticle::getArticlesOfCategory($cat_id, true);
foreach ($articles as $ooarticle)
{
if ($ooarticle->isStartArticle())
continue;
/*
if ($ooarticle->getValue('art_teaser') != '|true|')
continue;
*/
// Endlosschleife vermeiden
if ($ooarticle->getId() == REX_ARTICLE_ID)
continue;
if (ep_checkOnlineDate($date_start_time, $ooarticle->getValue('art_online_from')) )
$article_list[] = $ooarticle;
}
}
// Artikel holen fuer Modus
// -> Aktuelle Kategorie und alle darunter
// -> Kategorie wählen und alle darunter
if (($mode == 'tf' || $mode == 'cf') && $cat_id > 0)
{
$sql = new rex_sql();
$sql_lang = new rex_sql();
// $sql->debugsql = true;
$sql->setQuery('SELECT id FROM rex_article WHERE REX_VALUE[15] = "|true|" AND status = "1" AND id != "REX_ARTICLE_ID" AND path LIKE "%|'.$cat_id.'|%" ');
$rows = $sql->getRows();
if ($rows >= 1)
{
for ($i = 1; $i <= $rows; $i++, $sql->next())
{
$ooarticle = OOArticle::getArticleById($sql->getValue('id'));
if (ep_checkOnlineDate($date_start_time, $ooarticle->getValue('art_online_from')) )
$article_list[] = $ooarticle;
}
}
}
// Sortierung
if (count($article_list) > 0)
{
$sort_arr = explode('|', $sort);
$sort_f = strtolower($sort_arr[0]); // Feld
$sort_c = strtolower($sort_arr[1]); // Kriterium (ASC / DESC)
if ($sort_f == 'prior' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByPrio");
elseif ($sort_f == 'prior' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByPrioDesc");
elseif ($sort_f == 'ort' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByLocation");
elseif ($sort_f == 'ort' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByLocationDesc");
elseif ($sort_f == 'name' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByTeaserName");
elseif ($sort_f == 'name' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByTeaserNameDesc");
elseif ($sort_f == 'open' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByTeaserName");
elseif ($sort_f == 'open' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByTeaserNameDesc");
elseif ($sort_f == 'date' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByTeaserDate");
elseif ($sort_f == 'date' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByTeaserDateDesc");
}
if ($article_total > 0)
{
$article_list = array_slice($article_list, 0, $article_total);
}
$navi_pag = '';
if ($article_per_page > 0)
{
$articles_length = count($article_list);
$pages = ceil($articles_length / $article_per_page);
//$offset = $page - 1;
$offset = ($page * $article_per_page) - $article_per_page;
$article_list = array_slice($article_list, $offset, $article_per_page);
// Pagination
for ($i = 1; $i <= $pages; $i++)
{
$param = '';
if ($page == $i)
$param .= ' active';
if ($i == 1)
$param .= ' first';
if ($param != '')
$param = ' class="'.trim($param).'"';
$navi_pag .= '<li'.$param.'><a'.$param.' href="'.rex_getUrl('', '', array('page' => $i)).'">'.$i.'</a></li>';
}
}
if (count($article_list) > 0)
{
$c = 0;
foreach ($article_list as $article)
{
$fallback = OOArticle::getArticleById($article->getId(), 0);
$c++;
$name = '';
$name = $article->getValue('art_teaser_hdl');
if ($name == '')
$name = $fallback->getName();
$desc = $article->getValue('art_teaser_text');
if ($desc == '')
$desc = $fallback->getValue('art_teaser_text');
$file = $fallback->getValue('art_teaser_file');
$phone = $article->getValue('art_teaser_tel');
if ($phone == '')
$phone = $fallback->getValue('art_teaser_tel');
$star = $fallback->getValue('art_teaser_stern');
if ($star == '')
$star = '0';
$s = array (
'0',
'1',
'2',
'3',
'4',
'5'
);
$r = array (
'',
'<div class="sterne"></div>',
'<div class="sterne"></div><div class="sterne"></div>',
'<div class="sterne"></div><div class="sterne"></div><div class="sterne"></div>',
'<div class="sterne"></div><div class="sterne"></div><div class="sterne"></div><div class="sterne"></div>',
'<div class="sterne"></div><div class="sterne"></div><div class="sterne"></div><div class="sterne"></div><div class="sterne"></div>'
);
$stars = str_replace($s, $r, $star);
$teaser_link = $article->getValue('art_teaser_link_intern');
$link_id = '';
if ($teaser_link != '' && $teaser_link > 0)
$link_id = $teaser_link;
else
$link_id = $article->getId();
$link = '';
// Link nur anzeigen, wenn Checkbox deaktiviert ist
if ($article->getValue('art_teaser_link_more') != '|true|')
$link = '<a href="'.rex_getUrl($link_id).'">REX_VALUE[1]</a>';
$hdl = '';
$hdl .= '<'.$hdl_tag.'>';
// nur verlinken, wenn weiterlesen link vorhanden ist
if ($link != '')
$hdl .= '<a href="'.rex_getUrl($link_id).'">';
$hdl .= $name;
if ($link != '')
$hdl .= '</a>';
$hdl .= '</'.$hdl_tag.'>';
$from = '';
if ($article->getValue('art_online_from') != '')
{
$date = $article->getValue('art_online_from');
$d = date('d', $date);
$m = date('n', $date);
$from = '<span class="date"><span class="day">'.$d.'</span><span class="month">'.$month_abbr[$REX['CUR_CLANG']][$m].'</span></span>';
// $from = '<p class="tx1 tsr-date">'.date('d.m.Y', $article->getValue('art_online_from')).'</p>';
}
$class = '';
$file_out = '';
if ($file != "")
{
$class = ' ti-bl';
$src = '';
$srcWidth = 1;
$imageWidth = 150;
$s = getimagesize($REX['HTDOCS_PATH'].'files/'.$file);
if ($s[0] > $imageWidth)
{
$src = '/index.php?rex_resize=150w__'.$file;
$srcWidth = $imageWidth;
}
else
{
$src = $REX['HTDOCS_PATH'].'files/'.$file;
$srcWidth = $s[0];
}
$factor = $s[0] / $srcWidth;
$srcHeight = round($s[1] / $factor);
$media = OOMedia::getMediaByName($file);
$title = $media->getTitle();
$file_out = '';
// nur verlinken, wenn weiterlesen link vorhanden ist
if ($link != '')
$file_out .= '<a href="'.rex_getUrl($link_id).'">';
$file_out .= '<img src="'.$src.'" title="'.$title.'" alt="'.$title.'" width="'.$srcWidth.'" height="'.$srcHeight.'" />'.$from;
if ($link != '')
$file_out .= '</a>';
$file_out .= '';
}
$text_out = '';
if($desc != '')
{
$textile = htmlspecialchars_decode($desc);
$textile = str_replace("<br />", "", $textile);
$textile = rex_a79_textile($textile);
$srch = array();
$rplc = array();
$srch[] = 'href="#fn';
$rplc[] = 'href="'.rex_getUrl().'#fn';
$srch[] = 'href="http://';
$rplc[] = 'href="http://';
$srch[] = 'href="/';
$rplc[] = 'href="/';
$textile = str_replace($srch, $rplc, $textile);
if (substr($textile, -4) == '</p>')
$textile = substr($textile, 0, -4).'</p>';
else
$textile .= '<p class="tsr-lk"></p>';
$text_out = '<div class="content">'.$hdl.$textile.'</div>';
}
$tsr_class = '';
if ($c == 1)
$tsr_class = '';
$out .= '<div id="sortierung_border'.$tsr_class.'">';
$out .= '<div id="sortierung_image">'.$file_out.'</div>';
$out .= '<div id="sortierung_titel">'.$hdl.'</div>';
$out .= '<div id="sortierung_sterne">'.$stars.'</div>';
$out .= '<div id="sortierung_ort">'.$textile.'</div>';
$out .= '<div id="sortierung_telefon">###sort_tel### '.$phone.'</div>';
$out .= '<div id="sortierung_weiter">'.$link.'</div>';
// $out .= $from.$name;
$out .= '<div class="clearer"></div>';
$out .= '</div>';
}
}
if ($navi_pag != '')
$out .= '<div class="pagination"><dl><dt>###seite###</dt><dd><ul>'.$navi_pag.'</ul></dd></dl></div>';
echo $out;
// echo 'REX_VALUE[15]';
?>