예제 #1
0
        /// <summary> Returns an array of all values of a specified optional or non-
        /// standard qualifier of the element.
        ///
        /// The getQualifier method may be used to access the values of
        /// vendor-specific qualifiers (which begin with "X-").
        ///
        /// </summary>
        /// <param name="name">     The name of the qualifier, case-sensitive.
        ///
        /// </param>
        /// <returns> An array of values for the specified non-standard qualifier.
        /// </returns>
        public virtual string[] getQualifier(string name)
        {
            AttributeQualifier attr = (AttributeQualifier)hashQualifier[name];

            if (attr != null)
            {
                return(attr.Values);
            }
            return(null);
        }
        /// <summary>
        ///     Sets the values of a specified optional or non-standard qualifier of
        ///     the element.
        ///     The setQualifier method is used to set the values of vendor-
        ///     specific qualifiers (which begin with "X-").
        /// </summary>
        /// <param name="name">
        ///     The name of the qualifier, case-sensitive.
        /// </param>
        /// <param name="values">
        ///     The values to set for the qualifier.
        /// </param>
        public void SetQualifier(string name, string[] values)
        {
            _hashQualifier[name] = new AttributeQualifier(name, values);

            /*
             * This is the only method that modifies the schema element.
             * We need to reset the attribute value since it has changed.
             */
            Value = FormatString();
        }
예제 #3
0
파일: Checkr.cs 프로젝트: waldo2590/Rock
        /// <summary>
        /// Saves the attribute value.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="fieldType">Type of the field.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="qualifiers">The qualifiers.</param>
        /// <returns>True/False value of whether the request was successfully sent or not.</returns>
        private static bool SaveAttributeValue(Rock.Model.Workflow workflow, string key, string value,
                                               FieldTypeCache fieldType, RockContext rockContext, Dictionary <string, string> qualifiers = null)
        {
            bool createdNewAttribute = false;

            if (workflow.Attributes.ContainsKey(key))
            {
                workflow.SetAttributeValue(key, value);
            }
            else
            {
                // Read the attribute
                var attributeService = new AttributeService(rockContext);
                var attribute        = attributeService
                                       .Get(workflow.TypeId, "WorkflowTypeId", workflow.WorkflowTypeId.ToString())
                                       .Where(a => a.Key == key)
                                       .FirstOrDefault();

                // If workflow attribute doesn't exist, create it
                // ( should only happen first time a background check is processed for given workflow type)
                if (attribute == null)
                {
                    attribute = new Rock.Model.Attribute();
                    attribute.EntityTypeId = workflow.TypeId;
                    attribute.EntityTypeQualifierColumn = "WorkflowTypeId";
                    attribute.EntityTypeQualifierValue  = workflow.WorkflowTypeId.ToString();
                    attribute.Name        = key.SplitCase();
                    attribute.Key         = key;
                    attribute.FieldTypeId = fieldType.Id;
                    attributeService.Add(attribute);

                    if (qualifiers != null)
                    {
                        foreach (var keyVal in qualifiers)
                        {
                            var qualifier = new AttributeQualifier();
                            qualifier.Key   = keyVal.Key;
                            qualifier.Value = keyVal.Value;
                            attribute.AttributeQualifiers.Add(qualifier);
                        }
                    }

                    createdNewAttribute = true;
                }

                // Set the value for this attribute
                var attributeValue = new AttributeValue();
                attributeValue.Attribute = attribute;
                attributeValue.EntityId  = workflow.Id;
                attributeValue.Value     = value;
                new AttributeValueService(rockContext).Add(attributeValue);
            }

            return(createdNewAttribute);
        }
예제 #4
0
        /// <summary> Sets the values of a specified optional or non-standard qualifier of
        /// the element.
        ///
        /// The setQualifier method is used to set the values of vendor-
        /// specific qualifiers (which begin with "X-").
        ///
        /// </summary>
        /// <param name="name">          The name of the qualifier, case-sensitive.
        ///
        /// </param>
        /// <param name="values">        The values to set for the qualifier.
        /// </param>
        public virtual void setQualifier(string name, string[] values)
        {
            AttributeQualifier attrQualifier = new AttributeQualifier(name, values);

            SupportClass.PutElement(hashQualifier, name, attrQualifier);

            /*
             * This is the only method that modifies the schema element.
             * We need to reset the attribute value since it has changed.
             */
            Value = formatString();
        }
