コード例 #1
0
        /// <summary>
        /// Handles the Add actions event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void gFilters_Add(object sender, EventArgs e)
        {
            var rockContext      = new RockContext();
            var attributeService = new AttributeService(rockContext);

            // Reset attribute editor fields.
            edtFilter.Name            = string.Empty;
            edtFilter.Key             = string.Empty;
            edtFilter.AbbreviatedName = "";

            Rock.Model.Attribute attribute = new Rock.Model.Attribute();

            // Set attribute fields to those from a new attribute to made sure the AttributeEditor / ViewState has no leftover values.
            edtFilter.AttributeGuid       = attribute.Guid;
            edtFilter.AttributeId         = attribute.Id;
            edtFilter.IsFieldTypeEditable = true;
            edtFilter.SetAttributeFieldType(FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id, null);

            edtFilter.ReservedKeyNames = AttributeCache.AllForEntityType(_blockTypeEntityId)
                                         .Where(a =>
                                                a.EntityTypeQualifierColumn == "Id" &&
                                                a.EntityTypeQualifierValue == _block.Id.ToString())
                                         .Select(a => a.Key)
                                         .Distinct()
                                         .ToList();

            mdFilter.Title = "Add Filter";
            mdFilter.Show();
        }
コード例 #2
0
        /// <summary>
        /// Gs the defined type attributes_ show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute GUID.</param>
        protected void gDefinedTypeAttributes_ShowEdit(Guid attributeGuid)
        {
            pnlDetails.Visible = false;
            vsDetails.Enabled  = false;
            pnlDefinedTypeAttributes.Visible = true;

            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute             = new Attribute();
                attribute.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtDefinedTypeAttributes.ActionTitle = ActionTitle.Add("attribute for defined type " + tbTypeName.Text);
            }
            else
            {
                AttributeService attributeService = new AttributeService(new RockContext());
                attribute = attributeService.Get(attributeGuid);
                edtDefinedTypeAttributes.ActionTitle = ActionTitle.Edit("attribute for defined type " + tbTypeName.Text);
            }

            edtDefinedTypeAttributes.ReservedKeyNames = new AttributeService(new RockContext())
                                                        .GetByEntityTypeId(new DefinedValue().TypeId, true).AsQueryable()
                                                        .Where(a =>
                                                               a.EntityTypeQualifierColumn.Equals("DefinedTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                               a.EntityTypeQualifierValue.Equals(hfDefinedTypeId.Value) &&
                                                               !a.Guid.Equals(attributeGuid))
                                                        .Select(a => a.Key)
                                                        .Distinct()
                                                        .ToList();

            edtDefinedTypeAttributes.SetAttributeProperties(attribute, typeof(DefinedValue));

            this.HideSecondaryBlocks(true);
        }
コード例 #3
0
        /// <summary>
        /// Determines whether this instance can delete the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="checkAttributeUsage">if set to <c>true</c> [check attribute usage].</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns>
        ///   <c>true</c> if this instance can delete the specified item; otherwise, <c>false</c>.
        /// </returns>
        public bool CanDelete(AttributeMatrixTemplate item, bool checkAttributeUsage, out string errorMessage)
        {
            if (!this.CanDelete(item, out errorMessage))
            {
                return(false);
            }
            else
            {
                if (checkAttributeUsage)
                {
                    // check if any MatrixAttributes are using this AttributeMatrixTemplate
                    var matrixFieldTypeId    = FieldTypeCache.Get <MatrixFieldType>().Id;
                    var qualifierKey         = MatrixFieldType.ATTRIBUTE_MATRIX_TEMPLATE;
                    var qualifierValue       = item.Id.ToString();
                    var usedAsMatrixTemplate = new AttributeService(new RockContext()).Queryable()
                                               .Where(a => a.FieldTypeId == matrixFieldTypeId)
                                               .Any(a => a.AttributeQualifiers.Any(q => q.Key == qualifierKey && q.Value == qualifierValue));
                    if (usedAsMatrixTemplate)
                    {
                        errorMessage = string.Format("This {0} is assigned to an {1}.", AttributeMatrixTemplate.FriendlyTypeName, Rock.Model.Attribute.FriendlyTypeName);
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #4
0
        public IQueryable <ContentChannelItem> GetFromPersonDataView(string guids)
        {
            RockContext rockContext = new RockContext();

            // Turn the comma separated list of guids into a list of strings.
            List <string> guidList = (guids ?? "").Split(',').ToList();

            // Get the Id of the Rock.Model.ContentChannelItem Entity.
            int contentChannelItemEntityTypeId = EntityTypeCache.Get("Rock.Model.ContentChannelItem").Id;

            // Get the Field Type (Attribute Type) Id of the Data View Field Type.
            int fieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.DATAVIEWS.AsGuid()).Id;

            // Get the list of attributes that are of the Rock.Model.ContentChannelItem entity type
            // and that are of the Data View field type.
            List <int> attributeIdList = new AttributeService(rockContext)
                                         .GetByEntityTypeId(contentChannelItemEntityTypeId)
                                         .Where(item => item.FieldTypeId == fieldTypeId)
                                         .Select(a => a.Id)
                                         .ToList();

            // I want a list of content channel items whose ids match up to attribute values that represent entity ids
            IQueryable <ContentChannelItem> contentChannelItemList = new ContentChannelItemService(rockContext)
                                                                     .Queryable()
                                                                     .WhereAttributeValue(rockContext, av => attributeIdList.Contains(av.AttributeId) && guidList.Contains(av.Value));

            // Return this list
            return(contentChannelItemList);
        }
コード例 #5
0
        /// <summary>
        /// gs the item attributes show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute unique identifier.</param>
        protected void gItemAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                     = new Attribute();
                attribute.FieldTypeId         = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtItemAttributes.ActionTitle = ActionTitle.Add(tbName.Text + " Item Attribute");
            }
            else
            {
                attribute = ItemAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtItemAttributes.ActionTitle = ActionTitle.Edit(tbName.Text + " Item Attribute");
            }


            List <string> reservedKeys = ItemAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList();

            reservedKeys.AddRange(ItemInheritedKey);
            edtItemAttributes.ReservedKeyNames = reservedKeys;

            edtItemAttributes.SetAttributeProperties(attribute, typeof(ContentChannelItem));

            edtItemAttributes.IsIndexingEnabledVisible = cbIndexChannel.Visible && cbIndexChannel.Checked;

            ShowDialog("ItemAttributes", true);
        }
コード例 #6
0
ファイル: SiteDetail.ascx.cs プロジェクト: ewin66/rockrms
        /// <summary>
        /// gs the page attributes show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute unique identifier.</param>
        protected void gPageAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                     = new Attribute();
                attribute.FieldTypeId         = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtPageAttributes.ActionTitle = ActionTitle.Add("attribute for pages of site " + tbSiteName.Text);
            }
            else
            {
                attribute = PageAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtPageAttributes.ActionTitle = ActionTitle.Edit("attribute for pages of site " + tbSiteName.Text);
            }

            var reservedKeyNames = new List <string>();

            PageAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList().ForEach(a => reservedKeyNames.Add(a));
            edtPageAttributes.ReservedKeyNames = reservedKeyNames.ToList();

            edtPageAttributes.SetAttributeProperties(attribute, typeof(Rock.Model.Page));

            dlgPageAttribute.Show();
            HideSecondaryBlocks(true);
        }
