Select the search type
  • Site
  • Web
Search
You are here:  Support/Forums
Support

Bring2mind Forums

Programatic Creation
Last Post 01/06/2009 4:58 PM by Peter Donker. 9 Replies.
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Arick
New Member
New Member
Posts:64


--
03/18/2008 11:10 PM

Is there any way I can programatically create a new folder with sub folders programtically in v4?  I'm in the process of writing an app that provides us wiht customer inforamtion.  What I'd like is under each customer to have a folder structure that pertains only to that customer without manually having to go in and add a DMX module to the page. More so I'd like to generate this from one page with one DMX module but if that cannot be done I can handle working with multiple pages.  Is this something that is possible without purchasing source code and if so do you have any API documention on how this can be accomplished?

Thanks,

Arick

Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
03/19/2008 9:17 PM
Hi Arick,

This is not hard to do. Go through the DMX.Business.EntriesController (in the dmx core dll) for this. There are a bunch of useful methods there. 1 such method is MakeCollection(ByVal PortalId As Integer, ByVal CollectionId As Integer, ByVal Title As String, ByVal User As UserInfo, ByVal BypassSecurity As Boolean). Note that internally DMX refers to folders as collections (legacy naming). What comes out of the method is an EntryId for the new folder. O, CollectionId 0 is the absolute root of the portal.

Peter
Arick
New Member
New Member
Posts:64


--
03/20/2008 1:37 AM
Peter,

Thanks for your replay, but I must be missing something simple. What I currently have inside my module is this: int NewValue = EntriesController.MakeCollection(PortalId, 0, "MyTestTitle",UserInfo, false); When I debug the code I get to this module and receive the following stack trace:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="Bring2mind.DNN.Modules.DMX.Core"
StackTrace:
at Bring2mind.DNN.Modules.DMX.Business.EntriesController.MakeCollection(Int32 PortalId, Int32 CollectionId, String Title, UserInfo User, Boolean BypassSecurity)
at DesktopModules_DocumentTest_DocTest.Page_Load(Object sender, EventArgs e) in c:\Inetpub\DANetUpgrade\Website\DesktopModules\DocumentExchangeTest\DocTest.ascx.cs:line 20
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Both the PortalID and UserInfo object have data populated in them so I'm not sure what null value it would be looking for. Any assistance on this would be of great help. Thanks for all your help in advance.
-Arick
Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
03/20/2008 7:25 PM
Arick,

This is probably due to the fact that CollectionId 0 is somewhat special. Try a different one. The problem with Collection 0 is that it does not have any permissions for the new child to inherit. So the 'simple' method no longer applies.

If you absolutely have to add something to the root, then you'll need to make your own EntryInfo and add that with the EntriesController. Note in the EntryInfo you'll need to use the ML text objects and permission collection which means a lot more to manager. It'll be easier if you can add to an existing folder probably.

Peter
Arick
New Member
New Member
Posts:64


--
03/20/2008 8:45 PM
Peter,

Thanks for that bit of information. A couple of additional questions on this. I'm able to create a collection now however, in a quest to get to my ultimate goal, I am getting an error IsAllowedToEdit index out of range. My ultimate goal is to programatically create the following structure under a root folder I will then have:

Client X
Client Folder 1
Client Folder 2
Client Folder n

So I've setup the code to do the following:
EntriesController.MakeCollection(PortalId, 4, "Client X", UserInfo, false);
EntriesController.MakeCollection(PortalId, 5, "Client Folder 1", UserInfo, false);
EntriesController.MakeCollection(PortalId, 5, "Client Folder 2", UserInfo, false);
EntriesController.MakeCollection(PortalId, 5, "Client Folder n", UserInfo, false);

Using 4 and 5 becasue that is the only one my current system allows. Is there an easier way to find out the next available collection or the first collection under the root that can be used? If you have any documentation on this I'd be more then happy to look through that as well.

Thanks again,
Arick
Arick
New Member
New Member
Posts:64


--
03/20/2008 8:45 PM
Forgot to mention I'm getting the Error about IsAllowedToEdit on collection 5 after collection 4 is created.
Arick
New Member
New Member
Posts:64


--
03/21/2008 12:47 AM
Peter,