예제 #5
0
        /// <summary>
        /// Gets the attribute properties.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        public void GetAttributeProperties( Rock.Model.Attribute attribute )
        {
            if ( attribute != null )
            {
                attribute.Id = this.AttributeId ?? 0;
                attribute.Guid = this.AttributeGuid;
                attribute.Name = this.Name;
                attribute.Key = this.Key;
                attribute.IconCssClass = this.IconCssClass;
                attribute.Description = this.Description;
                attribute.FieldTypeId = this.FieldTypeId ?? 0;
                attribute.IsMultiValue = false;
                attribute.IsRequired = this.Required;
                attribute.IsGridColumn = this.ShowInGrid;
                attribute.AllowSearch = this.AllowSearch;

                attribute.Categories.Clear();
                new CategoryService( new RockContext() ).Queryable().Where( c => this.CategoryIds.Contains( c.Id ) ).ToList().ForEach( c =>
                    attribute.Categories.Add( c ) );

                attribute.AttributeQualifiers.Clear();
                foreach ( var qualifier in Qualifiers )
                {
                    AttributeQualifier attributeQualifier = new AttributeQualifier();
                    attributeQualifier.IsSystem = false;
                    attributeQualifier.Key = qualifier.Key;
                    attributeQualifier.Value = qualifier.Value.Value ?? string.Empty;
                    attribute.AttributeQualifiers.Add( attributeQualifier );
                }

                attribute.DefaultValue = this.DefaultValue;
            }
        }
예제 #6
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.Read("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)
                                               .Get(entityType.Id, "DefinedTypeId", definedType.Id.ToString())
                                               .ToList();

                        // Verify (and create if neccessary) the "Is Link" attribute
                        if (!attributes.Any(a => a.Key == "IsLink"))
                        {
                            var fieldType = FieldTypeCache.Read(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();

                                DefinedTypeCache.Flush(definedType.Id);
                                foreach (var dv in definedType.DefinedValues)
                                {
                                    DefinedValueCache.Flush(dv.Id);
                                }
                            }
                        }
                    }
                }

                BindGrid();

                pnlView.Visible = false;
                pnlEdit.Visible = true;
            }
        }
예제 #7
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            using (new UnitOfWorkScope())
            {
                var attributeService          = new AttributeService();
                var attributeQualifierService = new AttributeQualifierService();

                Rock.Model.Attribute attribute;

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

                if (attributeId == 0)
                {
                    attribute              = new Rock.Model.Attribute();
                    attribute.IsSystem     = false;
                    attribute.EntityTypeId = _entityTypeId;
                    attribute.EntityTypeQualifierColumn = _entityQualifierColumn;
                    attribute.EntityTypeQualifierValue  = _entityQualifierValue;
                    attributeService.Add(attribute, CurrentPersonId);
                }
                else
                {
                    AttributeCache.Flush(attributeId);
                    attribute = attributeService.Get(attributeId);
                }

                attribute.Key         = tbKey.Text;
                attribute.Name        = tbName.Text;
                attribute.Category    = tbCategory.Text;
                attribute.Description = tbDescription.Text;
                attribute.FieldTypeId = int.Parse(ddlFieldType.SelectedValue);

                var fieldType = FieldTypeCache.Read(attribute.FieldTypeId);

                foreach (var oldQualifier in attribute.AttributeQualifiers.ToList())
                {
                    attributeQualifierService.Delete(oldQualifier, CurrentPersonId);
                }

                attribute.AttributeQualifiers.Clear();

                List <Control> configControls = new List <Control>();
                foreach (var key in fieldType.Field.ConfigurationKeys())
                {
                    configControls.Add(phFieldTypeQualifiers.FindControl("configControl_" + key));
                }

                foreach (var configValue in fieldType.Field.ConfigurationValues(configControls))
                {
                    AttributeQualifier qualifier = new AttributeQualifier();
                    qualifier.IsSystem = false;
                    qualifier.Key      = configValue.Key;
                    qualifier.Value    = configValue.Value.Value ?? string.Empty;
                    attribute.AttributeQualifiers.Add(qualifier);
                }

                attribute.DefaultValue = tbDefaultValue.Text;
                attribute.IsMultiValue = cbMultiValue.Checked;
                attribute.IsRequired   = cbRequired.Checked;

                attributeService.Save(attribute, CurrentPersonId);
            }

            BindGrid();

            pnlDetails.Visible = false;
            pnlList.Visible    = true;
        }
