public function UnitPricingCalendar::calculatePricingEvents in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Get a set of PricingEvent between start_date and end_date filtered by days.
Parameters
int $unit_id: The unit id to calculate.
int $amount: The initial amount.
DateTime $start_date: The start date.
DateTime $end_date: The end date.
string $operation: The operation to perform.
int $days: The event duration.
Return value
PricingEventInterface[] The events in that range of dates
Overrides UnitPricingCalendarInterface::calculatePricingEvents
File
- modules/
rooms_pricing/ includes/ rooms_pricing.unit_pricing_calendar.inc, line 535 - Contains UnitPricingCalendar.
Class
- UnitPricingCalendar
- Handles querying and updating the pricing information relative to a single bookable unit.
Code
public function calculatePricingEvents($unit_id, $amount, DateTime $start_date, DateTime $end_date, $operation, $days) {
$s_timestamp = $start_date
->getTimestamp();
$e_timestamp = $end_date
->getTimestamp();
$events = array();
do {
$s_date = getdate($s_timestamp);
$wday_start = $s_date['wday'];
if (in_array($wday_start + 1, $days)) {
$events[] = new PricingEvent($unit_id, $amount, new DateTime(date('Y-m-d', $s_timestamp)), new DateTime(date('Y-m-d', $s_timestamp)), $operation, $days);
}
$s_timestamp = strtotime('+1 days', $s_timestamp);
} while ($s_timestamp <= $e_timestamp);
return $events;
}