コード例 #7
0
        /// <summary>
        /// Sets the entity field from field type attribute.
        /// </summary>
        /// <param name="entityField">The entity field.</param>
        /// <param name="fieldTypeAttribute">The field type attribute.</param>
        /// <returns></returns>
        private static bool SetEntityFieldFromFieldTypeAttribute(EntityField entityField, FieldTypeAttribute fieldTypeAttribute)
        {
            if (fieldTypeAttribute != null)
            {
                var fieldTypeCache = FieldTypeCache.Get(fieldTypeAttribute.FieldTypeGuid);
                if (fieldTypeCache != null && fieldTypeCache.Field != null)
                {
                    if (fieldTypeCache.Field.HasFilterControl())
                    {
                        if (entityField.Title.EndsWith(" Id"))
                        {
                            entityField.Title = entityField.Title.ReplaceLastOccurrence(" Id", string.Empty);
                        }

                        entityField.FieldType = fieldTypeCache;
                        if (fieldTypeAttribute.ConfigurationKey != null && fieldTypeAttribute.ConfigurationValue != null)
                        {
                            entityField.FieldConfig.Add(fieldTypeAttribute.ConfigurationKey, new ConfigurationValue(fieldTypeAttribute.ConfigurationValue));
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #8
0
        /// <summary>
        /// Creates a <see cref="Rock.Field.FieldVisibilityRule"/>
        /// object from its view model representation.
        /// </summary>
        /// <param name="viewModel">The view model that represents the object.</param>
        /// <returns>The object created from the view model.</returns>
        internal static Rock.Field.FieldVisibilityRule FromViewModel(this FieldFilterRuleViewModel viewModel, List <FormFieldViewModel> formFields)
        {
            var rule = new Rock.Field.FieldVisibilityRule
            {
                Guid                    = viewModel.Guid,
                ComparisonType          = ( ComparisonType )viewModel.ComparisonType,
                ComparedToFormFieldGuid = viewModel.AttributeGuid,
                ComparedToValue         = viewModel.Value
            };

            if (rule.ComparedToFormFieldGuid.HasValue)
            {
                var comparisonValue = new Rock.Reporting.ComparisonValue
                {
                    ComparisonType = rule.ComparisonType,
                    Value          = rule.ComparedToValue
                };
                var field = formFields.Where(f => f.Guid == rule.ComparedToFormFieldGuid.Value).FirstOrDefault();

                if (field != null)
                {
                    var fieldType = FieldTypeCache.Get(field.FieldTypeGuid);

                    if (fieldType?.Field != null)
                    {
                        var privateConfigurationValues = fieldType.Field.GetPrivateConfigurationValues(field.ConfigurationValues);
                        var filterValues = fieldType.Field.GetPrivateFilterValue(comparisonValue, privateConfigurationValues).FromJsonOrNull <List <string> >();

                        if (filterValues != null && filterValues.Count == 2)
                        {
                            rule.ComparedToValue = filterValues[1];
                        }
                        else if (filterValues != null && filterValues.Count == 1)
                        {
                            rule.ComparedToValue = filterValues[0];
                        }
                    }
                }
                else
                {
                    var attribute = AttributeCache.Get(rule.ComparedToFormFieldGuid.Value);

                    if (attribute?.FieldType?.Field != null)
                    {
                        var filterValues = attribute.FieldType.Field.GetPrivateFilterValue(comparisonValue, attribute.ConfigurationValues).FromJsonOrNull <List <string> >();

                        if (filterValues != null && filterValues.Count == 2)
                        {
                            rule.ComparedToValue = filterValues[1];
                        }
                        else if (filterValues != null && filterValues.Count == 1)
                        {
                            rule.ComparedToValue = filterValues[0];
                        }
                    }
                }
            }

            return(rule);
        }
コード例 #9
0
        /// <summary>
        /// Gs the group type attributes_ show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute GUID.</param>
        protected void gAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                 = new Attribute();
                attribute.FieldTypeId     = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtAttributes.ActionTitle = ActionTitle.Add("attribute for matrix attributes that use matrix template " + tbName.Text);
            }
            else
            {
                attribute = AttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtAttributes.ActionTitle = ActionTitle.Edit("attribute for matrix attributes that use matrix template " + tbName.Text);
            }

            var reservedKeyNames = new List <string>();

            AttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList().ForEach(a => reservedKeyNames.Add(a));
            edtAttributes.ReservedKeyNames = reservedKeyNames.ToList();

            edtAttributes.ExcludedFieldTypes = new FieldTypeCache[] { FieldTypeCache.Get <MatrixFieldType>() };
            edtAttributes.SetAttributeProperties(attribute, typeof(AttributeMatrixTemplate));

            dlgAttribute.Show();
        }
コード例 #10
0
        /// <summary>
        /// gs the item attributes show edit.
        /// </summary>
        /// <param name="attributeGuid">The attribute unique identifier.</param>
        protected void gItemAttributes_ShowEdit(Guid attributeGuid)
        {
            Attribute attribute;

            if (attributeGuid.Equals(Guid.Empty))
            {
                attribute                     = new Attribute();
                attribute.FieldTypeId         = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                edtItemAttributes.ActionTitle = ActionTitle.Add(tbName.Text + " Item Attribute");
            }
            else
            {
                attribute = ItemAttributesState.First(a => a.Guid.Equals(attributeGuid));
                edtItemAttributes.ActionTitle = ActionTitle.Edit(tbName.Text + " Item Attribute");
            }

            edtItemAttributes.ReservedKeyNames = ItemAttributesState.Where(a => !a.Guid.Equals(attributeGuid)).Select(a => a.Key).ToList();

            edtItemAttributes.SetAttributeProperties(attribute, typeof(ContentChannelItem));

            // always enable the display of the indexing option as the channel decides whether or not to index not the type
            edtItemAttributes.IsIndexingEnabledVisible = true;

            ShowDialog("ItemAttributes", true);
        }
コード例 #11
0
        /// <summary>
        /// Gets the attribute value.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="key">The key.</param>
        /// <param name="checkWorkflowAttributeValue">if set to <c>true</c> and the returned value is a guid, check to see if the workflow
        /// or activity contains an attribute with that guid. This is useful when using the WorkflowTextOrAttribute field types to get the
        /// actual value or workflow value.</param>
        /// <returns></returns>
        protected string GetAttributeValue(WorkflowAction action, string key, bool checkWorkflowAttributeValue)
        {
            string value = GetActionAttributeValue(action, key);

            if (checkWorkflowAttributeValue)
            {
                Guid?attributeGuid = value.AsGuidOrNull();
                if (attributeGuid.HasValue)
                {
                    var attribute = AttributeCache.Get(attributeGuid.Value);
                    if (attribute != null)
                    {
                        value = action.GetWorklowAttributeValue(attributeGuid.Value);
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            if (attribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.ENCRYPTED_TEXT.AsGuid()).Id)
                            {
                                value = Security.Encryption.DecryptString(value);
                            }
                            else if (attribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.SSN.AsGuid()).Id)
                            {
                                value = Rock.Field.Types.SSNFieldType.UnencryptAndClean(value);
                            }
                        }
                    }
                }
            }

            return(value);
        }
