Skip to content

Instantly share code, notes, and snippets.

@imlucas
Created October 22, 2008 18:34
Show Gist options
  • Save imlucas/18745 to your computer and use it in GitHub Desktop.
Save imlucas/18745 to your computer and use it in GitHub Desktop.
<?php
private static function sortAlbumsByBestSelling($genreIds, $excludeIds = array(),
$perPage, $pageNum, $priceFilter=null){
$sources = array(new Amie_ListGen_Source_DbAlbumSales(),
new Amie_ListGen_Source_DbAlbumSales());
foreach ($sources as $source) {
self::addGenreFilter($genreIds, $source);
self::addPriceFilter($priceFilter, $source);
$source->filterExcludeAlbums($excludeIds);
}
$sources[0]->setWikiFilter('only');
$sources[1]->setWikiFilter('not');
$s = new Amie_ListGen_Source_Concat($sources);
return $s->getPage($perPage, $pageNum);
}
private static function sortAlbumsByCommunityBuzz($genreIds, $excludeIds = array(),
$perPage, $pageNum, $priceFilter=null){
$source = new Amie_ListGen_Source_DbAlbum;
$source->orderByAmieIndexDesc();
$source->filterExcludeAlbums($excludeIds);
self::addGenreFilter($genreIds, $source);
self::addPriceFilter($priceFilter, $source);
return $source->getPage($perPage, $pageNum);
}
private static function sortAlbumsByRecency($genreIds, $excludeIds = array(),
$perPage, $pageNum, $priceFilter=null){
$source = new Amie_ListGen_Source_DbAlbum;
self::addGenreFilter($genreIds, $source);
self::addPriceFilter($priceFilter, $source);
$source->filterExcludeAlbums($excludeIds);
$source->orderByReleaseDateDesc();
return $source->getPage($perPage, $pageNum);
}
private static function addGenreFilter($genreIds, $source) {
if ($genreIds != null) {
if (isset($genreIds[0]) && is_array($genreIds[0])) {
foreach ($genreIds as $idList) {
$source->filterOnlyGenres($idList);
}
} else {
$source->filterOnlyGenres($genreIds);
}
}
}
private static function addPriceFilter($priceFilter, $source) {
if(!is_null($priceFilter)){
if($priceFilter=='priced'){
$source->filterMinPrice('0.01');
}
elseif($priceFilter=='free'){
$source->filterMaxPrice('0');
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment