I've set up a availability event type with hourly granularity. When using bat state facet only on available state with start/end dates including fraction of an hour i get invalid results.
An example:
- i've setup only a single unit, say A, for unit type Car
- i have already an event in "booked" (blocking) state from 2018-04-15 0:00 to 2018-04-16 12:30 for in the availability calendar of unit A
- i search for availability from 2018-04-16 12:00 to 2018-04-17 13:30
expected result:
An empty set
actual result:
1 unit of type Car (Unit A)
After some debugging i found that this behaviour come from the call to getMatchingUnits in bat_facet.module at line 77
$response = $calendar->getMatchingUnits($start_date, $end_date, $valid_states, $constraints, TRUE);
the last parameter (TRUE) makes the search using "intersection" of states of events found in date range with the "available" state instead of difference.
In the date range from 2018-04-16 12:00 to 2018-04-17 13:30 the states are two ["booked", "available"]. This is right since the resource is booked until 2018-04-16 12:30 and then available.
But intersection (AbstractCalendar, line 148)
array_intersect($current_states, $valid_states);
returns "available" element since $current_states = ["booked", "available"] and $valid_states = ["available"].
This puts the unit in the "included" set but this resource is clearly not bookable in the requested range.
The solution, at least for this specific case, is to use difference instead of intersection by changing:
$response = $calendar->getMatchingUnits($start_date, $end_date, $valid_states, $constraints);
Probably could be useful to choose the search behaviour from Bat State facet setting page.
Attached patch only changes the line above.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | showing_only_date.png | 151.57 KB | Swathi Nagella |
| bat_facet.patch | 760 bytes | maurizio.ganovelli |
Comments
Comment #2
maurizio.ganovelliComment #3
Swathi Nagella commentedHi,
I have same problem I used the patch also still i have same problem.
Comment #4
maurizio.ganovelliHi, i'm using current latest dev (Commit 48123d2) with this patch and seems to work correctly. Are you using the same version?
Comment #5
Swathi Nagella commentedYa I used latest dev version only.
Comment #6
maurizio.ganovelliI've extensively tested the system with this patch and it always gives me back the expected results.
I found other issues on bat_facets but not related to OP.
I'm sorry that I can't help you further on this.
Comment #7
acrollet commentedThis patch looks like the right thing to do - I've created a PR at https://github.com/Roomify/bat_drupal/pull/57 and am going to have a colleague review it. Thanks!
Comment #8
Swathi Nagella commentedHi,
#1 you mention that your getting date with time in search availability view page, but i am not getting time filed even if i select hours .Please can anyone help me
Comment #9
maurizio.ganovelliHi, in my case i've done a form alter since i have a custom datepicker for date and a dropdown for time (limited to opening hours).
Comment #10
Swathi Nagella commentedHi, kindly advise how you mange the time.
Comment #11
maurizio.ganovelliI think it's better to file a new issue since this seems unrelated to OP.
Comment #14
acrollet commentedcommitted, thanks for the contribution!