Is there a way to show dates in the past? I would like to show the availability calendar for a full year, January to December, even if some months have already passed. And I would like to be able to edit past dates. Is that possible? How would I go about doing it?
Thanks!

CommentFileSizeAuthor
#5 availability_calendars-1490928-5.patch3.55 KBJelle_S
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fietserwin’s picture

You are asking various things:

1) Show past dates
This existed in the non-field based version, so I would have to reintroduce that setting. This part of your request is a duplicate of #533486: View Prior Availability Calendars.

2) Edit past dates
I would call this ancient soviet practices, but I guess valid use cases exists for this feature. To implement, another setting would be needed.

3) More flexible view/edit ranges
I would have to think about a UI for that, perhaps 2 fields accepting strings that are passed to strtotime(). For now this can be solved with a theme preprocess hook, see #1484186: All calendars for specific month for an explanation.

I will try to add this in the next version.

Peacog’s picture

Thank you very much for the very fast reply. I'll just explain the use case here, as it's possibly not the usual way this module is used. I want to use it to configure and display the opening hours for a theme park. During the year the park opens and closes at different times, staying open much later in summer than it does in winter. The opening hours for a particular year are often not finalised until well into January, or even later. Rather than showing upcoming empty months when it gets to September, October of 2012, they would prefer to show the full calendar for 2012 until such time as the dates for 2013 are configured. That's why I need to go back in time to configure January, february and march, and not show 2013 until those dates are ready.

I'll take a look at the preprocess hook. Thanks again.

fietserwin’s picture

Version: 7.x-3.2 » 7.x-3.x-dev
Assigned: Unassigned » fietserwin
Category: support » feature

Turning this into a change request for the features explained in #1.

fietserwin’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev
Jelle_S’s picture

Status: Active » Needs review
FileSize
3.55 KB

I've made a patch that allows you to edit dates in the past and show the state of dates in the past. The actual showing of the past dates I do in a hook_form_alter and a hook_entity_view_alter where I change the #from and #to properties of the element based on an other date field on this entity.

Patch was made against 4.x-dev.

fietserwin’s picture

Status: Needs review » Needs work

Thanks for posting the patch.

Recalling #1, there are 2 options here;
- showing past dates
- editing past dates

They are distinct and thus should get distinct settings. Showing past dates can be done on both widget and formatter, editing past dates can only be done on the widget.

If you can adapt your patch to that, we are quite far.

When this gets in, a next step could be the 3rd option mentioned in #1, but for now that is to be done via hooks. Thinking of it, yet another option could be to also allow to select past dates. I think it is automatically possible now, as it is the js that decides so based no the state. So that should perhaps be forbidden and thus made into another setting as well (on the formatter, thus probably quite similar to the edit option on the widget).

Jelle_S’s picture

Well, showing past dates is quite similar to

3) More flexible view/edit ranges

All this patch really does for now is, when like today, we're the 16th, it will allow the widget to edit the states of the dates starting from the first day of the current month (as the widget will always start at the current month), and it will allow the formatter to show the states of the days of this month that have passed. If you want dates further in the past you have to alter the element in the appropriate hooks.

So I guess I'm not quite clear on the difference between "showing past dates" and "More flexible view/edit ranges"

fietserwin’s picture

That 3rd option will be deferred as this patch is a prerequisite for that. (And I guess it is already possible with hooks, but not sure about that.)

Likewise we could say showing past dates is a prerequisite for editing them, but it is not the same. Being able to view past occupation (or when high season started last year) is different from editing it.

Moreover, now that we are thinking about it: viewing and editing past dates should be a permission as well: the owner might want to see past occupation, visitors should not.

So a setting and a permission and in the theme functions both should be AND'ed:

$show_past_dates = user_access('view past dates') && $settings['allow_showing_past'];
...
if (... && $show_past_dates) {
...
}
Jelle_S’s picture

OK, so to clarify on the logic:

Formatter:

User has permission 'view past dates' && formatter settings 'allow_showing_past' == TRUE:

Past dates will be shown with their corresponding states.

User does not have permission 'view past dates' || formatter settings 'allow_showing_past' == FALSE:

Formatter will show dates starting this month (or starting from 'show_from_date' if it is in the future, when this option is implemented)
Past dates (beginning of this month) will have no styling no matter what state they have.

Widget:

User has permission 'edit past dates' && widget settings 'allow_editing_past' == TRUE:

Past dates will be shown with their corresponding states & can be edited by the user.

User does not have permission 'edit past dates' || widget settings 'allow_editing_past' == FALSE:

Widget will show dates starting this month (or starting from 'edit_from_date' if it is in the future)
Past dates will have no styling no matter what state they have

Does that sound about right to you?

fietserwin’s picture

Widget:

User has permission 'view past dates' && widget settings 'allow_showing_past' == TRUE:
Past dates will be shown with their corresponding states (but cannot necessarily be edited, see rules below for that).

User does not have permission 'view past dates' || widget settings 'allow_showing_past' == FALSE:
Widget will show dates starting this month (or starting from 'show_from_date' if it is in the future, when this option is implemented)
Past dates (beginning of this month) will have no styling no matter what state they have.

If past dates are shown (via the above rules) in the widget && User has permission 'edit past dates' && widget settings 'allow_editing_past' == TRUE:
Past dates can also be edited by the user.

Past dates are not shown || User does not have permission 'edit past dates' || widget settings 'allow_editing_past' == FALSE:
Widget will show dates starting this month (or starting from 'edit_from_date' if it is in the future)
Past dates will not be editable.

Additional notes:
- This makes the edit permission requiring the view permission as well. I'm not sure how that is typically done in Drupal: admin has to assign both permissions to a role or code handles edit permission internally as "edit and view" permission.
- I think that for the distinction between viewing and editing/selecting changes in js are necessary. If javascript is not your cup of tea, I can do that part of the patch.

quardz’s picture

Issue summary: View changes

im facing same issue in version 5.x, would be helpful if someone gives me clue.

William Aubert’s picture

Thank you for this patch,

I tried to display a calendar of the current year starting by january.

function mytheme_preprocess_availability_calendar_months(&$variables) {
  $months_year = 12; 
  $variables['settings']['show_number_of_months'] = $months_year;
  $variables['month'] = 1;
  }

I used the patch to display past dates : #1490928: Showing dates in the past#comment-7970489.
But only the dates of the current month have the templated class. All other previous months have the class 'cal-other'.

Is there any specific hook to get the $state values ​​of past dates ?