Skip to content

Instantly share code, notes, and snippets.

@tbaddade
Last active July 30, 2020 14:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tbaddade/4748841 to your computer and use it in GitHub Desktop.
Save tbaddade/4748841 to your computer and use it in GitHub Desktop.
REDAXO :: sortieren der Slices eines Artikels
<?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();
}
}
}
Copy link

ghost commented Feb 14, 2013

hmm, ich steh grad irgendwie aufm schlauch :| in einer frischen 4.5 geht dein code snippet aufjedenfall. deshalb vermute ich, dass das prob ganz auf meiner seite liegen muss...

übrigens: das gnaze noch in ne funktion packen, module_type optional als paramter und im idealfall ab in den core admit ;)

@tbaddade
Copy link
Author

@rexdude Funktion oder Klasse? Muss ich mal sehen. So wird es nicht bleiben.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment