protected void CustomUniSelector_OnSelectionChanged(object sender, EventArgs e) { string SelectedItems = ValidationHelper.GetString(((UniSelector)sender).Value, ""); int RelationshipNameID = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName).RelationshipNameId; int[] NodeIDs = SelectedItems.Split(";|,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(x => ValidationHelper.GetInteger(x, -1)).ToArray(); if (MaxRelationships > -1 && GetRelationshipCount() + NodeIDs.Length > MaxRelationships) { AddMessage(CMS.Base.Web.UI.MessageTypeEnum.Error, "Too many relationships, max allowed is " + MaxRelationships); return; } foreach (int NodeID in NodeIDs) { if (NodeID > 0) { if (ddlCurrentNodeDirection.SelectedValue == "LeftNode") { RelationshipInfoProvider.AddRelationship(CurrentNodeID, NodeID, RelationshipNameID); } else { RelationshipInfoProvider.AddRelationship(NodeID, CurrentNodeID, RelationshipNameID); } } } // Save direction SessionHelper.SetValue("RelatedPageTreeDirection_" + CurrentNodeID + "_" + UIContext.ElementGuid, ddlCurrentNodeDirection.SelectedValue); URLHelper.RefreshCurrentPage(); }
/// <summary> /// Saves relationship. /// </summary> public void SaveRelationship() { if (TreeNode == null) { return; } // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { return; } bool currentNodeIsOnLeftSide = !DefaultSide; // Selected node Id int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0); var relationshipName = UseAdHocRelationshipName ? RelationshipNameInfoProvider.GetAdHocRelationshipNameCodeName(TreeNode.ClassName, FieldInfo) : RelationshipName; var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName); int relationshipNameId; if (relationshipNameInfo != null) { relationshipNameId = relationshipNameInfo.RelationshipNameId; } else { throw new NullReferenceException("[RelatedDocuments.SaveRelationship]: Missing relationship name to use for relation."); } if ((selectedNodeId <= 0) || (relationshipNameId <= 0)) { return; } try { // Left side if (currentNodeIsOnLeftSide) { RelationshipInfoProvider.AddRelationship(TreeNode.NodeID, selectedNodeId, relationshipNameId); } // Right side else { RelationshipInfoProvider.AddRelationship(selectedNodeId, TreeNode.NodeID, relationshipNameId); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider); ShowConfirmation(GetString("relationship.wasadded")); } catch (Exception ex) { ShowError(ex.Message); } }
protected void AddPagesToRelationship(int[] SelectedNodeIDs) { int RelationshipNameID = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName).RelationshipNameId; if (MaxRelationships > -1 && GetRelationshipCount() + SelectedNodeIDs.Length > MaxRelationships) { AddMessage(CMS.Base.Web.UI.MessageTypeEnum.Error, "Too many relationships, max allowed is " + MaxRelationships); return; } foreach (int NodeID in SelectedNodeIDs) { if (NodeID > 0) { if (ddlCurrentNodeDirection.SelectedValue == "LeftNode") { RelationshipInfoProvider.AddRelationship(CurrentNodeID, NodeID, RelationshipNameID); } else { RelationshipInfoProvider.AddRelationship(NodeID, CurrentNodeID, RelationshipNameID); } } } // Save direction SessionHelper.SetValue("RelatedPageTreeDirection_" + CurrentNodeID + "_" + UIContext.ElementGuid, ddlCurrentNodeDirection.SelectedValue); URLHelper.RefreshCurrentPage(); }
/// <summary> /// Fires on the grid action. /// </summary> /// <param name="actionName">Action name</param> /// <param name="actionArgument">Action argument</param> private void UniGridRelationship_OnAction(string actionName, object actionArgument) { // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { return; } if (actionName == "delete") { string[] parameters = ((string)actionArgument).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (parameters.Length == 3) { // Parse parameters int leftNodeId = ValidationHelper.GetInteger(parameters[0], 0); int rightNodeId = ValidationHelper.GetInteger(parameters[1], 0); int relationshipNameId = ValidationHelper.GetInteger(parameters[2], 0); // If parameters are valid if ((leftNodeId > 0) && (rightNodeId > 0) && (relationshipNameId > 0)) { // Remove relationship RelationshipInfoProvider.RemoveRelationship(leftNodeId, rightNodeId, relationshipNameId); // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider); ShowConfirmation(GetString("relationship.wasdeleted")); } } } }
/// <summary> /// Fires on the grid action. /// </summary> /// <param name="actionName">Action name</param> /// <param name="actionArgument">Action argument</param> private void UniGridRelationship_OnAction(string actionName, object actionArgument) { // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { return; } switch (actionName.ToLowerInvariant()) { case "delete": var relationshipId = actionArgument.ToInteger(0); // If parameters are valid if (relationshipId > 0) { // Remove relationship RelationshipInfoProvider.RemoveRelationship(relationshipId); if (RelHelper.IsStagingEnabled()) { // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider); } ShowConfirmation(GetString("relationship.wasdeleted")); URLHelper.RefreshCurrentPage(); } break; } }
/// <summary> /// Saves relationship. /// </summary> public void SaveRelationship() { if (TreeNode == null) { return; } // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { return; } bool currentNodeIsOnLeftSide = !DefaultSide; // Selected node Id int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0); // Get relationshipNameId var relationshipNameId = GetRelationshipNameId(); if ((selectedNodeId <= 0) || (relationshipNameId <= 0)) { return; } try { // Left side if (currentNodeIsOnLeftSide) { RelationshipInfoProvider.AddRelationship(TreeNode.NodeID, selectedNodeId, relationshipNameId); } // Right side else { RelationshipInfoProvider.AddRelationship(selectedNodeId, TreeNode.NodeID, relationshipNameId); } if (RelHelper.IsStagingEnabled()) { // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider); } ShowConfirmation(GetString("relationship.wasadded")); } catch (Exception ex) { ShowError(ex.Message); } }
protected void ProcessCategory(int productNodeId, string categoryPath) { if (!string.IsNullOrEmpty(categoryPath)) { var categoryItem = FindProductCategory(categoryPath); if (categoryItem != null) { RelationshipInfoProvider.AddRelationship(productNodeId, categoryItem.NodeID, productCategoryProductRelationshipID); } // if product detail or product category are null log error and add to error tracker (add error tracking custom table)fields, product detail name, product category name and explanation of what's wrong else { // Prepares the code name (class name) of the custom table to which the data record will be added string customTableClassName = "PbcLinear.ProcessCategoryErrors"; // Gets the custom table DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName); if (customTable != null) { // Creates a new custom table item CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName); // Sets the values for the fields of the custom table (ItemText in this case) newCustomTableItem.SetValue("ProductNodeId", productNodeId); newCustomTableItem.SetValue("CategoryPath", categoryPath); newCustomTableItem.SetValue("Error", "categoryItem is null "); if (productNodeId == 0) { var newError = newCustomTableItem.GetValue("Error") + " productNodeId is empty"; newCustomTableItem.SetValue("Error", newError); } if (!string.IsNullOrEmpty(categoryPath)) { var newError = newCustomTableItem.GetValue("Error") + " categoryPath is empty"; newCustomTableItem.SetValue("Error", newError); } // Save the new custom table record into the database newCustomTableItem.Insert(); } } } }
private int GetRelationshipCount() { int RelationshipNameID = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName).RelationshipNameId; if (AllowSwitchSides) { return(RelationshipInfoProvider.GetRelationships() .WhereEquals("RelationshipNameID", RelationshipNameID) .Where(string.Format("(LeftNodeID = {0} or RightNodeID = {0})", CurrentNodeID)) .Count); } else { return(RelationshipInfoProvider.GetRelationships() .WhereEquals("RelationshipNameID", RelationshipNameID) .WhereEquals(DirectionMode == "LeftNode" ? "LeftNodeID" : "RightNodeID", CurrentNodeID) .Count); } }
private List <object> GetRelationshipElements(TreeNode node) { var query = new DataQuery(); var nodeRelationshipsQuery = RelationshipInfoProvider.GetRelationships() .WhereEquals("LeftNodeID", node.NodeID); // Get all the relationships for the document and also empty records for every existing relationships that the document is not using to send a complete set of relationship elements var allRelationshipsQuery = query .From( @" (" + query.IncludeDataParameters(nodeRelationshipsQuery.Parameters, nodeRelationshipsQuery.QueryText) + @") R FULL OUTER JOIN CMS_RelationshipNameSite RNS ON R.RelationshipNameID = RNS.RelationshipNameID LEFT JOIN CMS_RelationshipName RN ON RNS.RelationshipNameID = RN.RelationshipNameID LEFT JOIN CMS_Tree T ON R.RightNodeID = T.NodeID " ) .Columns("NodeGUID", "RelationshipGUID") .WhereEqualsOrNull("RelationshipNameIsAdHoc", false) .WhereEquals("RNS.SiteID", node.NodeSiteID) .OrderBy("RelationshipOrder"); var relationshipElements = allRelationshipsQuery .Result .Tables[0] .AsEnumerable() .GroupBy(row => (Guid)row["RelationshipGUID"]) .Select(group => new { element = new { external_id = ContentTypeSync.GetFieldExternalId(ContentTypeSync.RELATED_PAGES_GUID, group.Key) }, value = (object)group .Where(row => row["NodeGUID"] != DBNull.Value) .Select(row => new { external_id = GetPageExternalId((Guid)row["NodeGUID"]) }) .ToList() }) .Cast <object>() .ToList(); return(relationshipElements); }
/// <summary> /// Deletes relationship between documents. Called when the "Delete relationship" button is pressed. /// Expects the CreateRelationshipName and the CreateRelationship methods to be run first. /// </summary> private bool DeleteRelationship() { // Get the relationship name RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName"); if (relationshipName != null) { // Get the tree structure TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); // Get documents which are in relationship (the Root document is used for both in this example) TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true); // Delete the relationship between documents RelationshipInfoProvider.RemoveRelationship(root.NodeID, root.NodeID, relationshipName.RelationshipNameId); return(true); } return(false); }
/// <summary> /// Get related pages for a Pages field specified on a component. /// </summary> /// <param name="component">The component that has the Pages field.</param> /// <param name="fieldName">The code name of the Pages field on the component.</param> /// <returns>The related pages for the specified component field.</returns> public static IEnumerable <TreeNode> GetRelatedDocumentsForComponent(this IContentComponent component, string fieldName) { TreeNode parent = component.Parent; if (parent == null) { return(Enumerable.Empty <TreeNode>()); } FormInfo form = FormHelper.GetFormInfo(component.NodeClassName, false); FormFieldInfo formField = form.GetFormField(fieldName); if (formField == null) { return(Enumerable.Empty <TreeNode>()); } string relationshipNameCodeName = RelationshipNameInfoProvider.GetAdHocRelationshipNameCodeName(parent.NodeClassName, formField); RelationshipNameInfo relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipNameCodeName); var relationshipQuery = DocumentHelper.GetDocuments() .Culture(parent.DocumentCulture) .CombineWithDefaultCulture(parent.TreeProvider.GetCombineWithDefaultCulture(parent.Site.SiteName)) .Published(!parent.IsLastVersion) .PublishedVersion(!parent.IsLastVersion) .WithCoupledColumns() .InRelationWith( parent.NodeGUID, relationshipNameCodeName, RelationshipSideEnum.Left ); return(RelationshipInfoProvider.ApplyRelationshipOrderData( relationshipQuery, parent.NodeID, relationshipNameInfo.RelationshipNameId )); }
private IList <Guid> GetRelatedNodeGuids(TreeNode node, FormFieldInfo relationshipsField) { var relationshipName = RelationshipNameInfoProvider.GetAdHocRelationshipNameCodeName(node.ClassName, relationshipsField); var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName); if (relationshipNameInfo == null) { return(new List <Guid>()); } var guids = RelationshipInfoProvider.GetRelationships() .Columns("NodeGUID") .Source( s => s.LeftJoin(new QuerySourceTable("CMS_Tree"), "RightNodeID", "NodeID") ) .WhereEquals("LeftNodeID", node.NodeID) .WhereEquals("RelationshipID", relationshipNameInfo.RelationshipNameId) .OrderBy("RelationshipOrder") .GetListResult <Guid>(); return(guids); }
/// <summary> /// Saves relationship. /// </summary> public void SaveRelationship() { if (TreeNode == null) { return; } // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { return; } bool currentNodeIsOnLeftSide = !DefaultSide; // Selected node Id int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0); if (BindOnPrimaryNodeOnly) { selectedNodeId = RelHelper.GetPrimaryNodeID(selectedNodeId); } var relationshipName = RelationshipName; var relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipName); int relationshipNameId; if (relationshipNameInfo != null) { relationshipNameId = relationshipNameInfo.RelationshipNameId; } else { throw new NullReferenceException("[RelatedDocuments.SaveRelationship]: Missing relationship name to use for relation."); } if ((selectedNodeId <= 0) || (relationshipNameId <= 0)) { return; } try { // Test to make sure the selected page is a Right Side macro-allowed page or left side, and also matches the Page type limiter var SelectedTreeNode = (AllowAllTypes ? new DocumentQuery() : new DocumentQuery(AllowedPageTypes)).WhereEquals("NodeID", selectedNodeId).FirstOrDefault(); // If null probably not an allowed page type, but we will need it to validate below if (SelectedTreeNode == null) { SelectedTreeNode = new DocumentQuery().WhereEquals("NodeID", selectedNodeId).FirstOrDefault(); } var CurrentPageMacroResolver = MacroResolver.GetInstance(); CurrentPageMacroResolver.SetNamedSourceData("CurrentDocument", TreeNode); var PageMacroResolver = MacroResolver.GetInstance(); PageMacroResolver.SetNamedSourceData("CurrentDocument", SelectedTreeNode); // Left side if (currentNodeIsOnLeftSide) { if (!AllowAllTypes && !ClassNames.Contains(SelectedTreeNode.ClassName.ToLower())) { AddError(ResHelper.LocalizeExpression("RelatedPages.BadPageType")); } else if (!ValidationHelper.GetBoolean(CurrentPageMacroResolver.ResolveMacros(IsLeftSideMacro), false) || !ValidationHelper.GetBoolean(PageMacroResolver.ResolveMacros(IsRightSideMacro), false)) { AddError(ResHelper.LocalizeExpression("RelatedPages.LeftSideRightSideInvalid")); } else if (TreeNode.NodeID == SelectedTreeNode.NodeID) { AddError(ResHelper.LocalizeExpression("RelatedPages.CannotSelectSelf")); } else { RelationshipInfoProvider.AddRelationship(TreeNode.NodeID, selectedNodeId, relationshipNameId); if (RelHelper.IsStagingEnabled()) { // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, TreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider); } ShowConfirmation(GetString("relationship.wasadded")); } } // Right side else { if (!AllowAllTypes && !ClassNames.Contains(SelectedTreeNode.ClassName.ToLower())) { AddError(ResHelper.LocalizeExpression("RelatedPages.BadPageType")); } else if (!ValidationHelper.GetBoolean(CurrentPageMacroResolver.ResolveMacros(IsLeftSideMacro), false) || !ValidationHelper.GetBoolean(PageMacroResolver.ResolveMacros(IsRightSideMacro), false)) { AddError(ResHelper.LocalizeExpression("RelatedPages.LeftSideRightSideInvalid")); } else if (TreeNode.NodeID == SelectedTreeNode.NodeID) { AddError(ResHelper.LocalizeExpression("RelatedPages.CannotSelectSelf")); } else { RelationshipInfoProvider.AddRelationship(selectedNodeId, TreeNode.NodeID, relationshipNameId); if (RelHelper.IsStagingEnabled()) { // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(TreeNode.NodeSiteName, SelectedTreeNode.NodeAliasPath, TaskTypeEnum.UpdateDocument, TreeProvider); } ShowConfirmation(GetString("relationship.wasadded")); } } } catch (Exception ex) { ShowError(ex.Message); } }
private int GetRelationshipCount() { return(RelationshipInfoProvider.GetRelationships() .WhereEquals("RelationshipNameID", GetRelationshipNameId()) .WhereEquals("LeftNodeID", TreeNode.NodeID).Count); }
/// <summary> /// Saves relationship. /// </summary> /// <returns>True, if relatioship was successfully saved.</returns> public bool SaveRelationship() { bool saved = false; // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { return(saved); } bool currentNodeIsOnLeftSide = ValidationHelper.GetBoolean(Request.Params[hdnCurrentOnLeft.UniqueID], false); int selectedNodeId = ValidationHelper.GetInteger(hdnSelectedNodeId.Value, 0); TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); // Try to get by path if not selected if (selectedNodeId <= 0) { string aliaspath = currentNodeIsOnLeftSide ? txtRightNode.Text.Trim() : txtLeftNode.Text.Trim(); if (aliaspath != string.Empty) { node = tree.SelectSingleNode(SiteContext.CurrentSiteName, aliaspath, TreeProvider.ALL_CULTURES); if (node != null) { selectedNodeId = node.NodeID; } else { ShowError(GetString("relationship.selectcorrectrelateddoc")); } } else { ShowError(GetString("relationship.selectrelateddoc")); } } int selectedValue = 0; // Only one relationship name in textbox if ((relationshipNameInfo != null) && (lblRelName.Visible)) { selectedValue = relationshipNameInfo.RelationshipNameId; } // Value from relationship name selector else if (relNameSelector.Visible) { selectedValue = ValidationHelper.GetInteger(relNameSelector.Value, 0); } if ((currentNodeId > 0) && (selectedNodeId > 0) && (selectedValue > 0)) { int relationshipNameId = selectedValue; try { // Left side if (currentNodeIsOnLeftSide) { RelationshipInfoProvider.AddRelationship(currentNodeId, selectedNodeId, relationshipNameId); } // Right side else { RelationshipInfoProvider.AddRelationship(selectedNodeId, currentNodeId, relationshipNameId); } // Log synchronization for single document TreeNode currentNode = node ?? tree.SelectSingleNode(currentNodeId); DocumentSynchronizationHelper.LogDocumentChange(currentNode, TaskTypeEnum.UpdateDocument, tree); saved = true; ShowChangesSaved(); } catch (Exception ex) { ShowError(ex.Message); } } return(saved); }
private int GetRelationshipCount() { return(RelationshipInfoProvider.GetCount(query => query.WhereEquals("RelationshipNameID", GetRelationshipNameId()))); }
private int GetRelationshipCount() { return RelationshipInfoProvider.GetRelationships().WhereEquals("RelationshipNameID", GetRelationshipNameId()).Count(); }