コード例 #1
0
ファイル: Edit.ascx.cs プロジェクト: tvelzy/RadstackMedia
    /// <summary>
    // Processes the form - saves the data.
    /// </summary>
    private void Process()
    {
        // Check manage permissions
        if (!CheckPermissions("CMS.ABTest", PERMISSION_MANAGE))
        {
            return;
        }

        // Validate the form
        if (Validate())
        {
            // Ensure the info object
            if (VariantObj == null)
            {
                VariantObj = new ABVariantInfo();
                VariantObj.ABVariantTestID = TestID;
                VariantObj.ABVariantSiteID = CMSContext.CurrentSiteID;
            }

            // Initialize object
            VariantObj.ABVariantDisplayName = txtABVariantDisplayName.Text.Trim();
            VariantObj.ABVariantName        = txtABVariantName.Text.Trim();
            VariantObj.ABVariantPath        = ucPath.Value.ToString().Trim();

            // Save object data to database
            ABVariantInfoProvider.SetABVariantInfo(VariantObj);

            ItemID = VariantObj.ABVariantID;
            RaiseOnSaved();

            // Set the info message
            ShowChangesSaved();
        }
    }
コード例 #2
0
ファイル: Edit.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    // Processes the form - saves the data.
    /// </summary>
    private void Process()
    {
        // Check manage permissions
        if (!CheckPermissions("CMS.ABTest", CMSAdminControl.PERMISSION_MANAGE))
        {
            return;
        }

        // Validate the form
        if (Validate())
        {
            // Ensure the info object
            if (this.VariantObj == null)
            {
                this.VariantObj = new ABVariantInfo();
                this.VariantObj.ABVariantTestID = TestID;
                this.VariantObj.ABVariantSiteID = CMSContext.CurrentSiteID;
            }

            // Initialize object
            this.VariantObj.ABVariantDisplayName = this.txtABVariantDisplayName.Text.Trim();
            this.VariantObj.ABVariantName        = this.txtABVariantName.Text.Trim();
            this.VariantObj.ABVariantPath        = this.ucPath.Value.ToString().Trim();

            // Save object data to database
            ABVariantInfoProvider.SetABVariantInfo(this.VariantObj);

            this.ItemID = this.VariantObj.ABVariantID;
            this.RaiseOnSaved();

            // Set the info message
            this.lblInfo.Text = GetString("general.changessaved");
        }
    }
コード例 #3
0
    /// <summary>
    /// Creates new AB variant if AB test filled in.
    /// </summary>
    /// <param name="newDocument">Newly created document</param>
    /// <returns>True if new variant is successfully created or if AB test is not defined.</returns>
    private bool CreateABVariant(TreeNode newDocument)
    {
        // If ABTest selected - create new variant
        int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0);

        if (abTestID <= 0)
        {
            return(true);
        }

        // If no test found, handle it as no test was specified
        ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID);

        if (abTest == null)
        {
            return(true);
        }

        string        defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newDocument.NodeAlias), 45, String.Empty);
        string        codeName        = defaultCodeName;
        ABVariantInfo info            = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName);

        // Find non existing variant code name
        int index = 0;

        while (info != null)
        {
            index++;
            codeName = defaultCodeName + "-" + index;
            info     = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName);
        }

        // Save AB Variant
        ABVariantInfo variantInfo = new ABVariantInfo();

        variantInfo.ABVariantTestID      = abTestID;
        variantInfo.ABVariantPath        = newDocument.NodeAliasPath;
        variantInfo.ABVariantName        = codeName;
        variantInfo.ABVariantDisplayName = newDocument.NodeAlias;
        variantInfo.ABVariantSiteID      = SiteContext.CurrentSiteID;

        try
        {
            ABVariantInfoProvider.SetABVariantInfo(variantInfo);
        }
        catch (InfoObjectException ex)
        {
            newDocument.Delete(true, true);
            ShowError(ex.Message);
            return(false);
        }
        return(true);
    }
コード例 #4
0
    /// <summary>
    /// Creates a new AB variant that should be created by default to given AB test
    /// </summary>
    private void CreateDefaultVariant(ABTestInfo info)
    {
        // Create instance of AB variant
        ABVariantInfo variant = new ABVariantInfo();

        // Set properties
        variant.ABVariantPath        = info.ABTestOriginalPage;
        variant.ABVariantTestID      = info.ABTestID;
        variant.ABVariantDisplayName = GetString("abtesting.originalvariantdisplayname");
        variant.ABVariantName        = "Original";
        variant.ABVariantSiteID      = info.ABTestSiteID;

        // Save to the storage
        ABVariantInfoProvider.SetABVariantInfo(variant);
    }
