public static HabSearchAnalytics GetHabSearchAnalyticsSettings()
        {
            try
            {
                var siteContext = new SiteContext();
                var siteDefinition = siteContext.GetSiteDefinition(Sitecore.Context.Item);

                if (siteDefinition?.Item == null || !siteDefinition.Item.IsDerived(Templates.HabSearchAnalyticSettings.ID))
                {
                    return null;
                }

                var habSearchAnalytics = new HabSearchAnalytics();

                CheckboxField cbIsAnalyticsEnabled = siteDefinition.Item.Fields[Templates.HabSearchAnalyticSettings.Fields.EnableHabSeachAnalytics];

                if (cbIsAnalyticsEnabled != null && cbIsAnalyticsEnabled.Checked)
                {
                    habSearchAnalytics.IsAnalyticsEnabled = true;
                    habSearchAnalytics.SearchTermsRootFolderPath = siteDefinition.Item[Templates.HabSearchAnalyticSettings.Fields.SearchTermsRootFolder];
                }

                return habSearchAnalytics;
            }
            catch (Exception ex)
            {
                Log.Error("Error while getting HabSearch Analytics settings", ex, typeof(HabSearchAnalyticsRepository));
            }

            return null;
        }
예제 #2
0
    public static IEnumerable<Language> GetSupportedLanguages()
    {
      var languages = GetAll();
      var siteContext = new SiteContext();
      var siteDefinition = siteContext.GetSiteDefinition(Sitecore.Context.Item);
      
      if (siteDefinition?.Item == null || !siteDefinition.Item.IsDerived(Feature.Language.Templates.LanguageSettings.ID))
      {
        return languages;
      }

      var supportedLanguagesField = new MultilistField(siteDefinition.Item.Fields[Feature.Language.Templates.LanguageSettings.Fields.SupportedLanguages]);
      if (supportedLanguagesField.Count == 0)
      {
        return languages;
      }

      var supportedLanguages = supportedLanguagesField.GetItems();

      languages = languages.Where(language => supportedLanguages.Any(item => item.Name.Equals(language.Name)));

      return languages;
    }