4
votes

We are looking at getting RSS of the content on our Orchard site and then parsing it using C# to stick it into our own database. To do this, we need the RSS to grab each field of our custom type. Right now, when I get the RSS of a Projection, we get the default elements of title, description, etc, but not the fields of the type.

On the other hand, using the Import/Export module, I am able to get all the fields of a custom type, but the module does not support querying (which is why we are using projections).

Is there any way to get an RSS feed of all the fields of a type, but using a query/projection?

1

1 Answers

5
votes

There is no automatic way to do this, but you can write your own module that does this.

What you need to do is to add a class that implements Orchard.Core.Feeds.IFeedItemBuilder interface. The interface itself has only one method you need to implement - void Populate(FeedContext context).

Here's the code snippet of how you might implement this method:

public void Populate(FeedContext context) 
{
    context.Response.Contextualize(
      c => {
        foreach (var feedItem in context.Response.Items.OfType<FeedItem<ContentItem>>()) 
        {
          var contentItem = feedItem.Item;
          foreach (var part in contentItem.Parts)
          {
            // extract data you're interested in from parts
            foreach (var field in part.Fields)
            {
              // extract data you're interested in from fields
              feedItem.Element.SetElementValue("description", "Text to output to RSS");
            }
          }
        }
      });
}

context.Response.Items holds all items that will be outputted to RSS. The tricky part here is to know which data you want to output to RSS since there are many different parts with many different fields. And they all have different property names you would like to output to RSS.

Therefore, my suggestion is to test if contentItem in the example above is of your custom type. If it is, cast it and use your custom field names to fill the description of that feedItem.