コード例 #5
0
    /// <summary>
    /// Creates document.
    /// </summary>
    /// <param name="createAnother">If false user will be redirected to created document</param>
    public int Save(bool createAnother)
    {
        // Validate input data
        string message = new Validator().NotEmpty(txtDocumentName.Text.Trim(), GetString("om.enterdocumentname")).Result;

        if (message == String.Empty)
        {
            if (node != null)
            {
                // Select parent node
                TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, ucPath.Value.ToString(), TreeProvider.ALL_CULTURES, false, null, false);
                if (parent != null)
                {
                    // Check security
                    if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(parent.NodeID, node.NodeClassName))
                    {
                        RedirectToAccessDenied(GetString("cmsdesk.notauthorizedtocreatedocument"));
                        return(0);
                    }
                    TreeNode newNode = ProcessAction(node, parent, "copynode", false, true, true);

                    if (newNode != null)
                    {
                        newNode.SetValue("DocumentMenuItemHideInNavigation", !chkShowInNavigation.Checked);
                        newNode.SetValue("DocumentShowInSiteMap", chkShowInSiteMap.Checked);
                        newNode.SetValue("DocumentSearchExcluded", chkExcludeFromSearch.Checked);
                        // Limit length to 100 characters
                        string nodeAlias = TextHelper.LimitLength(txtDocumentName.Text.Trim(), 100, String.Empty);
                        newNode.NodeAlias    = nodeAlias;
                        newNode.DocumentName = nodeAlias;

                        // Update menu item name
                        newNode.SetDocumentNameSource(nodeAlias);

                        newNode.Update();

                        // If ABTest selected - create new variant
                        int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0);
                        if (abTestID != 0)
                        {
                            ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID);
                            if (abTest != null)
                            {
                                string        defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newNode.GetDocumentName()), 45, String.Empty);
                                string        codeName        = defaultCodeName;
                                ABVariantInfo info            = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName);

                                // Find non existing variant code name
                                int index = 0;
                                while (info != null)
                                {
                                    index++;
                                    codeName = defaultCodeName + "-" + index;
                                    info     = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName);
                                }

                                // Save AB Variant
                                ABVariantInfo variantInfo = new ABVariantInfo();
                                variantInfo.ABVariantTestID      = abTestID;
                                variantInfo.ABVariantPath        = newNode.NodeAliasPath;
                                variantInfo.ABVariantName        = codeName;
                                variantInfo.ABVariantDisplayName = newNode.GetDocumentName();
                                variantInfo.ABVariantSiteID      = CMSContext.CurrentSiteID;

                                ABVariantInfoProvider.SetABVariantInfo(variantInfo);
                            }
                        }

                        // Get the page mode
                        if (CMSContext.ViewMode != ViewModeEnum.EditLive)
                        {
                            CMSContext.ViewMode = ViewModeEnum.EditForm;
                        }

                        txtDocumentName.Text = String.Empty;
                        return(newNode.NodeID);
                    }
                }
                else
                {
                    message = GetString("om.pathdoesnotexists");
                }
            }
        }

        if (message != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = message;
        }
        return(0);
    }
コード例 #6
0
    /// <summary>
    // Processes the form - saves the data.
    /// </summary>
    private void Process()
    {
        // Check manage permissions
        if (!CheckPermissions("CMS.ABTest", CMSAdminControl.PERMISSION_MANAGE))
        {
            return;
        }

        // Validate the form
        if (Validate())
        {
            bool isNew = false;

            // Ensure the info object
            if (this.AbTestObj == null)
            {
                this.AbTestObj = new ABTestInfo();
                if (AliasPath != String.Empty)
                {
                    this.AbTestObj.ABTestOriginalPage = AliasPath;
                }

                isNew = true;
            }

            // Initialize object
            String newName = this.txtABTestName.Text.Trim();
            this.AbTestObj.ABTestDisplayName    = this.txtABTestDisplayName.Text.Trim();
            this.AbTestObj.ABTestDescription    = this.txtABTestDescription.Text.Trim();
            this.AbTestObj.ABTestMaxConversions = ValidationHelper.GetInteger(this.txtABTestMaxConversions.Text.Trim(), 0);
            this.AbTestObj.ABTestOpenFrom       = this.dtpABTestOpenFrom.SelectedDateTime;
            this.AbTestObj.ABTestOpenTo         = this.dtpABTestOpenTo.SelectedDateTime;
            this.AbTestObj.ABTestCulture        = this.ucCultureSelector.Value.ToString();
            this.AbTestObj.ABTestEnabled        = this.chkABTestEnabled.Checked;
            this.AbTestObj.ABTestSiteID         = CMSContext.CurrentSiteID;

            // Name has changed. Change analytics statistics data for existing object
            if ((this.AbTestObj.ABTestID != 0) && (this.AbTestObj.ABTestName != newName))
            {
                ABTestInfoProvider.RenameABTestStatistics(this.AbTestObj.ABTestName, newName, CMSContext.CurrentSiteID);
            }
            this.AbTestObj.ABTestName = newName;

            // Store conversion type
            TargetConversionType conversionType = TargetConversionType.Total;
            if (radAnyVariant.Checked)
            {
                conversionType = TargetConversionType.AnyVariant;
            }
            this.AbTestObj.ABTestTargetConversionType = conversionType;

            if (ShowAliasPath)
            {
                this.AbTestObj.ABTestOriginalPage = this.ucPath.Value.ToString().Trim();
            }

            // Save object data to database
            ABTestInfoProvider.SetABTestInfo(this.AbTestObj);

            this.ItemID = this.AbTestObj.ABTestID;

            // For new A/B test create default variant
            if (isNew)
            {
                // Create instance of ab variant
                ABVariantInfo variant = new ABVariantInfo();

                // Set properties
                variant.ABVariantPath        = this.AbTestObj.ABTestOriginalPage;
                variant.ABVariantTestID      = this.AbTestObj.ABTestID;
                variant.ABVariantDisplayName = this.AbTestObj.ABTestDisplayName + " " + GetString("om.variant");
                variant.ABVariantName        = this.AbTestObj.ABTestName;
                variant.ABVariantSiteID      = this.AbTestObj.ABTestSiteID;

                // Save to the storage
                ABVariantInfoProvider.SetABVariantInfo(variant);
            }

            this.RaiseOnSaved();

            // Set the info message
            this.lblInfo.Text = GetString("general.changessaved");
        }
    }