/// <summary> /// Given the protected modifier the CMSNode.MakeNew method can only be accessed by // derrived classes > who by definition knows of its own objectType. /// </summary> /// <param Name="parentId">The parent CMSNode id</param> /// <param Name="objectType">The objecttype identifier</param> /// <param Name="userId">Creator</param> /// <param Name="level">The level in the tree hieararchy</param> /// <param Name="text">The Name of the CMSNode</param> /// <param Name="uniqueId">The unique identifier</param> /// <returns></returns> protected static CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueId) { CMSNode parent; string path = ""; int sortOrder = 0; if (level > 0) { parent = new CMSNode(parentId); sortOrder = parent.Children.Length + 1; path = parent.Path; } else { path = "-1"; } Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery( _ConnString, CommandType.Text, "Insert into UmbracoNode " + "(trashed, parentID, nodeObjectType, nodeUser, level, path, sortOrder, uniqueId, text) values" + "(0, " + parentId + ", '" + objectType + "', " + userId + "," + (level++).ToString() + ", '" + path + "'," + sortOrder + ",'" + uniqueId.ToString() + "', N'" + SqlHelper.SafeString(text) + "')" ); CMSNode retVal = new CMSNode(uniqueId); retVal.Path = path + "," + retVal.Id.ToString(); return(retVal); }
/// <summary> /// Moves the CMSNode from the current position in the hierarchicy to the target /// </summary> /// <param Name="NewParentId">Target CMSNode id</param> public void Move(int NewParentId) { int maxSortOrder = int.Parse(Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteScalar( GlobalSettings.DbDSN, CommandType.Text, "select isnull(max(sortOrder),0) from umbracoNode where parentid = @parentId", new SqlParameter("@parentId", NewParentId)).ToString()); CMSNode n = new CMSNode(NewParentId); this.Parent = n; this.Level = n.Level + 1; this.Path = n.Path + "," + this.Id.ToString(); this.sortOrder = maxSortOrder + 1; // Nasty hack - this will be fixed when the // application server part is done in the Umbraco.Umbraco.Cms.BusinessLogic // project. if (n.nodeObjectType == web.Document._objectType) { new Umbraco.Cms.BusinessLogic.web.Document(n.Id).XmlGenerate(new XmlDocument()); } else if (n.nodeObjectType == media.Media._objectType) { new Umbraco.Cms.BusinessLogic.media.Media(n.Id).XmlGenerate(new XmlDocument()); } foreach (CMSNode c in this.Children) { c.Move(this.Id); } }
/// <summary> /// Given the protected modifier the CMSNode.MakeNew method can only be accessed by // derrived classes > who by definition knows of its own objectType. /// </summary> /// <param Name="parentId">The parent CMSNode id</param> /// <param Name="objectType">The objecttype identifier</param> /// <param Name="userId">Creator</param> /// <param Name="level">The level in the tree hieararchy</param> /// <param Name="text">The Name of the CMSNode</param> /// <param Name="uniqueId">The unique identifier</param> /// <returns></returns> protected static CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueId) { CMSNode parent; string path = ""; int sortOrder = 0; if (level > 0) { parent = new CMSNode(parentId); sortOrder = parent.Children.Length+1; path = parent.Path; } else path = "-1"; Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery( _ConnString, CommandType.Text , "Insert into UmbracoNode " + "(trashed, parentID, nodeObjectType, nodeUser, level, path, sortOrder, uniqueId, text) values" + "(0, " + parentId + ", '"+ objectType +"', " + userId + "," + (level++).ToString() + ", '" + path + "'," + sortOrder + ",'" + uniqueId.ToString() + "', N'" + SqlHelper.SafeString(text) + "')" ); CMSNode retVal = new CMSNode(uniqueId); retVal.Path = path + "," + retVal.Id.ToString(); return retVal; }
/// <summary> /// Moves the CMSNode from the current position in the hierarchicy to the target /// </summary> /// <param Name="NewParentId">Target CMSNode id</param> public void Move(int NewParentId) { int maxSortOrder = int.Parse(Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteScalar( GlobalSettings.DbDSN, CommandType.Text, "select isnull(max(sortOrder),0) from umbracoNode where parentid = @parentId", new SqlParameter("@parentId", NewParentId)).ToString()); CMSNode n = new CMSNode(NewParentId); this.Parent = n; this.Level = n.Level+1; this.Path = n.Path + "," + this.Id.ToString(); this.sortOrder = maxSortOrder+1; // Nasty hack - this will be fixed when the // application server part is done in the Umbraco.Umbraco.Cms.BusinessLogic // project. if (n.nodeObjectType == web.Document._objectType) new Umbraco.Cms.BusinessLogic.web.Document(n.Id).XmlGenerate(new XmlDocument()); else if (n.nodeObjectType == media.Media._objectType) new Umbraco.Cms.BusinessLogic.media.Media(n.Id).XmlGenerate(new XmlDocument()); foreach (CMSNode c in this.Children) c.Move(this.Id); }