コード例 #12
0
        /// <summary>
        /// Sets the form.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="workflowTypeAttributes">The workflow type attributes.</param>
        public void SetForm(WorkflowActionForm value, Dictionary <Guid, Rock.Model.Attribute> workflowTypeAttributes)
        {
            EnsureChildControls();

            if (value != null)
            {
                _hfFormGuid.Value = value.Guid.ToString();
                _ddlNotificationSystemEmail.SetValue(value.NotificationSystemEmailId);
                _cbIncludeActions.Checked = value.IncludeActionsInNotification;
                _ceHeaderText.Text        = value.Header;
                _ceFooterText.Text        = value.Footer;
                _falActions.Value         = value.Actions;
                _cbAllowNotes.Checked     = value.AllowNotes.HasValue && value.AllowNotes.Value;

                // Remove any existing rows (shouldn't be any)
                foreach (var attributeRow in Controls.OfType <WorkflowFormAttributeRow>())
                {
                    Controls.Remove(attributeRow);
                }

                foreach (var formAttribute in value.FormAttributes.OrderBy(a => a.Order))
                {
                    var row = new WorkflowFormAttributeRow();
                    row.AttributeGuid = formAttribute.Attribute.Guid;
                    row.AttributeName = formAttribute.Attribute.Name;
                    row.Guid          = formAttribute.Guid;
                    row.IsVisible     = formAttribute.IsVisible;
                    row.IsEditable    = !formAttribute.IsReadOnly;
                    row.IsRequired    = formAttribute.IsRequired;
                    row.HideLabel     = formAttribute.HideLabel;
                    row.PreHtml       = formAttribute.PreHtml;
                    row.PostHtml      = formAttribute.PostHtml;
                    Controls.Add(row);
                }

                _ddlActionAttribute.Items.Clear();
                _ddlActionAttribute.Items.Add(new ListItem());
                foreach (var attributeItem in workflowTypeAttributes)
                {
                    var fieldType = FieldTypeCache.Get(attributeItem.Value.FieldTypeId);
                    if (fieldType != null && fieldType.Field is Rock.Field.Types.TextFieldType)
                    {
                        var li = new ListItem(attributeItem.Value.Name, attributeItem.Key.ToString());
                        li.Selected = value.ActionAttributeGuid.HasValue && value.ActionAttributeGuid.Value.ToString() == li.Value;
                        _ddlActionAttribute.Items.Add(li);
                    }
                }
            }
            else
            {
                _hfFormGuid.Value = string.Empty;
                _ddlNotificationSystemEmail.SelectedIndex = 0;
                _cbIncludeActions.Checked = true;
                _ceHeaderText.Text        = string.Empty;
                _ceFooterText.Text        = string.Empty;
                _falActions.Value         = "Submit^^^Your information has been submitted successfully.";
                _ddlNotificationSystemEmail.SelectedIndex = 0;
                _cbAllowNotes.Checked = false;
            }
        }
