It would be really nice if we could use relative dates ('-1 day') for scheduling and reminder mails. This would allow site admins to set sensible defaults for registration field instances.

I realise the current registration entity does not have a date associated with it, so the registration itself does not know when the event is. Node registration offers a select list to reference the event date (and other properties such as number of places) which can be set as node fields to the registration. We might be able to use some of that code?

That way people creating (basic) registrations would not need to enter the settings page anymore, as all properties are already set during node creation.

Is this something you would consider adding to the 7.x-2.x branch?

Comments

Neograph734 created an issue. See original summary.

neograph734’s picture

Title: Allow relative dates for registration reminders » Allow relative dates for scheduling and registration reminders
greg boggs’s picture

This sounds like a great feature to me. We'd likely review, test, and accept useful patches like one that would add the feature.

neograph734’s picture

Assigned: Unassigned » neograph734

I'll see what I can do then. But it might take some time.

neograph734’s picture

Perhaps you can think along with me to get this first time right.

The registration should be aware of a possible event date, thus we should add a property (event_date) to the registration entity. This property is to become the base for relative dates so that '-1 day' is calculated as event_date -1 day. There are two possible options;

  1. This becomes a computed property, so during entity construction we calculate it's value based on the parent. (This requires updating eg. cron functions where we will not be able to use the database anymore, but we'd need to build entities.)
  2. We add this field to the registration_entity table, but we must make sure to update the field every time the parent (date field) is updated, so it is always kept in sync.

On registration entity save, we update the reminder and schedule date fields with the newly calculated values reminder_date = event_date - x days or, when no event_date is provided (or the user does not want to use relative dates) we use the current date field. This makes sure all current implementations remain functioning as they are and requires some form API #states magic. The problem is we should store all relative date settings; open -10 days, close -1 day, reminder -3 days. Would a database blob field work (as we don't need this data to be readable or writable anywhere else except for in the forms).

Summary

Should we calculate the event date based on a parent entity's property OR do we want to clone the field value and make sure it is always kept up to date?
Would it suffice to store all relative date values in a database blob to prevent creating lots of new db columns which don't require reading or writing except for when used in the form?

neograph734’s picture

@Greg, could you perhaps share your thoughts on the proposed changes?

neograph734’s picture

Assigned: neograph734 » Unassigned
Status: Active » Needs review

Temporarily removing myself so hopefully a maintainer sees the issue.

greg boggs’s picture

I've read this a couple of times. This module has several maintainers and we all get emailed by each post in our issue queue. I'm afraid I'm not going to be much help to you in creating this feature. But, at a high level, it's best not to store blobs in the database. Blobs can't be used in views. Blobs can't easily be accessed with wrappers. Meanwhile, database columns are accessible. I'm wondering if you can't rely on only storing the date of the event. But, I don't really understand your use case completely as I haven't used node registration.

~Greg

neograph734’s picture

Thanks Greg, I understand and I guess I can handle most of the issue by myself, I just wanted to get these basics discussed so I can write something that fits the module as good as possible.

The problem is twofold;

  1. In order for a relative date to work, the registration module needs to be aware of the event date. The way node registration handles this, is by referencing a date field on the node and loading the date from there. The alternative option is to add a field to the database which stores the event date.
    The question, should we
    1. Load the event date from the parent entity (node in most cases), where it is likely to exist already (calendars, event listings, etc.)?.
    2. Store the event date on the registration, all settings for registrations are in one place and can be changed easily. Users might however change the date on the node and forget about changing it on the event.
    3. Offer both options and have the user choose to use the parent field, or use a 'local' value.
  2. We need a place to store the relative date formatter. This can be a string in the form '-n days 5 hours' etc. This string is never to be used in Views and is just a setting on the registration field, therefore it is suitable for storing in a blob. My idea was to convert this setting during entity save into a regular date and store that date in the appropriate existing field (open, close, reminder date). This should work as long as nobody alters the date programmatically as the date will be out of sync with the relative date (we might need a mechanism to detect such a change).
    This has the following advantages:
    1. Relative date is built on top of current registration functions.
    2. Relative dates are not required and people can still use the existing date fields.
    3. All registration processing will function as it currently does.

    Is this solid or am I missing things?

I hope I explained better now. There are two things I'd like to know before I start.

Which of the options in 1 better fits this module?
Is storing relative date strings, which are only used during the saving of registration field for calculating other date fields in a blob ok?

oranges13’s picture

A lot of the work for this feature is already done in the patches for issue #1559178: Relative dates for scheduling and registration reminders

It allows you to choose the date field on the parent node you want to use, and basically replicates the relative date settings that the Signup module did. You set defaults in the Registration type, and then you can edit them on an instance-basis in each event node when you create it.

rootwork’s picture

oranges13’s picture

I should have some time this weekend to get back into the code and help out with this :)

neograph734’s picture

Status: Needs review » Needs work

Awesome! Lets do this :)

neograph734’s picture

This is what I came up with. I contains a database update hook, so you need to run update.php.

It still needs some checking if the linked date field actually contains a value, relative date options should be completely disabled otherwise.
Further it seems the state options are terribly broken somehow so all fields are shown at once. (No idea why though...)
Finally, the form validations might need some time but I could not look into that yet.

Last you want to know is that the fields are fully compatible with php relative formats, so you can enter things like -2 weekdays, -1 month, first day of this week, etc.

Please let me know what you think, I can continue working on this tomorrow.

Credits to nielsonm and oranges13 for their initial work on this.

neograph734’s picture

Status: Needs work » Needs review
neograph734’s picture

StatusFileSize
new17.97 KB

Removed some TODO's as they were already done...

neograph734’s picture

StatusFileSize
new20.78 KB
new14.96 KB

States API is fixed and the linked date field is actually working.

Now there are some validations that need updating (such as the registration requires a date check).
Also if no field is provided, it should not be an option to select it and minor ui tweaks (such as field descriptions).

kclarkson’s picture

Status: Needs review » Closed (duplicate)