Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

How to Use RSSFeed with DataObjectSet that does NOT consist of Pages?


Reply


5 Posts   1574 Views

Avatar
Garrett

Community Member, 245 Posts

25 November 2009 at 4:45am

Hi,

I've got some data objects in my CMS, that is, tables constructed using the DataObjectManager rather than pages, but I'd still like to use the RSSFeed class with them so that people can subscribe to these particular items. I thought all I had to do with RSSFeed was to pass in any DataObjectSet to make this work, i.e.: it didn't have to be Page objects. And I still think this is *theoretically* true-- the problem is that the RSSFeed constructor appears to be looking for specific fields, eg. "Title" and "Content".

What if the fields in the table whose rows I am retrieving in the DataObjectSet I'm passing in do not match these names? Eg., "AnalystTitle", and "AnalystDescription"? And the main problem is the Link() issue. This DataObject does not HAVE a SilverStripe Link value-- it has a link to a FILE, a PDF, called "AnalystURL".

How can I make this work? Seems like it should be totally possible, at least by cloning the RSSFeed class and adding the ability to pass in custom-named fields to be retrieved, but I tried this and it didn't work. Here's my RSSFeed call in my summary page where the RSS link is:

   function init() {
      RSSFeed::linkToFeed($this->Link() . "rss");   
      parent::init();
   }

   function rss() {
      $rss = new RSSFeed(Page_Controller::Analysts(), Page_Controller::Analysts()->AnalystURL, "REDACTED > ".$this->Title);
      $rss->outputToBrowser();
   }

...where Analysts() returns a DataObjectSet containing all the fields I mentioned above.

Then, again theoretically, in my RSSFeedDOM class, the constructor would look something like this:

function __construct(DataObjectSet $entries, $link, $title,
                                  $description = null, $titleField = "AnalystTitle",
                                  $descriptionField = "AnalystDescription", $authorField = null,
                                  $lastModified = null, $etag = null) {

Can anyone help me get this working? I think adding this functionality would be a huge improvement to SilverStripe. Why can I only subscribe to Pages? I just want to get the Title and associated file link from an alternate object. I should be able to.

Thanks in advance,
Garrett

Avatar
Willr

Forum Moderator, 5513 Posts

25 November 2009 at 2:36pm

well the forum module uses RSS feed of non page objects (Posts) same with Page Comments. How these ones work is just overriding the Link() function to generate the URL for the link. This doesn't *have* to be a link to a page.

In your case the link would be the AnalystURL so try adding this to your DataObject

Analyst.php

function Link() {
return $this->AnalystURL;
}

Avatar
Garrett

Community Member, 245 Posts

26 November 2009 at 7:50am

Hmmm, yes, this does seem like it would work. Maybe I'm doing something else wrong? This is my AnalystHolder_Controller:

class AnalystHolder_Controller extends Page_Controller {

   function init() {
      RSSFeed::linkToFeed(Analyst_Controller::Link() . "rss");   
      parent::init();
   }

   function rss() {
      $rss = new RSSFeed(Page_Controller::Analysts(), Analyst_Controller::Link(), "Terra Technology > ".$this->Title);
      $rss->outputToBrowser();
   }
   
}

And I placed the Link() function you provided in Analyst.php/Analyst_Controller class. Seems that the linkToFeed() function is sort of irrelevant in this case, but that's a moot point as the feed is still empty and is not populating these URLs. And isn't the $titleField in the RSSFeed constructor also an issue here? The Analyst object doesn't Have a Title field. It's called AnalystTitle. I tried hard-coding that in the constructor but still no dice! Any ideas, @willr?

Thanks as always,
Garrett

Avatar
Garrett

Community Member, 245 Posts

23 December 2009 at 5:44am

I have to wake this thread up again, as I never got this working and now I'm in the same situation on a different project. If I use a DataObjectSet OTHER THAN $this->Children(), for example something in Page_Controller, which is a custom DB::query(), if I want to put an RSS feed for the result of this query, what do I put for the second parameter when declaring the new RSSFeed() on the page init()? $this-> Link() won't work. I need the links from the pages/objects in the result set. How?

function init() {
      RSSFeed::linkToFeed($this->Link() . "rss");   
      parent::init();
   }

   function rss() {
      $rss = new RSSFeed(Page_Controller::MostRecent(10), WHAT GOES HERE, "Most Recent News");
      $rss->outputToBrowser();
   }

Thanks,
Garrett

Avatar
Willr

Forum Moderator, 5513 Posts

23 December 2009 at 9:00am

If you want to know 'What goes in position X' use the API documentation. It provides alot more information - http://api.silverstripe.org/sapphire/integration/RSSFeed.html#__construct - Through that you can see the 2nd parameter is a string to the link of the actual feed. So you should normally just need to use $this->Link(). Sorry my first post is a bit misleading - I was thinking the links to the individual entries.