コード例 #13
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public static void SetValue(string key, string value)
        {
            var rockContext      = new Rock.Data.RockContext();
            var attributeService = new AttributeService(rockContext);
            var attribute        = attributeService.GetSystemSetting(key);

            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.FieldTypeId = FieldTypeCache.Get(new Guid(SystemGuid.FieldType.TEXT)).Id;
                attribute.EntityTypeQualifierColumn = Rock.Model.Attribute.SYSTEM_SETTING_QUALIFIER;
                attribute.EntityTypeQualifierValue  = string.Empty;
                attribute.Key          = key;
                attribute.Name         = key.SplitCase();
                attribute.DefaultValue = value;
                attributeService.Add(attribute);
            }
            else
            {
                attribute.DefaultValue = value;
            }

            // NOTE: Service Layer will automatically update this Cache (see Attribute.cs UpdateCache)
            rockContext.SaveChanges();

            if (key == Rock.SystemKey.SystemSetting.START_DAY_OF_WEEK)
            {
                RockDateTime.FirstDayOfWeek = value.ConvertToEnumOrNull <DayOfWeek>() ?? RockDateTime.DefaultFirstDayOfWeek;
            }
        }
コード例 #14
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            var filteredFieldTypes = new List <string>();

            if (configurationValues != null &&
                configurationValues.ContainsKey(ATTRIBUTE_FIELD_TYPES_KEY))
            {
                filteredFieldTypes = configurationValues[ATTRIBUTE_FIELD_TYPES_KEY].Value
                                     .Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            var editControl = new Rock.Web.UI.Controls.RockDropDownList {
                ID = id
            };

            editControl.Items.Add(new ListItem());

            var attributes = GetContextAttributes();

            if (attributes != null)
            {
                foreach (var attribute in attributes)
                {
                    var fieldType = FieldTypeCache.Get(attribute.Value.FieldTypeId);
                    if (!filteredFieldTypes.Any() || filteredFieldTypes.Contains(fieldType.Class, StringComparer.OrdinalIgnoreCase))
                    {
                        editControl.Items.Add(new ListItem(attribute.Value.Name, attribute.Key.ToString()));
                    }
                }
            }

            return(editControl);
        }
