Last active
July 30, 2020 14:09
-
-
Save tbaddade/4748841 to your computer and use it in GitHub Desktop.
REDAXO :: sortieren der Slices eines Artikels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// -------------------------------- Einstellungen | |
$article_id = 2; // Artikel Id | |
$clang = false; // Sprachen Id --------- false = aktuelle Sprache | |
$ctype = 0; // Ctype Id ------------ 0 = alle Ctypes | |
$slices_amount = 2; // Anzahl der Slices --- 0 = alle Slices | |
// -------------------------------- alle Slices holen | |
$slices = OOArticleSlice::getSlicesForArticle( $article_id, $clang ); | |
if (is_object($slices)) { | |
echo $slices->getSlice(); | |
} else { | |
// -------------------------------- Slices korrekt sortieren | |
$slice_ids = array(); | |
$slice_counter = array(); | |
$c = 0; | |
foreach ($slices as $slice) { | |
$slice_ids [ $slice->_re_article_slice_id ] = $slice->getId(); | |
$slice_counter[ $slice->_re_article_slice_id ] = $c; | |
$c++; | |
} | |
$_id = 0; | |
$slices_sort = array(); | |
foreach ($slices as $slice) { | |
$_next_id = $slice_ids[ $_id ]; | |
if ($ctype > 0 && $ctype != $slices[$slice_counter[$_id]]->_ctype) { | |
$_id = $_next_id; | |
continue; | |
} | |
$slices_sort[ $slices[$slice_counter[$_id]]->_ctype ][] = $slices[$slice_counter[$_id]]; | |
$_id = $_next_id; | |
} | |
ksort($slices_sort); | |
// -------------------------------- auf $slices_amount Slices beschraenken | |
$slices_out = array(); | |
if ($slices_amount > 0) { | |
foreach ($slices_sort as $ctype => $slices) { | |
$slices_out[$ctype] = array_slice($slices, 0, $slices_amount); | |
} | |
} | |
// -------------------------------- Ausgabe der Slices | |
foreach ($slices_out as $ctype => $slices) { | |
foreach ($slices as $slice) { | |
echo $slice->getSlice(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rexdude Funktion oder Klasse? Muss ich mal sehen. So wird es nicht bleiben.