rooms.calendar.inc in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
File
includes/rooms.calendar.inc
View source
<?php
abstract class RoomsCalendar implements RoomsCalendarInterface {
protected $unit_id;
protected $default_state;
protected $base_table;
public abstract function updateCalendar($events);
public function addMonthEvent(RoomsEventInterface $event) {
if ($this
->monthDefined($event
->startMonth(), $event
->startYear())) {
$partial_month_row = $this
->preparePartialMonthArray($event);
$update = db_update($this->base_table)
->condition('unit_id', $this->unit_id)
->condition('month', $event
->startMonth())
->condition('year', $event
->startYear())
->fields($partial_month_row)
->execute();
}
else {
$days = $this
->prepareFullMonthArray($event);
$month_row = array(
'unit_id' => $this->unit_id,
'year' => $event
->startYear(),
'month' => $event
->startMonth(),
);
$month_row = array_merge($month_row, $days);
$insert = db_insert($this->base_table)
->fields($month_row);
$insert
->execute();
}
}
protected abstract function prepareFullMonthArray(RoomsEventInterface $event);
protected abstract function preparePartialMonthArray(RoomsEventInterface $event);
public abstract function getEvents(DateTime $start_date, DateTime $end_date);
public abstract function getRawDayData(DateTime $start_date, DateTime $end_date);
public function monthDefined($month, $year) {
$query = db_select($this->base_table, 'a');
$query
->addField('a', 'unit_id');
$query
->addField('a', 'year');
$query
->addField('a', 'month');
$query
->condition('a.unit_id', $this->unit_id);
$query
->condition('a.year', $year);
$query
->condition('a.month', $month);
$result = $query
->execute()
->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0) {
return TRUE;
}
return FALSE;
}
}
Classes
Name |
Description |
RoomsCalendar |
Handles querying and updating the availability information
relative to a single bookable unit. |