Пример #1
0
        /// <summary>
        /// Formats the search result.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="displayOptions">The display options.</param>
        /// <param name="mergeFields"></param>
        /// <returns></returns>
        public override FormattedSearchResult FormatSearchResult(Person person, Dictionary <string, object> displayOptions = null, Dictionary <string, object> mergeFields = null)
        {
            string url = string.Empty;
            bool   isSecurityDisabled = false;

            if (displayOptions != null)
            {
                if (displayOptions.ContainsKey("ChannelItem-IsSecurityDisabled"))
                {
                    isSecurityDisabled = displayOptions["ChannelItem-IsSecurityDisabled"].ToString().AsBoolean();
                }
            }

            if (!isSecurityDisabled)
            {
                // check security
                var contentChannelItem = new ContentChannelItemService(new RockContext()).Get((int)this.Id);
                var isAllowedView      = false;

                if (contentChannelItem != null)
                {
                    isAllowedView = contentChannelItem.IsAuthorized("View", person);
                }

                if (!isAllowedView)
                {
                    return(new FormattedSearchResult()
                    {
                        IsViewAllowed = false
                    });
                }
            }

            // if url was not passed in use default from content channel
            if (displayOptions == null || !displayOptions.ContainsKey("ChannelItem-Url"))
            {
                var channel = new ContentChannelService(new RockContext()).Get(this.ContentChannelId);
                if (channel != null)
                {
                    url = channel.ItemUrl;

                    if (url.IsNotNullOrWhiteSpace())
                    {
                        if (mergeFields == null)
                        {
                            mergeFields = new Dictionary <string, object>();
                        }

                        mergeFields.AddOrReplace("Id", this.Id);
                        mergeFields.AddOrReplace("Title", this.Title);
                        mergeFields.AddOrReplace("ContentChannelId", this.ContentChannelId);
                        mergeFields.AddOrReplace("Slug", this.PrimarySlug);

                        if (displayOptions == null)
                        {
                            displayOptions = new Dictionary <string, object>();
                        }
                        displayOptions["ChannelItem-Url"] = url.ResolveMergeFields(mergeFields);
                    }
                }
            }

            return(base.FormatSearchResult(person, displayOptions));
        }
Пример #2
0
        /// <summary>
        /// Formats the search result.
        /// </summary>
        /// <param name="person"></param>
        /// <param name="displayOptions"></param>
        /// <returns></returns>
        public override FormattedSearchResult FormatSearchResult( Person person, Dictionary<string, object> displayOptions = null )
        {
            bool showSummary = true;
            string url = string.Empty;
            bool isSecurityDisabled = false;

            if ( displayOptions != null )
            {
                if ( displayOptions.ContainsKey( "ChannelItem.ShowSummary" ) )
                {
                    showSummary = displayOptions["ChannelItem.ShowSummary"].ToString().AsBoolean();
                }
                if ( displayOptions.ContainsKey( "ChannelItem.Url" ) )
                {
                    url = displayOptions["ChannelItem.Url"].ToString();
                }
                if ( displayOptions.ContainsKey( "ChannelItem.IsSecurityDisabled" ) )
                {
                    isSecurityDisabled = displayOptions["ChannelItem.IsSecurityDisabled"].ToString().AsBoolean();
                }
            }

            if ( !isSecurityDisabled )
            {
                // check security
                var contentChannelItem = new ContentChannelItemService( new RockContext() ).Get( (int)this.Id );
                var isAllowedView = false;

                if (contentChannelItem != null )
                {
                    isAllowedView = contentChannelItem.IsAuthorized( "View", person );
                }

                if ( !isAllowedView )
                {
                    return new FormattedSearchResult() { IsViewAllowed = false };
                }
            }

            // if url was not passed in use default from content channel
            if ( string.IsNullOrWhiteSpace( url ) )
            {
                var channel = new ContentChannelService( new RockContext() ).Get( this.ContentChannelId );
                url = channel.ItemUrl;
            }

            var mergeFields = new Dictionary<string, object>();
            mergeFields.Add( "Id", this.Id );
            mergeFields.Add( "Title", this.Title );
            mergeFields.Add( "ContentChannelId", this.ContentChannelId );

            var summary = this["Summary"] ?? "" + this["summaryText"] ?? "";

            return new FormattedSearchResult() { IsViewAllowed = true, FormattedResult = $@"
                            <div class='row model-cannavigate' data-href='{url.ResolveMergeFields( mergeFields )}'>
                                <div class='col-sm-1 text-center'>
                                    <i class='{this.IconCssClass} fa-2x'></i>
                                </div>
                                <div class='col-sm-4'>
                                    {this.Title} <small>({this.ContentChannel})</small>
                                </div>
                                <div class='col-sm-7'>
                                    {(showSummary ? summary : "")}
                                </div>
                            </div>" };
        }