21489 Posts in 5783 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 845 Views |
-
Reversing RSS Feed/ DataObjectSet

15 June 2010 at 10:41am Last edited: 15 June 2010 10:42am
Morning
I've put together some code to pull an RSS list of events through so we can display them on our website. I have two issues:
1.) The events are sorted by descending date for the RSS field which means the most far away events are displayed at the top of the list.
2.) There are 74 events and I only want to show 5.So I want to display the next 5 upcoming events. Here is my code:
Page.php
class Page_Controller extends ContentController {
function RestfulLinks($url, $delimiter, $interval){$rssfeed = new RestfulService($url,$interval);
$conn = $rssfeed->request('')->getBody();
$result = $rssfeed->getValues($conn, $delimiter);return $result;
}
}HomePage.php
class HomePage_Controller extends Page_Controller {
function EventList($num=5) {
$RSSFeed = RestfulLinks("http://itson.co.nz/feeds/all/", "entry", 3600);
$EventList = new DataObjectSet();
$num_items=0;
foreach($RSSFeed as $EventItem){
$extrainfo = array(
'EventTitle' => $EventItem->title,
);
$EventList -> push(new ArrayData($extrainfo));
if (++$num_items == $num) break;
}
return $EventList;
}
}This returns the following:
* South Island U15 & U17 Badminton Championships (Monday 12th–Saturday 17th July 2010)
* Nelson Winter Music Festival - The Funky Monkeys (Monday 12th July 2010)
* 'The Ballad of Robin Hood'- Children's Theatre (Monday 12th–Tuesday 13th July 2010)
* Nelson Winter Music Festival - Josef Spacek & Michael Houstoun (Sunday 11th July 2010)
* Nelson Winter Music Festival - Kemp English (Sunday 11th July 2010)What I'd like to return is the following:
* Nelson Farmers' Market (Wednesday 20th January 2010–Monday 31st January 2011)
* Shelter from the Storm (Saturday 24th April–Wednesday 30th June 2010)
* 'Mille-Fleurs' Art Exhibition at The Suter Art Gallery (Saturday 8th May–Sunday 20th June 2010)
* YMCA (Thursday 13th May–Saturday 31st July 2010)
* TREATY2U (Friday 14th May–Sunday 1st August 2010)Does anyone have a good idea on how to achieve this? I can think of some pretty ugly methods but I'm hoping that the order of $RSSFeed can be easily reversed.
Thanks in advance
Tama -
Re: Reversing RSS Feed/ DataObjectSet

15 June 2010 at 11:16am
Have you tried using the sort() method on the set - http://api.silverstripe.org/2.4/sapphire/model/DataObjectSet.html#methodsort
-
Re: Reversing RSS Feed/ DataObjectSet

23 June 2010 at 10:40am
Hi Will, thanks for that - I didn't notice the sort method. Will give it a crack.
-
Re: Reversing RSS Feed/ DataObjectSet

14 July 2010 at 10:58pm
I would like to know the outcome of this. Did the sort method work for you?
-
Re: Reversing RSS Feed/ DataObjectSet

15 July 2010 at 9:12am
Hi David - I replaced "return $EventList" with the following code:
// Reverse order so near events show first
$EventList -> sort("EndDate", "ASC");
// Limit the number of events returned
return $EventList -> getRange(0, $num );
| 845 Views | ||
|
Page:
1
|
Go to Top |



