--[[----------------------------------------------------------------------------

WFCatSortByRating.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2015 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

--==============================================================================

local WFCatSortByRating = {}

--------------------------------------------------------------------------------

function WFCatSortByRating.executeSort( wfCatalog, assetIds, order)

	if order ~= "ASC" then
		order = "DESC"
	end

	local sqlString = string.format(
			[[ SELECT ratings.docId, ratings.rating 
				FROM TEMP_ids 
				LEFT JOIN ratings ON ratings.docId = TEMP_ids.docId 
				ORDER BY ratings.rating %s, ratings.captureDate %s, ratings.filenameLC COLLATE i18n_collate %s, ratings.docId %s ]],
			order, order, order, order )

	return wfCatalog:indexStore():query( {
			sql = sqlString,
			tempIds = assetIds,
			calm = 1,
		} )
		
end


--==============================================================================

return WFCatSortByRating
