/// <summary> /// Creates relationship between documents. Called when the "Create relationship" button is pressed. /// Expects the CreateRelationshipName method to be run first. /// </summary> private bool CreateRelationship() { // Get the relationship name RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName"); if (relationshipName != null) { // Get the tree structure TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Get documents for relationship (the Root document is used for both in this example) TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true); // Create the relationship between documents RelationshipProvider.AddRelationship(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 )); }
/// <summary> /// Returns true if document is in specified relationship with with selected document. /// </summary> /// <param name="document">Document to be checked</param> /// <param name="side">Relationship side</param> /// <param name="relationship">Relationship name</param> /// <param name="relatedDocumentPath">Alias path to selected document</param> /// <param name="relatedDocumentSite">Selected document site name</param> public static bool IsInRelationship(object document, string side, string relationship, string relatedDocumentPath, string relatedDocumentSite) { TreeNode doc = document as TreeNode; if (doc != null) { int leftNodeID = 0; int rightNodeID = 0; // Use site of the checked document when no other is specified if (String.IsNullOrEmpty(relatedDocumentSite)) { relatedDocumentSite = doc.NodeSiteName; } // Prepare left and right document for relationship side = side.ToLowerCSafe(); if (side == "left") { leftNodeID = doc.NodeID; rightNodeID = TreePathUtils.GetNodeIdByAliasPath(relatedDocumentSite, relatedDocumentPath); } else if (side == "right") { leftNodeID = TreePathUtils.GetNodeIdByAliasPath(relatedDocumentSite, relatedDocumentPath); rightNodeID = doc.NodeID; } // Get relationship ID from relationship name RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationship); if (relationshipName != null) { // Check whether relationship between the two documents exists return(RelationshipProvider.GetRelationshipInfo(leftNodeID, rightNodeID, relationshipName.RelationshipNameId) != null); } } return(false); }
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> /// Loads data of edited relationship name from DB into TextBoxes. /// </summary> protected void LoadData() { RelationshipNameInfo rni = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipNameId); if (rni != null) { txtRelationshipNameCodeName.Text = rni.RelationshipName; txtRelationshipNameDisplayName.Text = rni.RelationshipDisplayName; // Initialize drop down list with relationship type drpRelType.Items.Clear(); drpRelType.Items.Add(new ListItem(GetString("RelationshipNames.Documents"), ";" + CMSObjectHelper.GROUP_DOCUMENTS + ";")); drpRelType.Items.Add(new ListItem(GetString("RelationshipNames.Objects"), ";" + CMSObjectHelper.GROUP_OBJECTS + ";")); if (DataHelper.IsEmpty(rni.RelationshipAllowedObjects)) { drpRelType.SelectedIndex = 0; } else { drpRelType.SelectedValue = rni.RelationshipAllowedObjects; } } }
protected object gridItems_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView dr = null; switch (sourceName.ToLower()) { case "leftobject": { dr = (DataRowView)parameter; string objectType = ValidationHelper.GetString(dr["RelationshipLeftObjectType"], ""); int objectId = ValidationHelper.GetInteger(dr["RelationshipLeftObjectID"], 0); return(GetObjectString(objectId, objectType)); } case "rightobject": { dr = (DataRowView)parameter; string objectType = ValidationHelper.GetString(dr["RelationshipRightObjectType"], ""); int objectId = ValidationHelper.GetInteger(dr["RelationshipRightObjectID"], 0); return(GetObjectString(objectId, objectType)); } case "relationshipname": // Relationship name int relationshipId = ValidationHelper.GetInteger(parameter, 0); RelationshipNameInfo ri = RelationshipNameInfoProvider.GetRelationshipNameInfo(relationshipId); if (ri != null) { return(ri.RelationshipDisplayName); } break; } return(parameter); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); EditedDocument = Node; // Get default relationship name from settings string defaultRelName = ECommerceSettings.RelatedProductsRelationshipName(SiteContext.CurrentSiteName); // Check if relationship exists bool anyRelationshipsFound = true; RelationshipNameInfo defaultRelNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(defaultRelName); if (defaultRelNameInfo != null) { relatedDocuments.RelationshipName = defaultRelName; } else { // Check if any relationship exists DataSet dsRel = RelationshipNameInfoProvider.GetRelationshipNames("RelationshipAllowedObjects LIKE '%" + ObjectHelper.GROUP_DOCUMENTS + "%' AND RelationshipNameID IN (SELECT RelationshipNameID FROM CMS_RelationshipNameSite WHERE SiteID = " + SiteContext.CurrentSiteID + ")", null, 1, "RelationshipNameID"); if (DataHelper.DataSourceIsEmpty(dsRel)) { relatedDocuments.Visible = false; ShowInformation(GetString("relationship.norelationship")); anyRelationshipsFound = false; } } if (anyRelationshipsFound && (Node != null)) { // Check read permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Denied) { RedirectToAccessDenied(string.Format(GetString("cmsdesk.notauthorizedtoreaddocument"), Node.NodeAliasPath)); } // Check modify permissions else if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { pnlDocInfo.Label.Text = string.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), Node.DocumentName); relatedDocuments.Enabled = false; CurrentMaster.HeaderActions.Enabled = false; } } // Set tree node relatedDocuments.TreeNode = Node; // Set starting path if (!string.IsNullOrEmpty(ProductsStartingPath)) { relatedDocuments.StartingPath = ProductsStartingPath; } CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction { Text = GetString("relationship.addrelateddocs"), OnClientClick = relatedDocuments.GetAddRelatedDocumentScript() }); }
/// <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); } }
protected void Page_Load(object sender, EventArgs e) { // Register the dialog script ScriptHelper.RegisterDialogScript(Page); DefaultSide = QueryHelper.GetBoolean("defaultside", DefaultSide); AllowSwitchSides = QueryHelper.GetBoolean("allowswitchsides", AllowSwitchSides); RelationshipName = QueryHelper.GetString("relationshipname", RelationshipName); Config.ContentStartingPath = QueryHelper.GetString("startingpath", Config.ContentStartingPath); relNameSelector.IsLiveSite = false; btnSwitchSides.Visible = AllowSwitchSides; btnOk.Visible = ShowButtons; // Initialize dialog scripts Config.EditorClientID = txtLeftNode.ClientID + ";" + hdnSelectedNodeId.ClientID; string url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false); btnLeftNode.OnClientClick = "modalDialog('" + url + "', 'contentselectnode', '90%', '85%'); return false;"; Config.EditorClientID = txtRightNode.ClientID + ";" + hdnSelectedNodeId.ClientID; url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false); btnRightNode.OnClientClick = "modalDialog('" + url + "', 'contentselectnode', '90%', '85%'); return false;"; if (TreeNode != null) { currentNodeId = TreeNode.NodeID; // Check modify permissions if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { Enabled = false; ShowInformation(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), TreeNode.NodeAliasPath)); } string nodeDocumentName = TreeNode.GetDocumentName(); lblRightNode.Text = lblLeftNode.Text = HTMLHelper.HTMLEncode(nodeDocumentName); } else { Enabled = false; } // All relationship names for current site if (string.IsNullOrEmpty(RelationshipName)) { relNameSelector.Visible = true; lblRelName.Visible = false; } else { relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName); if (relationshipNameInfo != null) { lblRelName.Text = relationshipNameInfo.RelationshipDisplayName; } relNameSelector.Visible = false; lblRelName.Visible = true; } // Register switching js if (btnSwitchSides.Enabled && btnSwitchSides.Visible) { RegisterScript(); } if (!RequestHelper.IsPostBack()) { hdnCurrentOnLeft.Value = !DefaultSide ? "true" : "false"; } bool isLeftSide = ValidationHelper.GetBoolean(hdnCurrentOnLeft.Value, false); // Left side if (isLeftSide) { pnlLeftSelectedNode.AddCssClass("hidden"); lblRightNode.AddCssClass("hidden"); pnlRightSelectedNode.RemoveCssClass("hidden"); lblLeftNode.RemoveCssClass("hidden"); } // Right side else { lblLeftNode.AddCssClass("hidden"); pnlRightSelectedNode.AddCssClass("hidden"); pnlLeftSelectedNode.RemoveCssClass("hidden"); lblRightNode.RemoveCssClass("hidden"); } // Clear breadcrumbs suffix (we don't want it when creating new object) UIHelper.SetBreadcrumbsSuffix(""); }
protected void Page_Load(object sender, EventArgs e) { // Register the dialog script ScriptHelper.RegisterDialogScript(Page); DefaultSide = QueryHelper.GetBoolean("defaultside", DefaultSide); AllowSwitchSides = QueryHelper.GetBoolean("allowswitchsides", AllowSwitchSides); RelationshipName = QueryHelper.GetString("relationshipname", RelationshipName); relNameSelector.IsLiveSite = false; btnSwitchSides.Visible = AllowSwitchSides; btnOk.Visible = ShowButtons; // Initialize dialog scripts Config.EditorClientID = txtLeftNode.ClientID + ";" + hdnSelectedNodeId.ClientID; string url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false); btnLeftNode.OnClientClick = "modalDialog('" + url + "', 'contentselectnode', '90%', '85%'); return false;"; Config.EditorClientID = txtRightNode.ClientID + ";" + hdnSelectedNodeId.ClientID; url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false); btnRightNode.OnClientClick = "modalDialog('" + url + "', 'contentselectnode', '90%', '85%'); return false;"; leftCell.Text = GetString("Relationship.leftSideDoc"); middleCell.Text = GetString("Relationship.RelationshipName"); rightCell.Text = GetString("Relationship.rightSideDoc"); if (TreeNode != null) { currentNodeId = TreeNode.NodeID; // Check modify permissions if (CMSContext.CurrentUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { Enabled = false; lblInfo.Visible = true; lblInfo.Text = String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), TreeNode.NodeAliasPath); } string nodeDocumentName = TreeNode.DocumentName; lblRightNode.Text = lblLeftNode.Text = (string.IsNullOrEmpty(nodeDocumentName)) ? "/" : HTMLHelper.HTMLEncode(nodeDocumentName); } else { Enabled = false; } // All relationship names for current site if (string.IsNullOrEmpty(RelationshipName)) { relNameSelector.Visible = true; lblRelName.Visible = false; } else { relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName); if (relationshipNameInfo != null) { lblRelName.Text = relationshipNameInfo.RelationshipDisplayName; } relNameSelector.Visible = false; lblRelName.Visible = true; } // Register switching js if (btnSwitchSides.Enabled) { RegisterScript(); } if (!RequestHelper.IsPostBack()) { hdnCurrentOnLeft.Value = !DefaultSide ? "true" : "false"; } bool isLeftSide = ValidationHelper.GetBoolean(hdnCurrentOnLeft.Value, false); // Left side if (isLeftSide) { pnlLeftCurrentNode.Style.Add("display", "block"); pnlLeftSelectedNode.Style.Add("display", "none"); pnlLeftSelectButton.Style.Add("display", "none"); pnlRightCurrentNode.Style.Add("display", "none"); pnlRightSelectedNode.Style.Add("display", "block"); pnlRightSelectButton.Style.Add("display", "block"); } // Right side else { pnlLeftCurrentNode.Style.Add("display", "none"); pnlLeftSelectedNode.Style.Add("display", "block"); pnlLeftSelectButton.Style.Add("display", "block"); pnlRightCurrentNode.Style.Add("display", "block"); pnlRightSelectedNode.Style.Add("display", "none"); pnlRightSelectButton.Style.Add("display", "none"); } }