I have been palying with this functionality for some time now, and I think I have figured it out, what I need to do is create a new Folder(Collection) under my root collecting using the Entry ID of that collection. Once the root collection is created using the entryId returned from that collection I create any sub collections based off that entry ID, and I could continue down that path till all my folders are created. Am I on the correct path here? If so thank you for all your help!
Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
03/27/2008 1:38 PM
Yes, that should do it.
Peter
kreber
New Member
New Member
Posts:1


--
12/30/2008 9:40 PM
We desire to integrate your DMX with Catlook Stores... Does anyone have experience with this effort?

When an order is placed, we want to automatically create a set of folders for the newly placed order per the following:

new collection named "Order# [numeric value of Order ID number)" ..... set full permissions for client who ordered; and

with creation of separate sub-folder(s) inside the order folder for each line item product of the order named "Product# [numeric value of Product ID number of the order)]" .... set full permissions for client and the given vendor of the product.

I see above in the post how to use the EntriesController.MakeCollection command. However, how do we programatically set the permissions for the client and vendor?

Please advise.
Peter Donker
Veteran Member
Veteran Member
Posts:4536


--
01/06/2009 4:58 PM

Hi Joe,

If you're using MakeFolder the permissions are inherited by default. In the next version there'll also be a SPROC to create a folder including read/write role settings. Here it is:

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}{objectQualifier}DMX_Split') AND xtype IN (N'FN', N'IF', N'TF'))
DROP FUNCTION {databaseOwner}{objectQualifier}DMX_Split
GO

CREATE FUNCTION {databaseOwner}{objectQualifier}DMX_Split (@s varchar(512), @sep char(1))
RETURNS table
AS
RETURN (
    WITH Pieces(pn, start, stop) AS (
      SELECT 1, 1, CHARINDEX(@sep, @s)
      UNION ALL
      SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
      FROM Pieces
      WHERE stop > 0
    )
    SELECT pn,
      SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
    FROM Pieces
  )
GO

IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}DMX_AddFolder') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_AddFolder
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_AddFolder
 @PortalId INT,
 @CollectionId INT=0,
 @FolderName NVARCHAR(255)='New Folder',
 @ViewRoles VARCHAR(2000)='',
 @EditRoles VARCHAR(2000)='',
 @AddRoles VARCHAR(2000)='',
 @ApproveRoles VARCHAR(2000)=''
AS

