Reputation: 477
We have a Drupal 7 site producing an rss feed consumed by Ellucian Portal (built on top of Microsoft SharePoint). There is a "web part" (I think that's SharePoint's term) which lists the 5 item titles from the feed in reverse order. Our feed comprises 10 items which means that SharePoint is listing titles 10 through 6 instead of 1 - 5. Ugh. I don't know if the order reversal is a SharePoint thing or an Ellucian thing.
We're generating the view in the standard Drupal way with the View module.
I can think of 4 types of solutions to try.
Change the sort order setting in the Views UI. That won't work. If we have 20 nodes to pull from, we'll be feeding items 20 through 11 instead of 10 through 1. The Portal will nicely list items 11 through 15, but that's still not what we want.
Limit our feed to only 5 items. Then at least Ellucian/SharePoint will list the right items. That'll work but is sub-optimal: this is a feed of upcoming events and it'd be better to have the the nearest event first.
Convince Ellucian Portal not to reverse the order of the feed. This would certainly be the best solution if it is doable. The Keeper of the Portal has not found a way to do this. I don't know whether that's the incompetence of the Keeper, of Ellucian, or of SharePoint.
Resort the feed in our Drupal site after Views picks out 10 items for the feed. The closest to a promising place to do this I've found is to override the Views module's template_preprocess_views_view_rss() function. By then, the items part of the the xml has been generated. I'd have to parse it into individual items to resort. Doable but ugly. It'd be nice to find someplace I can simply apply reverse_array().
Any ideas? SharePoint or Portal experts might help me help the Keeper of the Portal. Or Drupal experts might help me find a better place to resort the feed. Or whatever else you have.
Upvotes: 0
Views: 108
Reputation: 477
MilanG provides the right answer, but it didn't solve the underlying problem. It turns out that SharePoint (or Ellucian Portal) is sorting the feeds based on <pubDate>, not on <item> order. I could arrange the items in any order I like and it makes no difference what shows up in Portal. I seem to have 2 options at this point--not counting optiojn (3) above in my question.
Massage the feed (using MilanG's answer) to give the wrong <pubDate> but at least force the correct order.
See if I can get access to the Portal css and fix it with flex-direction.
Two lessons to learn from this:
a. Whenever you get Microsoft involved, ugliness ensues.
b. Mandeville's Law: Anything software [in this case, SharePoint] does for you is something it does to you.
Upvotes: 0
Reputation: 7114
Try using hook_views_post_exexute()
hook function to re-order results.
Basically you'll have to create your module (if you don't have one already) and add function to it like:
function MY_MODULE_views_post_execute(&$view) {
if ($view->name == 'MY_VIEW') {
// re-order $view->result here
}
}
Your function will be called after view (query) is executed and you can alter results here, like re-ordering them.
Of course you'll replace "MY_MODULE" and "MY_VIEW" with machine names of your module and view...
https://api.drupal.org/api/views/views.api.php/function/hook_views_post_execute/7.x-3.x
Upvotes: 1