예제 #8
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            using ( new UnitOfWorkScope() )
            {
                var attributeService = new AttributeService();
                var attributeQualifierService = new AttributeQualifierService();

                Rock.Model.Attribute attribute;

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

                if ( attributeId == 0 )
                {
                    attribute = new Rock.Model.Attribute();
                    attribute.IsSystem = false;
                    attribute.EntityTypeId = _entityTypeId;
                    attribute.EntityTypeQualifierColumn = _entityQualifierColumn;
                    attribute.EntityTypeQualifierValue = _entityQualifierValue;
                    attributeService.Add( attribute, CurrentPersonId );
                }
                else
                {
                    AttributeCache.Flush( attributeId );
                    attribute = attributeService.Get( attributeId );
                }

                attribute.Key = tbKey.Text;
                attribute.Name = tbName.Text;
                attribute.Category = tbCategory.Text;
                attribute.Description = tbDescription.Text;
                attribute.FieldTypeId = int.Parse( ddlFieldType.SelectedValue );

                var fieldType = FieldTypeCache.Read( attribute.FieldTypeId );

                foreach ( var oldQualifier in attribute.AttributeQualifiers.ToList() )
                {
                    attributeQualifierService.Delete( oldQualifier, CurrentPersonId );
                }

                attribute.AttributeQualifiers.Clear();

                List<Control> configControls = new List<Control>();
                foreach ( var key in fieldType.Field.ConfigurationKeys() )
                {
                    configControls.Add( phFieldTypeQualifiers.FindControl( "configControl_" + key ) );
                }

                foreach ( var configValue in fieldType.Field.ConfigurationValues( configControls ) )
                {
                    AttributeQualifier qualifier = new AttributeQualifier();
                    qualifier.IsSystem = false;
                    qualifier.Key = configValue.Key;
                    qualifier.Value = configValue.Value.Value ?? string.Empty;
                    attribute.AttributeQualifiers.Add( qualifier );
                }

                attribute.DefaultValue = tbDefaultValue.Text;
                attribute.IsMultiValue = cbMultiValue.Checked;
                attribute.IsRequired = cbRequired.Checked;

                attributeService.Save( attribute, CurrentPersonId );
            }

            BindGrid();

            pnlDetails.Visible = false;
            pnlList.Visible = true;
        }
예제 #9
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.Read( "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 )
                            .Get( entityType.Id, "DefinedTypeId", definedType.Id.ToString() )
                            .ToList();

                        // Verify (and create if neccessary) the "Is Link" attribute
                        if ( !attributes.Any( a => a.Key == "IsLink" ) )
                        {
                            var fieldType = FieldTypeCache.Read( 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();

                                DefinedTypeCache.Flush( definedType.Id );
                                foreach( var dv in definedType.DefinedValues )
                                {
                                    DefinedValueCache.Flush( dv.Id );
                                }
                            }
                        }

                    }
                }

                BindGrid();

                pnlView.Visible = false;
                pnlEdit.Visible = true;
            }
        }
예제 #10
0
 public virtual void VisitAttributeQualifier(AttributeQualifier attributeQualifier)
 {
     DefaultVisit(attributeQualifier);
 }
예제 #11
0
 /// <summary>
 /// Instantiates a new DTO object from the entity
 /// </summary>
 /// <param name="attributeQualifier"></param>
 public AttributeQualifierDto( AttributeQualifier attributeQualifier )
 {
     CopyFromModel( attributeQualifier );
 }
예제 #12
0
 /// <summary>
 /// To the model.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static AttributeQualifier ToModel( this AttributeQualifierDto value )
 {
     AttributeQualifier result = new AttributeQualifier();
     value.CopyToModel( result );
     return result;
 }