コード例 #15
0
        private void LoadRockGroup(Group group)
        {
            _rockGroup   = group;
            _rockGroupId = _rockGroup.Id;

            var ebFieldType = FieldTypeCache.Get(rocks.kfs.Eventbrite.EBGuid.FieldType.EVENTBRITE_EVENT.AsGuid());

            if (ebFieldType != null)
            {
                _rockGroup.LoadAttributes(_rockContext);
                var attribute = _rockGroup.Attributes.Select(a => a.Value).FirstOrDefault(a => a.FieldTypeId == ebFieldType.Id);
                if (attribute != null)
                {
                    var attributeVal = _rockGroup.AttributeValues.Select(av => av.Value).FirstOrDefault(av => av.AttributeId == attribute.Id && av.Value != "");
                    if (attributeVal != null)
                    {
                        var splitVal = attributeVal.Value.SplitDelimitedValues("^");
                        if (splitVal.Length > 0)
                        {
                            _evntId = splitVal[0].AsLong();
                        }
                        if (splitVal.Length > 1)
                        {
                            _synced = splitVal[1];
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: Checkr.cs プロジェクト: waldo2590/Rock
 /// <summary>
 /// Sets the workflow RequestStatus attribute.
 /// </summary>
 /// <param name="workflow">The workflow.</param>
 /// <param name="rockContext">The rock context.</param>
 /// <param name="requestStatus">The request status.</param>
 private void UpdateWorkflowRequestStatus(Model.Workflow workflow, RockContext rockContext, string requestStatus)
 {
     if (SaveAttributeValue(workflow, "RequestStatus", requestStatus,
                            FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext, null))
     {
         rockContext.SaveChanges();
     }
 }
コード例 #17
0
        /// <summary>
        /// Displays the edit list.
        /// </summary>
        private void DisplayEditList()
        {
            lEditHeader.Text = GetAttributeValue("EditHeader");
            lEditFooter.Text = GetAttributeValue("EditFooter");

            if (_definedType != null)
            {
                using (var rockContext = new RockContext())
                {
                    var entityType  = EntityTypeCache.Get("Rock.Model.DefinedValue");
                    var definedType = new DefinedTypeService(rockContext).Get(_definedType.Id);
                    if (definedType != null && entityType != null)
                    {
                        var attributeService = new AttributeService(rockContext);
                        var attributes       = new AttributeService(rockContext)
                                               .GetByEntityTypeQualifier(entityType.Id, "DefinedTypeId", definedType.Id.ToString(), false)
                                               .ToList();

                        // Verify (and create if necessary) the "Is Link" attribute
                        if (!attributes.Any(a => a.Key == "IsLink"))
                        {
                            var fieldType = FieldTypeCache.Get(Rock.SystemGuid.FieldType.BOOLEAN);
                            if (entityType != null && fieldType != null)
                            {
                                var attribute = new Rock.Model.Attribute();
                                attributeService.Add(attribute);
                                attribute.EntityTypeId = entityType.Id;
                                attribute.EntityTypeQualifierColumn = "DefinedTypeId";
                                attribute.EntityTypeQualifierValue  = definedType.Id.ToString();
                                attribute.FieldTypeId  = fieldType.Id;
                                attribute.Name         = "Is Link";
                                attribute.Key          = "IsLink";
                                attribute.Description  = "Flag indicating if value is a link (vs Header)";
                                attribute.IsGridColumn = true;
                                attribute.DefaultValue = true.ToString();

                                var qualifier1 = new AttributeQualifier();
                                qualifier1.Key   = "truetext";
                                qualifier1.Value = "Yes";
                                attribute.AttributeQualifiers.Add(qualifier1);

                                var qualifier2 = new AttributeQualifier();
                                qualifier2.Key   = "falsetext";
                                qualifier2.Value = "No";
                                attribute.AttributeQualifiers.Add(qualifier2);

                                rockContext.SaveChanges();
                            }
                        }
                    }
                }

                BindGrid();

                pnlView.Visible = false;
                pnlEdit.Visible = true;
            }
        }
コード例 #18
0
        /// <summary>
        /// Executes the specified workflow action.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // Get the attribute's guid
            Guid guid = GetAttributeValue(action, "Attribute").AsGuid();

            if (!guid.IsEmpty())
            {
                // Get the attribute
                var attribute = AttributeCache.Get(guid, rockContext);
                if (attribute != null)
                {
                    if (attribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.PERSON.AsGuid(), rockContext).Id)
                    {
                        // If attribute type is a person, value should be person alias id
                        Guid?personAliasGuid = action.GetWorklowAttributeValue(guid).AsGuidOrNull();
                        if (personAliasGuid.HasValue)
                        {
                            var personAlias = new PersonAliasService(rockContext).Queryable("Person")
                                              .Where(a => a.Guid.Equals(personAliasGuid.Value))
                                              .FirstOrDefault();
                            if (personAlias != null)
                            {
                                action.Activity.AssignedPersonAlias   = personAlias;
                                action.Activity.AssignedPersonAliasId = personAlias.Id;
                                action.Activity.AssignedGroup         = null;
                                action.Activity.AssignedGroupId       = null;
                                action.AddLogEntry(string.Format("Assigned activity to '{0}' ({1})", personAlias.Person.FullName, personAlias.Person.Id));
                                return(true);
                            }
                        }
                    }

                    else if (attribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.GROUP.AsGuid(), rockContext).Id)
                    {
                        // If attribute type is a group, value should be group guid
                        Guid?groupGuid = action.GetWorklowAttributeValue(guid).AsGuidOrNull();
                        if (groupGuid.HasValue)
                        {
                            var group = new GroupService(rockContext).Get(groupGuid.Value);
                            if (group != null)
                            {
                                action.Activity.AssignedPersonAlias   = null;
                                action.Activity.AssignedPersonAliasId = null;
                                action.Activity.AssignedGroup         = group;
                                action.Activity.AssignedGroupId       = group.Id;
                                action.AddLogEntry(string.Format("Assigned activity to '{0}' group ({1})", group.Name, group.Id));
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #19
0
        /// <summary>
        /// Gets the list of view models that represent all the sections and fields
        /// of a form.
        /// </summary>
        /// <param name="actionForm">The <see cref="WorkflowActionForm"/> to be represented.</param>
        /// <returns>A collection of view models that represent that sections that will be edited.</returns>
        private static List <FormSectionViewModel> GetFormSectionViewModels(WorkflowActionForm actionForm)
        {
            var sectionViewModels = new List <FormSectionViewModel>();

            foreach (var workflowFormSection in actionForm.FormSections.OrderBy(s => s.Order))
            {
                // Create the basic section view model.
                var sectionViewModel = new FormSectionViewModel
                {
                    Guid                 = workflowFormSection.Guid,
                    Description          = workflowFormSection.Description,
                    Fields               = new List <FormFieldViewModel>(),
                    ShowHeadingSeparator = workflowFormSection.ShowHeadingSeparator,
                    Title                = workflowFormSection.Title,
                    Type                 = Rock.Blocks.WorkFlow.FormBuilder.Utility.GetDefinedValueGuid(workflowFormSection.SectionTypeValueId),
                    VisibilityRule       = workflowFormSection.SectionVisibilityRules?.ToViewModel()
                };

                // Get all the form attributes for this section.
                var formAttributes = actionForm.FormAttributes
                                     .Where(a => a.ActionFormSectionId == workflowFormSection.Id)
                                     .ToList();

                // Loop through each form attribute and make a view model out of it.
                foreach (var formAttribute in formAttributes.OrderBy(a => a.Order))
                {
                    var attribute = AttributeCache.Get(formAttribute.AttributeId);
                    var fieldType = FieldTypeCache.Get(attribute.FieldTypeId);

                    if (fieldType == null || fieldType.Field == null)
                    {
                        continue;
                    }

                    sectionViewModel.Fields.Add(new FormFieldViewModel
                    {
                        ConfigurationValues = fieldType.Field.GetPublicConfigurationValues(attribute.ConfigurationValues, Field.ConfigurationValueUsage.Configure, null),
                        DefaultValue        = fieldType.Field.GetPublicEditValue(attribute.DefaultValue, attribute.ConfigurationValues),
                        Description         = attribute.Description,
                        FieldTypeGuid       = fieldType.Guid,
                        Guid           = attribute.Guid,
                        IsHideLabel    = formAttribute.HideLabel,
                        IsRequired     = attribute.IsRequired,
                        IsShowOnGrid   = attribute.IsGridColumn,
                        Key            = attribute.Key,
                        Name           = attribute.Name,
                        Size           = formAttribute.ColumnSize ?? 12,
                        VisibilityRule = formAttribute.FieldVisibilityRules?.ToViewModel()
                    });
                }

                sectionViewModels.Add(sectionViewModel);
            }

            return(sectionViewModels);
        }
コード例 #20
0
        /// <summary>
        /// Gets the field type cache used for the given registration field type if it is supported
        /// </summary>
        /// <param name="fieldType"></param>
        /// <returns></returns>
        public static FieldTypeCache GetSupportedFieldTypeCache(RegistrationPersonFieldType fieldType)
        {
            switch (fieldType)
            {
            case RegistrationPersonFieldType.Gender:
                return(FieldTypeCache.Get(SystemGuid.FieldType.GENDER));

            default:
                return(null);
            }
        }
コード例 #21
0
        /// <summary>
        /// Gets the Guid for the FieldType that has the specified Id
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public override Guid?GetGuid(int id)
        {
            var cacheItem = FieldTypeCache.Get(id);

            if (cacheItem != null)
            {
                return(cacheItem.Guid);
            }

            return(null);
        }
コード例 #22
0
        private DateTime GetDateTimeActivated(WorkflowAction action)
        {
            var dateActivated = RockDateTime.Now;

            // Use the current action type' guid as the key for a 'Delay Activated' attribute
            string AttrKey = action.ActionTypeCache.Guid.ToString();

            // Check to see if the action's activity does not yet have the 'Delay Activated' attribute.
            // The first time this action runs on any workflow instance using this action instance, the
            // attribute will not exist and need to be created
            if (!action.Activity.Attributes.ContainsKey(AttrKey))
            {
                var attribute = new Rock.Model.Attribute();
                attribute.EntityTypeId = action.Activity.TypeId;
                attribute.EntityTypeQualifierColumn = "ActivityTypeId";
                attribute.EntityTypeQualifierValue  = action.Activity.ActivityTypeId.ToString();
                attribute.Name        = "Delay Activated";
                attribute.Key         = AttrKey;
                attribute.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()).Id;

                // Need to save the attribute now (using different context) so that an attribute id is returned.
                using (var newRockContext = new RockContext())
                {
                    new AttributeService(newRockContext).Add(attribute);
                    newRockContext.SaveChanges();
                }

                action.Activity.Attributes.Add(AttrKey, AttributeCache.Get(attribute));
                var attributeValue = new AttributeValueCache();
                attributeValue.AttributeId = attribute.Id;
                attributeValue.Value       = dateActivated.ToString("o");
                action.Activity.AttributeValues.Add(AttrKey, attributeValue);

                action.AddLogEntry(string.Format("Delay Activated at {0}", dateActivated), true);
            }
            else
            {
                // Check to see if this action instance has a value for the 'Delay Activated' attribute
                DateTime?activated = action.Activity.GetAttributeValue(AttrKey).AsDateTime();
                if (activated.HasValue)
                {
                    return(activated.Value);
                }
                else
                {
                    // If no value exists, set the value to the current time
                    action.Activity.SetAttributeValue(AttrKey, dateActivated.ToString("o"));
                    action.AddLogEntry(string.Format("Delay Activated at {0}", dateActivated), true);
                }
            }

            return(dateActivated);
        }
コード例 #23
0
        /// <summary>
        /// Applies the additional properties and security to view model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="loadAttributes">if set to <c>true</c> [load attributes].</param>
        public override void ApplyAdditionalPropertiesAndSecurityToViewModel(Attribute model, AttributeViewModel viewModel, Person currentPerson = null, bool loadAttributes = true)
        {
            var attributeCache = AttributeCache.Get(model.Id);

            viewModel.FieldTypeGuid   = FieldTypeCache.Get(attributeCache.FieldTypeId).Guid;
            viewModel.CategoryGuids   = attributeCache.Categories.Select(c => c.Guid).ToArray();
            viewModel.QualifierValues = attributeCache.QualifierValues.ToDictionary(kvp => kvp.Key, kvp => new ViewModel.NonEntities.AttributeConfigurationValue
            {
                Name        = kvp.Value.Name,
                Value       = kvp.Value.Value,
                Description = kvp.Value.Description
            });
        }
コード例 #24
0
        public BlockActionResult GetFilterSources(List <FormFieldViewModel> formFields)
        {
            var fieldFilterSources = new List <FieldFilterSourceViewModel>();

            foreach (var field in formFields)
            {
                var fieldType = FieldTypeCache.Get(field.FieldTypeGuid);

                // If the field type or its C# component could not be found then
                // we abort with a hard error. We need it to convert data.
                if (fieldType == null || fieldType.Field == null)
                {
                    throw new Exception($"Field type '{field.FieldTypeGuid}' not found.");
                }

                // Convert the attribute configuration into values that can be used
                // for filtering a value.
                var privateConfigurationValues = fieldType.Field.GetPrivateConfigurationValues(field.ConfigurationValues);
                var publicConfigurationValues  = fieldType.Field.GetPublicConfigurationValues(privateConfigurationValues, Field.ConfigurationValueUsage.Configure, null);

                /*
                 * Daniel Hazelbaker - 3/17/2022
                 *
                 * This should be removed once the WorkflowEntry block has been converted
                 * into Obsidian. This filters out any form fields whose field type does
                 * not support change notification in WebForms.
                 */
                if (!fieldType.IsWebFormChangeNotificationSupported(privateConfigurationValues))
                {
                    continue;
                }

                var source = new FieldFilterSourceViewModel
                {
                    Guid      = field.Guid,
                    Type      = 0,
                    Attribute = new PublicFilterableAttributeViewModel
                    {
                        AttributeGuid       = field.Guid,
                        ConfigurationValues = publicConfigurationValues,
                        Description         = field.Description,
                        FieldTypeGuid       = field.FieldTypeGuid,
                        Name = field.Name
                    }
                };

                fieldFilterSources.Add(source);
            }

            return(ActionOk(fieldFilterSources));
        }
コード例 #25
0
        private double HoursElapsed(WorkflowAction action)
        {
            // Use the current action type' guid as the key for a 'DateTime Sent' attribute
            string AttrKey = action.ActionTypeCache.Guid.ToString() + "_DateTimeSent";

            // Check to see if the action's activity does not yet have the 'DateTime Sent' attribute.
            // The first time this action runs on any workflow instance using this action instance, the
            // attribute will not exist and need to be created
            if (!action.Activity.Attributes.ContainsKey(AttrKey))
            {
                var attribute = new Rock.Model.Attribute();
                attribute.EntityTypeId = action.Activity.TypeId;
                attribute.EntityTypeQualifierColumn = "ActivityTypeId";
                attribute.EntityTypeQualifierValue  = action.Activity.ActivityTypeId.ToString();
                attribute.Name        = "DateTime Sent";
                attribute.Key         = AttrKey;
                attribute.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()).Id;

                // Need to save the attribute now (using different context) so that an attribute id is returned.
                using (var newRockContext = new RockContext())
                {
                    new AttributeService(newRockContext).Add(attribute);
                    newRockContext.SaveChanges();
                }

                action.Activity.Attributes.Add(AttrKey, AttributeCache.Get(attribute));
                var attributeValue = new AttributeValueCache();
                attributeValue.AttributeId = attribute.Id;
                attributeValue.Value       = RockDateTime.Now.ToString("o");
                action.Activity.AttributeValues.Add(AttrKey, attributeValue);
            }
            else
            {
                // Check to see if this action instance has a value for the 'Delay Activated' attribute
                DateTime?dateSent = action.Activity.GetAttributeValue(AttrKey).AsDateTime();
                if (dateSent.HasValue)
                {
                    // If a value does exist, check to see if the number of minutes to delay has passed
                    // since the value was saved
                    return(RockDateTime.Now.Subtract(dateSent.Value).TotalHours);
                }
                else
                {
                    // If no value exists, set the value to the current time
                    action.Activity.SetAttributeValue(AttrKey, RockDateTime.Now.ToString("o"));
                }
            }

            return(0.0D);
        }
コード例 #26
0
        private DateTime GetDateTimeActivated(WorkflowAction action)
        {
            var dateActivated = RockDateTime.Now;

            string AttrKey = action.ActionTypeCache.Guid.ToString();

            if (!action.Activity.Attributes.ContainsKey(AttrKey))
            {
                var attribute = new Rock.Model.Attribute
                {
                    EntityTypeId = action.Activity.TypeId,
                    EntityTypeQualifierColumn = "ActivityTypeId",
                    EntityTypeQualifierValue  = action.Activity.ActivityTypeId.ToString(),
                    Name        = "Process Signature Activated",
                    Key         = AttrKey,
                    FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()).Id
                };

                using (var newRockContext = new RockContext())
                {
                    new AttributeService(newRockContext).Add(attribute);
                    newRockContext.SaveChanges();
                }

                action.Activity.Attributes.Add(AttrKey, AttributeCache.Get(attribute));
                var attributeValue = new AttributeValueCache
                {
                    AttributeId = attribute.Id,
                    Value       = dateActivated.ToString("o")
                };
                action.Activity.AttributeValues.Add(AttrKey, attributeValue);

                action.AddLogEntry(string.Format("Process Signature Activated at {0}", dateActivated), true);
            }
            else
            {
                DateTime?activated = action.Activity.GetAttributeValue(AttrKey).AsDateTime();
                if (activated.HasValue)
                {
                    return(activated.Value);
                }
                else
                {
                    action.Activity.SetAttributeValue(AttrKey, dateActivated.ToString("o"));
                    action.AddLogEntry(string.Format("Process Signature Activated at {0}", dateActivated), true);
                }
            }

            return(dateActivated);
        }
コード例 #27
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // get the group attribute
            Guid groupAttributeGuid = GetAttributeValue(action, "Group").AsGuid();

            if (!groupAttributeGuid.IsEmpty())
            {
                Guid?groupGuid = action.GetWorkflowAttributeValue(groupAttributeGuid).AsGuidOrNull();

                if (groupGuid.HasValue)
                {
                    var groupLeader = new GroupMemberService(rockContext).Queryable().AsNoTracking()
                                      .Where(g => g.Group.Guid == groupGuid && g.GroupRole.IsLeader)
                                      .Select(g => g.Person).FirstOrDefault();

                    if (groupLeader != null)
                    {
                        // Get the attribute to set
                        Guid leaderGuid = GetAttributeValue(action, "Leader").AsGuid();
                        if (!leaderGuid.IsEmpty())
                        {
                            var personAttribute = AttributeCache.Get(leaderGuid, rockContext);
                            if (personAttribute != null)
                            {
                                // If this is a person type attribute
                                if (personAttribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.PERSON.AsGuid(), rockContext).Id)
                                {
                                    SetWorkflowAttributeValue(action, leaderGuid, groupLeader.PrimaryAlias.Guid.ToString());
                                }
                                else if (personAttribute.FieldTypeId == FieldTypeCache.Get(SystemGuid.FieldType.TEXT.AsGuid(), rockContext).Id)
                                {
                                    SetWorkflowAttributeValue(action, leaderGuid, groupLeader.FullName);
                                }
                            }
                        }
                    }
                }
                else
                {
                    errorMessages.Add("The group could not be found!");
                }
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(true);
        }
コード例 #28
0
        /// <summary>
        /// Handles the SaveClick event of the mdAttributeValue control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void mdAttributeValue_SaveClick(object sender, EventArgs e)
        {
            if (_displayValueEdit)
            {
                // If page is not valid, exit and allow validators to display error messages.
                Page.Validate();

                if (!Page.IsValid)
                {
                    return;
                }

                int attributeId = 0;
                if (hfIdValues.Value != string.Empty && !int.TryParse(hfIdValues.Value, out attributeId))
                {
                    attributeId = 0;
                }

                if (attributeId != 0 && phEditControls.Controls.Count > 0)
                {
                    var attribute = Rock.Web.Cache.AttributeCache.Get(attributeId);

                    var rockContext           = new RockContext();
                    var attributeValueService = new AttributeValueService(rockContext);
                    var attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId);
                    if (attributeValue == null)
                    {
                        attributeValue = new AttributeValue
                        {
                            AttributeId = attributeId,
                            EntityId    = _entityId
                        };
                        attributeValueService.Add(attributeValue);
                    }

                    var fieldType = FieldTypeCache.Get(attribute.FieldType.Id);
                    attributeValue.Value = fieldType.Field.GetEditValue(attribute.GetControl(phEditControls.Controls[0]), attribute.QualifierValues);

                    rockContext.SaveChanges();
                }

                hfIdValues.Value = string.Empty;

                HideDialog();
            }

            BindGrid();
        }
コード例 #29
0
        /// <summary>
        /// Handles the RowDataBound event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs" /> instance containing the event data.</param>
        protected void gFilters_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int attributeId = ( int )gFilters.DataKeys[e.Row.RowIndex].Value;

                var attribute = Rock.Web.Cache.AttributeCache.Get(attributeId);
                var fieldType = FieldTypeCache.Get(attribute.FieldTypeId);

                Literal lDefaultValue = e.Row.FindControl("lDefaultValue") as Literal;
                if (lDefaultValue != null)
                {
                    lDefaultValue.Text = fieldType.Field.FormatValueAsHtml(lDefaultValue, attribute.EntityTypeId, null, attribute.DefaultValue, attribute.QualifierValues, true);
                }
            }
        }
コード例 #30
0
        public static Group GetGroupByEBEventId(long ebEventId, RockContext rockContext)
        {
            Group retVar      = null;
            var   ebFieldType = FieldTypeCache.Get(EBGuid.FieldType.EVENTBRITE_EVENT.AsGuid());

            if (ebFieldType != null)
            {
                var attributeVal = new AttributeValueService(rockContext).Queryable().FirstOrDefault(av => av.Attribute.FieldTypeId == ebFieldType.Id && av.Value.Contains(ebEventId.ToString()));
                if (attributeVal != null)
                {
                    retVar = new GroupService(rockContext).Get(attributeVal.EntityId ?? 0);
                }
            }

            return(retVar);
        }