Shows a table describing an "availability rule"
Shows a stage in ctools multistep form where user selects date fields that negat
Shows a validation error at the top of the screen indicating issue with availabi

Experimental project

This is a sandbox project, which contains experimental code for developer use only.

Summary

This module uses Entity Referenence relationships and Date fields to flag entities as "unavailable" during specific time periods.

Documentation is available here: http://www.westernascentinc.com/open-source-projects/entity-availability

Flexibility for complex relationships

The idea is to allow an admin to create rules like this:
Date Field A.date-A of Entity A defines a period of time when Entity B is not available.
Entity A connects to Entity B with Entity Reference Field A.reference-B
When Entity C then tries to reference Entity B with an Entity Reference Field C.reference-B and defines a date range with Date Field C.date-A that is set within the time range defined by Date Field A.date-A, a validation error is thrown on save of Entity C, because Entity A has "reserved" or made Entity B unavailable in that time range.

The relationships are all configurable. Entity A and B could potentially be the same entity. The field relationships are all configurable as well, and a ctools multistep form wizard exists to help you get these complex rules set up.

The idea is that you can create your own complex availability rules based on whatever date and entity reference fields you choose.

Major concepts

There are 3 major parts to each configurable "Availability Rule"

  1. The "available entity"
    This is the entity that the availability rule will apply to.
  2. The "restricting date field"
    This is the field that defines the nonavailability.
  3. The "restricted entity reference field"
    This is the field that should be restricted based on the entity availability.

For example, a working rule could be described like this:
The profile2 entity of bundle "personal" is the Available Entity.
field_dates on all bundles of dateset entities referencing available entity via field_instructor are the Restricting Date field.
field_instructor on all bundles of dateset entities within date ranged defined by within date ranged defined by dsm_dates are the Restricted Entity Reference field.

Conflict resolution

There's a hook in this module (hook_entityavailability_handle_conflict ) that will allow other modules to decide how to react to entity availability conflicts. This provides a high level of customization. I'm also currently working on Rules integration.

Warning

This has only been lightly tested for a specific use case. It could use a lot of testing to work out any bugs related to other types of entity/field relationships.

Code details

I've used hook_field_widget_form_alter() to add and additional field validation to Entity Reference fields. The validation will check date fields and references between the entities involved against "restriction rules" that are managed in a UI this module provides, which define date/entityreference field relationships and how they affect "availability"

Sponsor

This project is sponsored by:

Western Ascent, Inc Logo

Project information