Skip to content

Commit

Permalink
- Updated HighlightLabelBadge to be obsolete in 1.14.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
cabal95 committed Jun 20, 2022
1 parent 89ca4df commit 0f9be8d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
38 changes: 17 additions & 21 deletions Rock/Badge/Component/Campus.cs
@@ -1,4 +1,4 @@
// <copyright>
// <copyright>
// Copyright by the Spark Development Network
//
// Licensed under the Rock Community License (the "License");
Expand All @@ -14,14 +14,14 @@
// limitations under the License.
// </copyright>
//
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;

using Rock.Data;
using Rock.Model;
using Rock.Web.Cache;
using Rock.Web.UI.Controls;

namespace Rock.Badge.Component
{
Expand All @@ -32,7 +32,7 @@ namespace Rock.Badge.Component
[Export( typeof( BadgeComponent ) )]
[ExportMetadata( "ComponentName", "Campus" )]
[Rock.SystemGuid.EntityTypeGuid( "D4B2BA9B-4F2C-47CB-A5BB-F3FF53A68F39")]
public class Campus : HighlightLabelBadge
public class Campus : BadgeComponent
{
/// <summary>
/// Determines of this badge component applies to the given type
Expand All @@ -44,38 +44,34 @@ public override bool DoesApplyToEntityType( string type )
return type.IsNullOrWhiteSpace() || typeof( Person ).FullName == type;
}

/// <summary>
/// Gets the Entity's Campus badge label even if the campus is inactive.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns></returns>
public override HighlightLabel GetLabel( IEntity entity )
/// <inheritdoc/>
public override void Render( BadgeCache badge, IEntity entity, TextWriter writer )
{
// This badge is only setup to work with a person
var person = entity as Person;
// This badge is only setup to work with a person.
if ( !( entity is Person person ) )
{
return;
}

// If the entity is not a person or there is only one campus, then don't display a badge
if ( person == null || CampusCache.All().Count <= 1 )
// If there is only one campus, then don't display a badge.
if ( CampusCache.All().Count <= 1 )
{
return null;
return;
}

var campusNames = person.GetCampusIds()
.Select( id => CampusCache.Get( id )?.Name )
.Where( name => !name.IsNullOrWhiteSpace() )
.OrderBy( name => name )
.Select( name => name.EncodeHtml() )
.ToList();

if ( !campusNames.Any() )
{
return null;
return;
}

return new HighlightLabel
{
LabelType = LabelType.Campus,
Text = campusNames.AsDelimited( ", " )
};
writer.Write( $"<span class=\"label label-campus\">{campusNames.AsDelimited( "," )}</span>" );
}
}
}
2 changes: 2 additions & 0 deletions Rock/Badge/HighlightLabelBadge.cs
Expand Up @@ -27,6 +27,8 @@ namespace Rock.Badge
/// <summary>
/// Base class for person profile icon badges
/// </summary>
[RockObsolete( "1.14" )]
[Obsolete( "HighlightLabelBadge depends on Webforms, use BadgeComponent instead and render the HTML." )]
public abstract class HighlightLabelBadge : BadgeComponent
{
/// <summary>
Expand Down

0 comments on commit 0f9be8d

Please sign in to comment.