BEGIN
 DECLARE @Owner INT
 SET @Owner = (SELECT AdministratorId FROM {databaseOwner}{objectQualifier}Portals WHERE PortalId=@PortalId)
 DECLARE @NewId INT
 INSERT INTO {databaseOwner}{objectQualifier}DMX_Entries
  (CollectionId, Created, Deleted, Entry, EntryType, IsApproved, Owner, PortalId, Version, PermissionsOnlyByAdmin)
  VALUES
  (@CollectionId, GETDATE(), 0, '', 'Collection', 1, @Owner, @PortalId, 1, 0);
 SET @NewId = SCOPE_IDENTITY()
 UPDATE {databaseOwner}{objectQualifier}DMX_Entries
  SET LastVersionId=EntryId
  WHERE EntryId=@NewId;
 INSERT INTO {databaseOwner}{objectQualifier}DMX_ShortTexts
  (Locale, ObjectId, SubTypeKey, [Text], TypeKey)
  VALUES ('', @NewId, 'TITLE', @FolderName, 'ENT');
 INSERT INTO {databaseOwner}{objectQualifier}DMX_Log
  ([Action],[Datime],[EntId],[UserId])
 VALUES ('Add', GETDATE(), @NewId, @Owner);
 DECLARE @AdminRoleId INT
 SET @AdminRoleId = (SELECT AdministratorRoleId FROM {databaseOwner}{objectQualifier}Portals WHERE PortalId=@PortalId)
 IF @ViewRoles='' AND @EditRoles='' AND @AddRoles='' AND @ApproveRoles=''
  BEGIN
   IF @CollectionId=0
    BEGIN
     -- set Admin roles for default folder under root
     INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
      ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
     SELECT 1, @NewId, PermissionId, @PortalId, @AdminRoleId, -10
      FROM {databaseOwner}{objectQualifier}DMX_Permissions
      WHERE PortalId=@PortalId AND (PermissionKey='VIEW' OR PermissionKey='EDIT' OR PermissionKey='ADD');
    END
   ELSE
    -- Inherit permissions from parent
    INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
     ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
    SELECT 1, @NewId, [PermissionId],[PortalId],[RoleId],[UserId]
     FROM {databaseOwner}{objectQualifier}DMX_EntryPermissions
     WHERE EntryId=@CollectionId;
  END
 ELSE
  BEGIN
   -- set View roles
   INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
    ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
   SELECT 1, @NewId, p1.PermissionId, @PortalId, r1.RoleId, -10
    FROM {databaseOwner}{objectQualifier}DMX_Split(@ViewRoles, ';') spl1
     INNER JOIN {databaseOwner}{objectQualifier}Roles r1 ON (CAST(r1.RoleId AS VARCHAR(10))=spl1.s OR r1.Rolename=spl1.s)
     INNER JOIN {databaseOwner}{objectQualifier}DMX_Permissions p1 ON (p1.PortalId=@PortalId AND p1.PermissionKey='VIEW')
    WHERE NOT @ViewRoles='';
   -- set Eit roles
   INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
    ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
   SELECT 1, @NewId, p1.PermissionId, @PortalId, r1.RoleId, -10
    FROM {databaseOwner}{objectQualifier}DMX_Split(@EditRoles, ';') spl1
     INNER JOIN {databaseOwner}{objectQualifier}Roles r1 ON (CAST(r1.RoleId AS VARCHAR(10))=spl1.s OR r1.Rolename=spl1.s)
     INNER JOIN {databaseOwner}{objectQualifier}DMX_Permissions p1 ON (p1.PortalId=@PortalId AND p1.PermissionKey='EDIT')
    WHERE NOT @EditRoles='';
   -- set Add roles
   INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
    ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
   SELECT 1, @NewId, p1.PermissionId, @PortalId, r1.RoleId, -10
    FROM {databaseOwner}{objectQualifier}DMX_Split(@AddRoles, ';') spl1
     INNER JOIN {databaseOwner}{objectQualifier}Roles r1 ON (CAST(r1.RoleId AS VARCHAR(10))=spl1.s OR r1.Rolename=spl1.s)
     INNER JOIN {databaseOwner}{objectQualifier}DMX_Permissions p1 ON (p1.PortalId=@PortalId AND p1.PermissionKey='ADD')
    WHERE NOT @AddRoles='';
   -- set Approve roles
   INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
    ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
   SELECT 1, @NewId, p1.PermissionId, @PortalId, r1.RoleId, -10
    FROM {databaseOwner}{objectQualifier}DMX_Split(@ApproveRoles, ';') spl1
     INNER JOIN {databaseOwner}{objectQualifier}Roles r1 ON (CAST(r1.RoleId AS VARCHAR(10))=spl1.s OR r1.Rolename=spl1.s)
     INNER JOIN {databaseOwner}{objectQualifier}DMX_Permissions p1 ON (p1.PortalId=@PortalId AND p1.PermissionKey='APPROVE')
    WHERE NOT @ApproveRoles='';
   -- make sure Admin is part of this
   INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
    ([AllowAccess],[EntryId],[PermissionId],[PortalId],[RoleId],[UserId])
   SELECT 1, @NewId, p.PermissionId, @PortalId, @AdminRoleId, -10
    FROM {databaseOwner}{objectQualifier}DMX_Permissions p
    WHERE p.PortalId=@PortalId AND (p.PermissionKey='VIEW' OR p.PermissionKey='EDIT' OR p.PermissionKey='ADD')
    AND NOT EXISTS(SELECT * FROM {databaseOwner}{objectQualifier}DMX_EntryPermissions ep 
        WHERE ep.PermissionId=p.PermissionId AND ep.EntryId=@NewId AND ep.RoleId=@AdminRoleId);
  END
END
GO

You can use this SPROC to add a folder (note it uses the split function above it). Use semi-colon separated list of role names or ids.

After you've created the folder any content underneath will inherit the roles. Note that folder to file inheritance moves ADD to EDIT roles.

Peter

You are not authorized to post a reply.