public function BookingEvent::lock in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Locks event - updates the rooms_booking_locks table to indicate that this event is locked.
Return value
bool TRUE if the event is locked successfully, FALSE if was already blocked.
Overrides BookingEventInterface::lock
File
- modules/
rooms_availability/ includes/ rooms_availability.booking_event.inc, line 46 - Class BookingEvent
Class
- BookingEvent
- @file Class BookingEvent
Code
public function lock() {
// Check that the event is not already locked.
$query = db_select('rooms_booking_locks', 'l');
$query
->addField('l', 'unit_id');
$query
->addField('l', 'state');
$query
->addField('l', 'locked');
$query
->condition('l.unit_id', $this->unit_id);
$query
->condition('l.state', $this->id);
$query
->condition('l.locked', 1);
$result = $query
->execute()
->fetchAll(PDO::FETCH_ASSOC);
if (count($result) == 1) {
return FALSE;
}
else {
$fields = array(
'unit_id' => $this->unit_id,
'state' => $this->id,
'locked' => 1,
);
$lock = db_insert('rooms_booking_locks')
->fields($fields);
$lock
->execute();
}
return TRUE;
}