@ -3015,86 +3015,101 @@ namespace Emby.Server.Implementations.Data
return " ORDER BY " + string . Join ( ',' , orderBy . Select ( i = >
{
var columnMap = MapOrderByField ( i . OrderBy , query ) ;
var sortOrder = columnMap . SortOrder = = SortOrder . Ascending ? "ASC" : "DESC" ;
return columnMap. S ortBy + " " + sortOrder ;
var sortBy = MapOrderByField ( i . OrderBy , query ) ;
var sortOrder = i . SortOrder = = SortOrder . Ascending ? "ASC" : "DESC" ;
return s ortBy + " " + sortOrder ;
} ) ) ;
}
private ( string SortBy , SortOrder SortOrder ) MapOrderByField ( string name , InternalItemsQuery query )
private string MapOrderByField ( string name , InternalItemsQuery query )
{
if ( string . Equals ( name , ItemSortBy . AirTime , StringComparison . OrdinalIgnoreCase ) )
{
// TODO
return ( "SortName" , SortOrder . Ascending ) ;
return "SortName" ;
}
else if ( string . Equals ( name , ItemSortBy . Runtime , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . Runtime , StringComparison . OrdinalIgnoreCase ) )
{
return ( "RuntimeTicks" , SortOrder . Ascending ) ;
return "RuntimeTicks" ;
}
else if ( string . Equals ( name , ItemSortBy . Random , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . Random , StringComparison . OrdinalIgnoreCase ) )
{
return ( "RANDOM()" , SortOrder . Ascending ) ;
return "RANDOM()" ;
}
else if ( string . Equals ( name , ItemSortBy . DatePlayed , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . DatePlayed , StringComparison . OrdinalIgnoreCase ) )
{
if ( query . GroupBySeriesPresentationUniqueKey )
{
return ( "MAX(LastPlayedDate)" , SortOrder . Ascending ) ;
return "MAX(LastPlayedDate)" ;
}
return ( "LastPlayedDate" , SortOrder . Ascending ) ;
return "LastPlayedDate" ;
}
else if ( string . Equals ( name , ItemSortBy . PlayCount , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . PlayCount , StringComparison . OrdinalIgnoreCase ) )
{
return ( "PlayCount" , SortOrder . Ascending ) ;
return "PlayCount" ;
}
else if ( string . Equals ( name , ItemSortBy . IsFavoriteOrLiked , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . IsFavoriteOrLiked , StringComparison . OrdinalIgnoreCase ) )
{
return ( "(Select Case When IsFavorite is null Then 0 Else IsFavorite End )" , SortOrder . Descending ) ;
return "(Select Case When IsFavorite is null Then 0 Else IsFavorite End )" ;
}
else if ( string . Equals ( name , ItemSortBy . IsFolder , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . IsFolder , StringComparison . OrdinalIgnoreCase ) )
{
return ( "IsFolder" , SortOrder . Descending ) ;
return "IsFolder" ;
}
else if ( string . Equals ( name , ItemSortBy . IsPlayed , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . IsPlayed , StringComparison . OrdinalIgnoreCase ) )
{
return ( "played" , SortOrder . Descending ) ;
return "played" ;
}
else if ( string . Equals ( name , ItemSortBy . IsUnplayed , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . IsUnplayed , StringComparison . OrdinalIgnoreCase ) )
{
return ( "played" , SortOrder . Descending ) ;
return "played" ;
}
else if ( string . Equals ( name , ItemSortBy . DateLastContentAdded , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . DateLastContentAdded , StringComparison . OrdinalIgnoreCase ) )
{
return ( "DateLastMediaAdded" , SortOrder . Ascending ) ;
return "DateLastMediaAdded" ;
}
else if ( string . Equals ( name , ItemSortBy . Artist , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . Artist , StringComparison . OrdinalIgnoreCase ) )
{
return ( "(select CleanValue from itemvalues where ItemId=Guid and Type=0 LIMIT 1)" , SortOrder . Ascending ) ;
return "(select CleanValue from itemvalues where ItemId=Guid and Type=0 LIMIT 1)" ;
}
else if ( string . Equals ( name , ItemSortBy . AlbumArtist , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . AlbumArtist , StringComparison . OrdinalIgnoreCase ) )
{
return ( "(select CleanValue from itemvalues where ItemId=Guid and Type=1 LIMIT 1)" , SortOrder . Ascending ) ;
return "(select CleanValue from itemvalues where ItemId=Guid and Type=1 LIMIT 1)" ;
}
else if ( string . Equals ( name , ItemSortBy . OfficialRating , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . OfficialRating , StringComparison . OrdinalIgnoreCase ) )
{
return ( "InheritedParentalRatingValue" , SortOrder . Ascending ) ;
return "InheritedParentalRatingValue" ;
}
else if ( string . Equals ( name , ItemSortBy . Studio , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . Studio , StringComparison . OrdinalIgnoreCase ) )
{
return ( "(select CleanValue from itemvalues where ItemId=Guid and Type=3 LIMIT 1)" , SortOrder . Ascending ) ;
return "(select CleanValue from itemvalues where ItemId=Guid and Type=3 LIMIT 1)" ;
}
else if ( string . Equals ( name , ItemSortBy . SeriesDatePlayed , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . SeriesDatePlayed , StringComparison . OrdinalIgnoreCase ) )
{
return ( "(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText ( query ) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)" , SortOrder . Ascending ) ;
return "(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText ( query ) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)" ;
}
else if ( string . Equals ( name , ItemSortBy . SeriesSortName , StringComparison . OrdinalIgnoreCase ) )
if ( string . Equals ( name , ItemSortBy . SeriesSortName , StringComparison . OrdinalIgnoreCase ) )
{
return ( "SeriesName" , SortOrder . Ascending ) ;
return "SeriesName" ;
}
return ( name , SortOrder . Ascending ) ;
return name ;
}
public List < Guid > GetItemIdsList ( InternalItemsQuery query )