Ejemplo n.º 1
0
        /// <summary>
        /// Gets the search items for the given module.
        /// </summary>
        /// <param name="modInfo">The module for which to get search items.</param>
        /// <returns>A new <see cref="SearchItemInfoCollection"/> for the items in the module</returns>
        public SearchItemInfoCollection GetSearchItems(ModuleInfo modInfo)
        {
            if (modInfo == null)
            {
                throw new ArgumentNullException("modInfo");
            }

            var detailDisplayTabId    = ModuleSettings.DetailsDisplayTabId.GetValueAsInt32For(Utility.DesktopModuleName, modInfo, ModuleSettings.DetailsDisplayTabId.DefaultValue);
            var detailDisplayModuleId = ModuleSettings.DetailsDisplayModuleId.GetValueAsInt32For(Utility.DesktopModuleName, modInfo, ModuleSettings.DetailsDisplayModuleId.DefaultValue);

            if ((detailDisplayTabId != null && detailDisplayTabId != modInfo.TabID) || detailDisplayModuleId == null)
            {
                // If it's set to display on another page, just show it in this module; there's no way to link a search result to another page
                detailDisplayModuleId = modInfo.ModuleID;
            }

            var isListingDisplay = ModuleSettings.DisplayType.GetValueAsStringFor(Utility.DesktopModuleName, modInfo, ModuleSettings.DisplayType.DefaultValue).Equals("LIST", StringComparison.OrdinalIgnoreCase);
            var dateRange        = isListingDisplay
                                ? ModuleSettings.GetDateRangeFor(new FakeModuleControlBase(Utility.DesktopModuleName, modInfo))
                                : new DateRange(DateRangeBound.CreateUnboundedBound(), DateRangeBound.CreateUnboundedBound());
            var featuredOnly           = ModuleSettings.FeaturedOnly.GetValueAsBooleanFor(Utility.DesktopModuleName, modInfo, ModuleSettings.FeaturedOnly.DefaultValue);
            var hideFullEvents         = ModuleSettings.HideFullEvents.GetValueAsBooleanFor(Utility.DesktopModuleName, modInfo, ModuleSettings.HideFullEvents.DefaultValue);
            var categoriesSettingValue = ModuleSettings.Categories.GetValueAsStringFor(Utility.DesktopModuleName, modInfo, ModuleSettings.Categories.DefaultValue);
            var categoryIds            = string.IsNullOrEmpty(categoriesSettingValue)
                                  ? Enumerable.Empty <int>()
                                  : categoriesSettingValue.Split(',').Select(id => int.Parse(id, CultureInfo.InvariantCulture));

            var querystringParameters = new[] { "modId=" + detailDisplayModuleId.Value.ToString(CultureInfo.InvariantCulture), "key=EventDetail" };

            var events = EventCollection.Load(
                modInfo.PortalID,
                dateRange.GetStartDateUtc(),
                dateRange.GetEndDateUtc(),
                isListingDisplay,
                featuredOnly,
                hideFullEvents,
                null,
                categoryIds);

            return(new SearchItemInfoCollection(events.Cast <Event>()
                                                .Select(e => new SearchItemInfo(
                                                            e.Title,
                                                            e.Overview,
                                                            e.CreatedBy,
                                                            e.RevisionDate,
                                                            modInfo.ModuleID,
                                                            e.Id.ToString(CultureInfo.InvariantCulture),
                                                            e.Title + ' ' + e.Overview + ' ' + e.Description,
                                                            string.Join("&", Utility.GetEventParameters(e, querystringParameters).ToArray())))
                                                .ToArray()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the value of the property with the given <paramref name="propertyName"/>, or <see cref="string.Empty"/> if a property with that name does not exist on this object or is <c>null</c>.
        /// </summary>
        /// <remarks>
        /// To avoid conflicts with template syntax, avoid using the following symbols in the property name
        /// <list type="bullet">
        ///     <item><description>:</description></item>
        ///     <item><description>%</description></item>
        ///     <item><description>$</description></item>
        ///     <item><description>#</description></item>
        ///     <item><description>&gt;</description></item>
        ///     <item><description>&lt;</description></item>
        ///     <item><description>"</description></item>
        ///     <item><description>'</description></item>
        /// </list>
        /// </remarks>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="format">
        /// A numeric or DateTime format string, or one of the string formatting options accepted by <see cref="TemplateEngine.FormatString"/>,
        /// or <c>null</c> or <see cref="string.Empty"/> to apply the default format.
        /// </param>
        /// <returns>The string representation of the value of this instance as specified by <paramref name="format"/>.</returns>
        public override string GetValue(string propertyName, string format)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            switch (propertyName.ToUpperInvariant())
            {
            case "MULTIPLE CATEGORIES":
            case "MULTIPLECATEGORIES":
                IEnumerable <Category> categories = CategoryCollection.Load(this.PortalId);
                var moduleCategoryIds             = ModuleSettings.GetCategoriesFor(new FakeModuleControlBase(Utility.DesktopModuleName, this.ModuleContext.Configuration));
                if (moduleCategoryIds.Any())
                {
                    var categoryIdsWithAncestor = Utility.AddAncestorIds(moduleCategoryIds.ToArray(), categories.ToArray(), true);
                    categories = categories.Where(category => categoryIdsWithAncestor.Contains(category.Id));
                }

                return((categories.Count() > 1).ToString(CultureInfo.InvariantCulture));
            }

            return(base.GetValue(propertyName, format));
        }