Episerver Community Poll and Sort by Latest Activity

I am trying to request the Episerver community to get pages approved within a date range (for example, within the last 2 days), ordered by the last stream activity (asset is the last stream approved response, or the date that the stream was created if approved responses are 0).

I've tried using the GetTopics () method and besides not being able to pass the date range, LastReply includes responses that are still in the moderation queue, so sorting doesn't work correctly.

I've also tried using the Query API, but I'm not sure if it is possible to build such a complex query. Is there a way to include AND / OR in the sort and also make sure LastReply is approved? As far as I know:

        var topicQuery = new TopicQuery
        {
            Created = new DateTimeCriterion(),
            Status = new EntityStatusCriterion
            {
                Operator = FlagsOperator.Equal,
                Value = EntityStatus.Approved
            },
            LastReply = new ReplyCriterion{
                Status = new EntityStatusCriterion(),
                Created = new DateTimeCriterion()
            }
        };

        //filter by days
        if (withinDays > 0)
        {
            topicQuery.Created.Operator = ComparisonOperator.GreaterThan | ComparisonOperator.Equals;
            topicQuery.Created.Value = DateTime.Now.AddDays(-withinDays);
        }

        //sort, this is incorrect, I am trying to sort by last approved reply date or created date if not available
        //Last reply is sometimes not approved and it needs to be...
        topicQuery.OrderBy.Add(new CriterionSortOrder(topicQuery.Created, SortingDirection.Descending));
        topicQuery.OrderBy.Add(new CriterionSortOrder(topicQuery.LastReply.Created, SortingDirection.Descending));

        var result = QueryHandler.GetQueryResult<Topic, MessageCollection>(topicQuery, page, pageSize);

      

+3


source to share





All Articles