Hello,
I've created a view that use Year-Month as an argument to display a list of books released on this Year-Month.
For instance, when I type:
/myreleases/2009-10, it displays releases for October, 2009

When no argument is supplied, it currently uses "now" as default argument.
So if "now" is October, 2009,
/myreleases displays releases for October, 2009.

The problem is that some months won't have any release, and /myreleases might display an empty view, so using "now" as default argument is not acceptable.
What I would like is that when there's no result for current month, it supplies the most recent month having releases as the default argument.
For instance, if "now" is December 2009 and if neither December 2009 nor November 2009 have any release, /myreleases should display October 2009's results instead of an empty view.
Is there a way to do this from views's interface or do I have to write some code?
I would like to avoid any database extra query...

Comments

arlinsandbulte’s picture

I think you will need to write some custom code for this functionality.
The best place to do this would be in your view's argument settings.
Under "Action to take if argument is not present," select "provide default argument" and then choose PHP code for default argument type.
Then, you can enter in some custom PHP code to determine which month is the most recent having a release and return that date as the default argument.
Unfortunately, this is going to require a database query.

Also, I don't know know PHP, so I can't help you write the code... I can only tell you what the code should do.
Hopefully this provides a start for you.

anrikun’s picture

Ok. It seems I'll need to write an additional query then.
Thanks for your help arlinsandbulte.

arlinsandbulte’s picture

Status: Active » Fixed

Assuming taht anrikun figured this out....

anrikun’s picture

Yes I have managed to create a custom argument plugin (extending the default date_api plugin) to achieve that.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.