Comparing/combining PageList objects for negative filtering
Permalink
Hello all
I'm trying to create a page which has a featured news article at the top, and paginated non-featured articles beneath. This is actually pretty difficult if the interface is to avoid repeating the featured article in the non-featured area, and if the client isn't going to have to manually check that only one article is set as is_featured.
What I'd like to do is compare two PageList objects to get a filtered set for the non-featured list of articles. In other words, the first PageList object will filter out just 1 featured article, while the second will filter out all news articles. If I can compare those two PageList object negatively, so the featured article is removed from the second PageList, then I'll have a properly filtered list of non-featured articles.
Unfortunately the PageList model doesn't seem to allow filtering negatively by individual pages (e.g. pagelist->removePageID() or similar) so this isn't a trivial thing to do.
I might be overegging it a bit but I don't want the client to have to keep track of which articles have the featured attribute set and which don't (otherwise we risk them forgetting to unset the attribute on an old featured article, thus hiding them from the non-featured PageList).
Any thoughts?
I'm trying to create a page which has a featured news article at the top, and paginated non-featured articles beneath. This is actually pretty difficult if the interface is to avoid repeating the featured article in the non-featured area, and if the client isn't going to have to manually check that only one article is set as is_featured.
What I'd like to do is compare two PageList objects to get a filtered set for the non-featured list of articles. In other words, the first PageList object will filter out just 1 featured article, while the second will filter out all news articles. If I can compare those two PageList object negatively, so the featured article is removed from the second PageList, then I'll have a properly filtered list of non-featured articles.
Unfortunately the PageList model doesn't seem to allow filtering negatively by individual pages (e.g. pagelist->removePageID() or similar) so this isn't a trivial thing to do.
I might be overegging it a bit but I don't want the client to have to keep track of which articles have the featured attribute set and which don't (otherwise we risk them forgetting to unset the attribute on an old featured article, thus hiding them from the non-featured PageList).
Any thoughts?
E.g.,
Of course you'll need to supply your own test for isFeatured, presumably with some attribute check. You'll want to check for the empty case too (if nothing has been featured, or there is only one article).
You can also do this with filter, find, reject, difference, etc. depending on your particular requirements. For example this approach could yield two articles in the "featured" group, and my pseudo-code above only selects the first one. So you might need a different approach based on the user interface.