|
|
|
|
|
https://www.dnnwerk.at Joined: 6/27/2005
Posts: 2083
|
|
|
Well... this works only for the title, and not for the columns set in the settings, which are completely ignored.
If you're courageous enough, run this script (from Host :: SQL - don't forget to check "Run as script", and I strongly recommend that you make a backup of the {objectQualifier}GetDocuments procedure before you do that. I tried it using SQL Server 2005 Express, DNN 04.08.04 and Documents 04.00.00, and it worked for me, but if you do that, you'll do it at your own risk!!!):
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE {databaseOwner}{objectQualifier}GetDocuments
@ModuleId int,
@PortalId int
AS
DECLARE @SortOrder nvarchar(2000)
DECLARE @sql nvarchar(max)
SET @SortOrder = (SELECT SortOrder FROM {databaseOwner}{objectQualifier}DocumentsSettings WHERE ModuleID = @ModuleId)
SET @SortOrder = REPLACE(@SortOrder, '-SortIndex', '{objectQualifier}Files.{objectQualifier}Documents.SortOrderIndex DESC')
SET @SortOrder = REPLACE(@SortOrder, 'SortIndex', '{objectQualifier}Files.{objectQualifier}Documents.SortOrderIndex')
SET @SortOrder = REPLACE(@SortOrder, '-Title', '{objectQualifier}Files.{objectQualifier}Documents.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'Title', '{objectQualifier}Files.{objectQualifier}Documents.Title')
SET @SortOrder = REPLACE(@SortOrder, '###', 'Title')
SET @SortOrder = REPLACE(@SortOrder, '-Owner', 'OwnedByUser.LastName + '' '' + OwnedByUser.FirstName DESC')
SET @SortOrder = REPLACE(@SortOrder, 'Owner', 'OwnedByUser.LastName + '' '' + OwnedByUser.FirstName')
SET @SortOrder = REPLACE(@SortOrder, '-Category', '{objectQualifier}Files.{objectQualifier}Documents.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'Category', '{objectQualifier}Files.{objectQualifier}Documents.Category')
SET @SortOrder = REPLACE(@SortOrder, '###', 'Category')
SET @SortOrder = REPLACE(@SortOrder, '-ModifiedDate', '{objectQualifier}Files.{objectQualifier}Documents.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'ModifiedDate', '{objectQualifier}Files.{objectQualifier}Documents.ModifiedDate')
SET @SortOrder = REPLACE(@SortOrder, '###', 'ModifiedDate')
SET @SortOrder = REPLACE(@SortOrder, '-Size', '{objectQualifier}Files.{objectQualifier}Files.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'Size', '{objectQualifier}Files.{objectQualifier}Files.Size')
SET @SortOrder = REPLACE(@SortOrder, '###', 'Size')
SET @SortOrder = REPLACE(@SortOrder, '-CreatedBy', '###User.LastName + '' '' + ###User.FirstName DESC')
SET @SortOrder = REPLACE(@SortOrder, 'CreatedBy', 'CreatedByUser.LastName + '' '' + CreatedByUser.FirstName')
SET @SortOrder = REPLACE(@SortOrder, '###', 'CreatedBy')
SET @SortOrder = REPLACE(@SortOrder, '-CreatedDate', '{objectQualifier}Files.{objectQualifier}Documents.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'CreatedDate', '{objectQualifier}Files.{objectQualifier}Documents.CreatedDate')
SET @SortOrder = REPLACE(@SortOrder, '###', 'CreatedDate')
SET @SortOrder = REPLACE(@SortOrder, '-ModifiedBy', '###User.LastName + '' '' + ###User.FirstName DESC')
SET @SortOrder = REPLACE(@SortOrder, 'ModifiedBy', 'ModifiedByUser.LastName + '' '' + ModifiedByUser.FirstName')
SET @SortOrder = REPLACE(@SortOrder, '###', 'ModifiedBy')
SET @SortOrder = REPLACE(@SortOrder, '-Description', '{objectQualifier}Files.{objectQualifier}Documents.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'Description', '{objectQualifier}Files.{objectQualifier}Documents.Description')
SET @SortOrder = REPLACE(@SortOrder, '###', 'Description')
SET @SortOrder = REPLACE(@SortOrder, '-Clicks', '{objectQualifier}Files.{objectQualifier}UrlTracking.### DESC')
SET @SortOrder = REPLACE(@SortOrder, 'Clicks', '{objectQualifier}Files.{objectQualifier}UrlTracking.TrackClicks')
SET @SortOrder = REPLACE(@SortOrder, '###', 'TrackClicks')
SET @sql = '
SELECT {objectQualifier}Documents.ItemID, {objectQualifier}Documents.ModuleID, {objectQualifier}Documents.Title, {objectQualifier}Documents.URL,
CreatedByUser.FirstName + '' '' + CreatedByUser.LastName AS ''CreatedByUser'',
OwnedByUser.FirstName + '' '' + OwnedByUser.LastName AS ''OwnedByUser'',
ModifiedByUser.FirstName + '' '' + ModifiedByUser.LastName AS ''ModifiedByUser'', {objectQualifier}Documents.Category, {objectQualifier}Files.Size, {objectQualifier}UrlTracking.TrackClicks,
{objectQualifier}UrlTracking.Clicks, {objectQualifier}UrlTracking.NewWindow, {objectQualifier}Documents.OwnedByUserID, {objectQualifier}Documents.ModifiedByUserID, {objectQualifier}Documents.ModifiedDate,
{objectQualifier}Documents.CreatedByUserID, {objectQualifier}Documents.CreatedDate, {objectQualifier}Documents.SortOrderIndex, {objectQualifier}Documents.Description
FROM {objectQualifier}Documents LEFT OUTER JOIN
{objectQualifier}Users AS CreatedByUser ON {objectQualifier}Documents.CreatedByUserID = CreatedByUser.UserID LEFT OUTER JOIN
{objectQualifier}Users AS OwnedByUser ON {objectQualifier}Documents.OwnedByUserID = OwnedByUser.UserID LEFT OUTER JOIN
{objectQualifier}Users AS ModifiedByUser ON {objectQualifier}Documents.ModifiedByUserID = ModifiedByUser.UserID LEFT OUTER JOIN
{objectQualifier}Files ON {objectQualifier}Documents.URL = ''fileid='' + CONVERT(varchar, {objectQualifier}Files.FileId) LEFT OUTER JOIN
{objectQualifier}UrlTracking ON {objectQualifier}Documents.URL = {objectQualifier}UrlTracking.Url AND {objectQualifier}UrlTracking.ModuleId = ' + CAST(@ModuleId AS nvarchar(10)) + '
WHERE ({objectQualifier}Documents.ModuleID = ' + CAST(@ModuleId AS nvarchar(10)) + ')'
IF NOT LEN(@SortOrder) = 0
SET @sql = @sql + ' ORDER BY ' + @SortOrder
EXEC sp_executesql @sql
Good luck!
Michael
|
|
|
|
| |
|
|
Joined: 1/7/2008
Posts: 11
|
|
|
Here is a fixed version of the above which had a bunch of stray "{objectQualifier}Files." where "{databaseOwner}" should have been:
SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO
ALTER PROCEDURE {databaseOwner}{objectQualifier}GetDocuments
@ModuleId int, @PortalId int AS DECLARE @SortOrder nvarchar(2000) DECLARE @sql nvarchar(max)
SET @SortOrder = (SELECT SortOrder FROM {databaseOwner}{objectQualifier}DocumentsSettings WHERE ModuleID = @ModuleId)
SET @SortOrder = REPLACE(@SortOrder, '-SortIndex', '{databaseOwner}{objectQualifier}Documents.SortOrderIndex DESC') SET @SortOrder = REPLACE(@SortOrder, 'SortIndex', '{databaseOwner}{objectQualifier}Documents.SortOrderIndex') SET @SortOrder = REPLACE(@SortOrder, '-Title', '{databaseOwner}{objectQualifier}Documents.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'Title', '{databaseOwner}{objectQualifier}Documents.Title') SET @SortOrder = REPLACE(@SortOrder, '###', 'Title') SET @SortOrder = REPLACE(@SortOrder, '-Owner', 'OwnedByUser.LastName + '' '' + OwnedByUser.FirstName DESC') SET @SortOrder = REPLACE(@SortOrder, 'Owner', 'OwnedByUser.LastName + '' '' + OwnedByUser.FirstName') SET @SortOrder = REPLACE(@SortOrder, '-Category', '{databaseOwner}{objectQualifier}Documents.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'Category', '{databaseOwner}{objectQualifier}Documents.Category') SET @SortOrder = REPLACE(@SortOrder, '###', 'Category') SET @SortOrder = REPLACE(@SortOrder, '-ModifiedDate', '{databaseOwner}{objectQualifier}Documents.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'ModifiedDate', '{databaseOwner}{objectQualifier}Documents.ModifiedDate') SET @SortOrder = REPLACE(@SortOrder, '###', 'ModifiedDate') SET @SortOrder = REPLACE(@SortOrder, '-Size', '{databaseOwner}{objectQualifier}Files.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'Size', '{databaseOwner}{objectQualifier}Files.Size') SET @SortOrder = REPLACE(@SortOrder, '###', 'Size') SET @SortOrder = REPLACE(@SortOrder, '-CreatedBy', '###User.LastName + '' '' + ###User.FirstName DESC') SET @SortOrder = REPLACE(@SortOrder, 'CreatedBy', 'CreatedByUser.LastName + '' '' + CreatedByUser.FirstName') SET @SortOrder = REPLACE(@SortOrder, '###', 'CreatedBy') SET @SortOrder = REPLACE(@SortOrder, '-CreatedDate', '{databaseOwner}{objectQualifier}Documents.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'CreatedDate', '{databaseOwner}{objectQualifier}Documents.CreatedDate') SET @SortOrder = REPLACE(@SortOrder, '###', 'CreatedDate') SET @SortOrder = REPLACE(@SortOrder, '-ModifiedBy', '###User.LastName + '' '' + ###User.FirstName DESC') SET @SortOrder = REPLACE(@SortOrder, 'ModifiedBy', 'ModifiedByUser.LastName + '' '' + ModifiedByUser.FirstName') SET @SortOrder = REPLACE(@SortOrder, '###', 'ModifiedBy') SET @SortOrder = REPLACE(@SortOrder, '-Description', '{databaseOwner}{objectQualifier}Documents.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'Description', '{databaseOwner}{objectQualifier}Documents.Description') SET @SortOrder = REPLACE(@SortOrder, '###', 'Description') SET @SortOrder = REPLACE(@SortOrder, '-Clicks', '{databaseOwner}{objectQualifier}UrlTracking.### DESC') SET @SortOrder = REPLACE(@SortOrder, 'Clicks', '{databaseOwner}{objectQualifier}UrlTracking.TrackClicks') SET @SortOrder = REPLACE(@SortOrder, '###', 'TrackClicks')
SET @sql = ' SELECT {objectQualifier}Documents.ItemID, {objectQualifier}Documents.ModuleID, {objectQualifier}Documents.Title, {objectQualifier}Documents.URL, CreatedByUser.FirstName + '' '' + CreatedByUser.LastName AS ''CreatedByUser'', OwnedByUser.FirstName + '' '' + OwnedByUser.LastName AS ''OwnedByUser'', ModifiedByUser.FirstName + '' '' + ModifiedByUser.LastName AS ''ModifiedByUser'', {objectQualifier}Documents.Category, {objectQualifier}Files.Size, {objectQualifier}UrlTracking.TrackClicks, {objectQualifier}UrlTracking.Clicks, {objectQualifier}UrlTracking.NewWindow, {objectQualifier}Documents.OwnedByUserID, {objectQualifier}Documents.ModifiedByUserID, {objectQualifier}Documents.ModifiedDate, {objectQualifier}Documents.CreatedByUserID, {objectQualifier}Documents.CreatedDate, {objectQualifier}Documents.SortOrderIndex, {objectQualifier}Documents.Description FROM {objectQualifier}Documents LEFT OUTER JOIN {objectQualifier}Users AS CreatedByUser ON {objectQualifier}Documents.CreatedByUserID = CreatedByUser.UserID LEFT OUTER JOIN {objectQualifier}Users AS OwnedByUser ON {objectQualifier}Documents.OwnedByUserID = OwnedByUser.UserID LEFT OUTER JOIN {objectQualifier}Users AS ModifiedByUser ON {objectQualifier}Documents.ModifiedByUserID = ModifiedByUser.UserID LEFT OUTER JOIN {objectQualifier}Files ON {objectQualifier}Documents.URL = ''fileid='' + CONVERT(varchar, {objectQualifier}Files.FileId) LEFT OUTER JOIN {objectQualifier}UrlTracking ON {objectQualifier}Documents.URL = {objectQualifier}UrlTracking.Url AND {objectQualifier}UrlTracking.ModuleId = ' + CAST(@ModuleId AS nvarchar(10)) + ' WHERE ({objectQualifier}Documents.ModuleID = ' + CAST(@ModuleId AS nvarchar(10)) + ')'
IF NOT LEN(@SortOrder) = 0 SET @sql = @sql + ' ORDER BY ' + @SortOrder
EXEC sp_executesql @sql
Same instructions as above; don't forget to check "Run as script". This worked for me on Documents 4.0.0, DNN 4.5.5, and SQL Server 2000 (after changing the nvarchar(max) to nvarchar(4000) - The script as provided should be fine for SQL Server 2005).
Thanks go to Michael, and enjoy!
|
|
|
|
| |