Пример #1
0
	public override void RenderControl(HtmlTextWriter writer)
	{
        string postId = Attributes["PostID"],
			postTitle = Attributes["PostTitle"];

		string postUrl = string.Empty;

		BXSearchQuery q = new BXSearchQuery();
		q.FieldsToSelect.Add(BXSearchField.Id);
		q.FieldsToSelect.Add(BXSearchField.ModuleId);
		q.FieldsToSelect.Add(BXSearchField.ItemId);
		q.FieldsToSelect.Add(BXSearchField.Body);
		q.FieldsToSelect.Add(BXSearchField.Title);
		q.FieldsToSelect.Add(BXSearchField.Param1);
		q.FieldsToSelect.Add(BXSearchField.Param2);

		BXSearchContentGroupFilter f = new BXSearchContentGroupFilter(BXFilterExpressionCombiningLogic.And);
		f.Add(new BXFormFilterItem("moduleId", "blog", BXSqlFilterOperators.Equal));
		f.Add(new BXFormFilterItem("itemId", "p" + postId, BXSqlFilterOperators.Equal));

		q.Filter = f;
		BXSearchResultCollection c = q.Execute();
		if (c.Count > 0)
			postUrl = c.Count > 0 && c[0].Urls.Length > 0 ? c[0].Urls[0] : string.Empty;       

		if(postUrl.Length > 0)
			writer.WriteLine(@"<a target=""_blank"" href=""" +  HttpUtility.HtmlAttributeEncode(postUrl) + @""">" + HttpUtility.HtmlEncode(postTitle) + @"</a>");
		else
			writer.WriteLine(HttpUtility.HtmlEncode(postTitle));
	}
    public string FindUrl(string moduleId, string Id, int ItemGroup)
    {
        BXSearchQuery q = new BXSearchQuery();
        q.FieldsToSelect.Add(BXSearchField.Id);
        q.FieldsToSelect.Add(BXSearchField.ModuleId);
        q.FieldsToSelect.Add(BXSearchField.ItemId);
        q.FieldsToSelect.Add(BXSearchField.Body);
        q.FieldsToSelect.Add(BXSearchField.Title);

        BXSite site = BXSite.Current;

        BXSearchContentGroupFilter filter = new BXSearchContentGroupFilter(BXFilterExpressionCombiningLogic.And);
        filter.Add(new BXFormFilterItem("moduleId", moduleId, BXSqlFilterOperators.Equal));
        filter.Add(new BXFormFilterItem("itemId", Id, BXSqlFilterOperators.Equal));
        if (ItemGroup != 0)
            filter.Add(new BXFormFilterItem("itemGroup", ItemGroup, BXSqlFilterOperators.Equal));
        q.Filter = filter;
        BXSearchResultCollection coll = q.Execute();
        if (coll.Count > 0)
        {
            BXSearchResult r = coll[0];
            if (r.Urls.Length > 0 && r.Urls[0].Length > 0)
                return r.Urls[0];
            else return string.Empty;
        }
        else
            return string.Empty;
    }
Пример #3
0
    protected List<BXSearchResult> SearchItems(string ModuleId, string searchQuery)
    {
        BXSearchQuery q = new BXSearchQuery();

        q.FieldsToSelect.Add(BXSearchField.Id);
        q.FieldsToSelect.Add(BXSearchField.ModuleId);
        q.FieldsToSelect.Add(BXSearchField.ItemId);
        q.FieldsToSelect.Add(BXSearchField.Body);
        q.FieldsToSelect.Add(BXSearchField.Title);
        q.PagingOptions = new BXPagingOptions(0, int.MaxValue);

        BXSite site = BXSite.Current;

        List<BXSearchResult> result = new List<BXSearchResult>();
        q.QueryExpression = new BXSearchExpression(site.LanguageId, searchQuery);
        q.Filter = new BXSearchContentGroupFilter(
            new BXFormFilter(new BXFormFilterItem("moduleId", ModuleId, BXSqlFilterOperators.Equal))
        );

        foreach (BXSearchResult r in q.Execute())
            result.Add(r);

        return result.Count > 0 ? result : null;
    }
Пример #4
0
		void IBlogRssComponentTagFilter.InitFilter(string siteId, string tags, List<int> ids, bool exclude, int categoryId)
		{
			if (ids.Count == 0 && !exclude)
			{
				empty = true;
				return;
			}

			q = new BXSearchQuery();
			q.SiteId = siteId;
			q.LanguageId = string.Empty;
			q.FieldsToSelect.Add(BXSearchField.ItemId);

			BXSearchContentGroupFilter f = new BXSearchContentGroupFilter(BXFilterExpressionCombiningLogic.And);
			
			//discrete timestep for count caching
			DateTime now = DateTime.Now;
			DateTime nowFloor = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute / 5 * 5, 0);
			f.Add(BXSearchContentFilter.IsActive(nowFloor));

			f.Add(new BXSearchContentFilterItem(BXSearchField.ModuleId, BXSqlFilterOperators.Equal, "blog"));


			List<int> ids2 = null;
			if (categoryId > 0)
			{
				ids2 = BXBlog.GetList(
					new BXFilter(new BXFilterItem(BXBlog.Fields.Categories.CategoryId, BXSqlFilterOperators.Equal, categoryId)),
					null,
					new BXSelect(BXBlog.Fields.Id),
					null
				)
				.ConvertAll(x => x.Id);
			}

			if (ids2 != null)
			{
				if (ids2.Count == 0)
					ids = ids2;									
				if (exclude)
				{
					if (ids.Count == 0)
						ids = ids2;
					else 
						ids = Bitrix.DataTypes.BXSet.Difference(ids2, ids);
				}
				else
					ids = Bitrix.DataTypes.BXSet.Intersection(ids2, ids);

				exclude = false;

				if (ids.Count == 0)
				{
					empty = true;
					return;
				}
			}


			if (!exclude || ids.Count > 0)
			{
				BXSearchContentFilter scf = new BXSearchContentFilterItem(BXSearchField.ItemGroup, Bitrix.DataLayer.BXSqlFilterOperators.In, ids.ConvertAll(x => x.ToString()).ToArray());
				if (exclude)
					scf = new BXSearchContentNotFilter(scf);
				f.Add(scf);
			}

			q.Filter = f;

			q.CalculateRelevance = false;
			q.AddTags(tags, ',');
            q.OrderBy = new BXSearchOrderBy(
                new BXSearchOrderByPair(BXSearchField.DateFrom, BXOrderByDirection.Desc),
                new BXSearchOrderByPair(BXSearchField.ContentDate, BXOrderByDirection.Desc),
                new BXSearchOrderByPair(BXSearchField.Id, BXOrderByDirection.Asc)
            ); 
		}
Пример #5
0
		void IBlogPostsComponentTagFilter.InitFilter(string siteId, string tags, string blogSlugs, List<int> ids, bool exclude, int categoryId)
		{
			if (ids != null && ids.Count == 0 && exclude)
				ids = null;

			if (ids != null && ids.Count == 0 && !exclude)
			{
				empty = true;
				return;
			}


			q = new BXSearchQuery();
			q.SiteId = siteId;
			q.LanguageId = "";
			q.FieldsToSelect.Add(BXSearchField.ItemId);

			BXSearchContentGroupFilter f = new BXSearchContentGroupFilter(BXFilterExpressionCombiningLogic.And);
			//discrete timestep for count caching
			DateTime now = DateTime.Now;
			//DateTime nowFloor = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute / 5 * 5, 0);
			f.Add(BXSearchContentFilter.IsActive(now.AddMinutes(5 - (now.Minute % 5)).AddSeconds(-now.Second).AddMilliseconds(-now.Millisecond)));
			f.Add(new BXSearchContentFilterItem(BXSearchField.ModuleId, BXSqlFilterOperators.Equal, "blog"));

			BXFilter bf = null;

			if (!string.IsNullOrEmpty(blogSlugs))
			{
				string[] blogSlugArr = blogSlugs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				if (blogSlugArr.Length > 0)
				{
					for (int i = 0; i < blogSlugArr.Length; i++)
						blogSlugArr[i] = blogSlugArr[i].Trim();

					bf = new BXFilter(new BXFilterItem(BXBlog.Fields.Slug, BXSqlFilterOperators.In, blogSlugArr));
				}
			}

			if (categoryId > 0)
			{
				if (bf == null)
					bf = new BXFilter();
				bf.Add(new BXFilterItem(BXBlog.Fields.Categories.CategoryId, BXSqlFilterOperators.Equal, categoryId));
			}

			List<int> blogIdLst = null;
			if (bf != null)
			{
				BXBlogCollection blogs = BXBlog.GetList(
					bf,
					null,
					new BXSelect(BXSelectFieldPreparationMode.Normal, BXBlog.Fields.Id),
					null
				);
				blogIdLst = blogs.ConvertAll(x => x.Id);
			}

			if (blogIdLst != null)
			{
				if (ids != null)
				{
					if (exclude)
					{
						ids = Bitrix.DataTypes.BXSet.Difference(blogIdLst, ids);
						exclude = false;
					}
					else
					{
						ids = Bitrix.DataTypes.BXSet.Intersection(blogIdLst, ids);
					}
				}
				else
				{
					ids = blogIdLst;
					exclude = false;
				}				
			}			
			
			if (ids != null && ids.Count == 0 && !exclude)
			{
				empty = true;
				return;
			}

			if (ids != null)
			{
				BXSearchContentFilter scf = new BXSearchContentFilterItem(BXSearchField.ItemGroup, Bitrix.DataLayer.BXSqlFilterOperators.In, ids.ConvertAll(x => x.ToString()).ToArray());
				if (exclude)
					scf = new BXSearchContentNotFilter(scf);
				f.Add(scf);
			}
			

			q.Filter = f;
			q.CalculateRelevance = false;
			q.AddTags(tags, ',');

			q.OrderBy = new BXSearchOrderBy(
				new BXSearchOrderByPair(BXSearchField.DateFrom, BXOrderByDirection.Desc),
				new BXSearchOrderByPair(BXSearchField.ContentDate, BXOrderByDirection.Desc),
				new BXSearchOrderByPair(BXSearchField.Id, BXOrderByDirection.Asc)
			 );
		}