| 1 |
<?php |
<?php |
| 2 |
// $Id: bookingsapi.views.inc,v 1.3 2008/07/31 06:41:04 carson Exp $ |
// $Id: bookingsapi.views.inc,v 1.4 2008/08/18 09:05:30 carson Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Expose booking information to Views. |
* Expose booking information to Views. |
| 43 |
'bookings_schedules' => array( |
'bookings_schedules' => array( |
| 44 |
'left_field' => 'record_id', |
'left_field' => 'record_id', |
| 45 |
'field' => 'record_id', |
'field' => 'record_id', |
| 46 |
|
'type' => 'INNER', |
| 47 |
), |
), |
| 48 |
'bookings_resources' => array( |
'bookings_resources' => array( |
| 49 |
'left_field' => 'resource_id', |
'left_field' => 'resource_id', |
| 50 |
'field' => 'resource_id', |
'field' => 'resource_id', |
| 51 |
|
'type' => 'INNER', |
| 52 |
), |
), |
| 53 |
); |
); |
| 54 |
|
|
| 122 |
), |
), |
| 123 |
); |
); |
| 124 |
|
|
| 125 |
$data['bookings_records']['ical_rrule'] = array( |
$data['bookings_records']['rrule'] = array( |
| 126 |
'title' => t('Repeat rule'), |
'title' => t('Repeat rule'), |
| 127 |
'help' => t('A description of the RRULE.'), |
'help' => t('A description of the RRULE.'), |
| 128 |
'field' => array( |
'field' => array( |
| 436 |
return $data; |
return $data; |
| 437 |
} |
} |
| 438 |
|
|
|
/** |
|
|
* Views assumes dates are always Unix timestamps, so convert our DATETIME-formatted columns. |
|
|
* |
|
|
*/ |
|
|
class views_handler_field_datetime extends views_handler_field_date { |
|
|
function query() { |
|
|
$this->ensure_my_table(); |
|
|
$this->field_alias = $this->query->add_field(NULL, "UNIX_TIMESTAMP(".$this->table_alias.'.'.$this->field.')', $this->table_alias . '_' . $this->field); |
|
|
} |
|
|
} |
|
|
|
|
|
class views_handler_filter_datetime extends views_handler_filter_date { |
|
|
function op_simple($field) { |
|
|
$value = intval(strtotime($this->value['value'], 0)); |
|
|
$value = date_convert($value, DATE_UNIX, DATE_DATETIME); |
|
|
if ($this->value['type'] == 'offset') { |
|
|
$value = 'NOW()' . sprintf('%+d', $value); // keep sign |
|
|
$this->query->add_where($this->options['group'], "$field $this->operator %s", $value); |
|
|
} else { |
|
|
$this->query->add_where($this->options['group'], "$field $this->operator '%s'", $value); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
class views_handler_filter_bookings_resource_disabled extends views_handler_filter_boolean_operator { |
|
|
function construct() { |
|
|
$this->definition['label'] = 'Check to show only disabled, or leave empty to show only enabled.'; |
|
|
parent::construct(); |
|
|
} |
|
|
} |
|
|
|
|
|
class views_handler_field_bookings_resource_disabled extends views_handler_field { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->additional_fields['disabled'] = 'disabled'; |
|
|
} |
|
|
|
|
|
function query() { // what is this? |
|
|
$this->ensure_my_table(); |
|
|
$this->add_additional_fields(); |
|
|
} |
|
|
|
|
|
function render($values) { |
|
|
parent::render($values); |
|
|
$disabled = (bool) $values->{$this->aliases['disabled']}; |
|
|
return $disabled ? t('Yes') : t('No'); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Filter by resource ID. |
|
|
* |
|
|
*/ |
|
|
class views_handler_filter_bookings_resource_id extends views_handler_filter_in_operator { |
|
|
function get_value_options() { |
|
|
if (isset($this->value_options)) { |
|
|
return; |
|
|
} |
|
|
|
|
|
$this->value_options = array(); |
|
|
$sql = 'SELECT name, resource_id FROM {bookings_resources}'; |
|
|
$q = db_query($sql); |
|
|
while($res = db_fetch_object($q)) { |
|
|
$this->value_options[$res->resource_id] = $res->name; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Filter by record ID. |
|
|
* |
|
|
*/ |
|
|
class views_handler_filter_bookings_record_id extends views_handler_filter_in_operator { |
|
|
function get_value_options() { |
|
|
if (isset($this->value_options)) { |
|
|
return; |
|
|
} |
|
|
|
|
|
$this->value_options = array(); |
|
|
$sql = 'SELECT name, record_id FROM {bookings_resources}'; |
|
|
$q = db_query($sql); |
|
|
while($res = db_fetch_object($q)) { |
|
|
$this->value_options[$res->record_id] = $res->name; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Filter by type (booking type + availability types). |
|
|
* |
|
|
*/ |
|
|
class views_handler_filter_bookings_record_types extends views_handler_filter_in_operator { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->definition['numeric'] = TRUE; |
|
|
} |
|
|
|
|
|
function get_value_options() { |
|
|
if (isset($this->value_options)) { |
|
|
return; |
|
|
} |
|
|
$this->value_options = array(); |
|
|
$types = bookingsapi_record_types(); |
|
|
foreach($types as $k => $v) { |
|
|
$this->value_options[$k] = $v; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Filter by availability type. |
|
|
* |
|
|
*/ |
|
|
class views_handler_filter_bookings_availability_types extends views_handler_filter_bookings_record_types { |
|
|
function get_value_options() { |
|
|
if (isset($this->value_options)) { |
|
|
return; |
|
|
} |
|
|
$this->value_options = array(); |
|
|
$types = bookingsapi_availability_types(); |
|
|
foreach($type as $k => $v) { |
|
|
$this->value_options[$k] = $v; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
class views_handler_field_bookings_record_types extends views_handler_field { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->additional_fields['type'] = 'type'; |
|
|
} |
|
|
|
|
|
function render($values) { |
|
|
parent::render($values); |
|
|
$type = $values->{$this->aliases['type']}; |
|
|
$types = bookingsapi_record_types(); |
|
|
// if using string ENUMs, do the necessary conversion |
|
|
if(is_string($type)) { |
|
|
$type = bookingsapi_record_types($type); |
|
|
} |
|
|
return $types[(int) $type]; |
|
|
} |
|
|
} |
|
| 439 |
|
|
|
class views_handler_field_bookings_default_availability extends views_handler_field { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->additional_fields['default_availability'] = 'default_availability'; |
|
|
} |
|
|
|
|
|
function render($values) { |
|
|
parent::render($values); |
|
|
$type = $values->{$this->aliases['default_availability']}; |
|
|
$types = bookingsapi_record_types(); |
|
|
// if using string ENUMs, do the necessary conversion |
|
|
if(is_string($type)) { |
|
|
$type = bookingsapi_record_types($type); |
|
|
} |
|
|
return $types[(int) $type]; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Display the ical_rrule column in human-readable format. |
|
|
* |
|
|
*/ |
|
|
class views_handler_field_bookings_rrule extends views_handler_field { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->additional_fields['ical_rrule'] = 'ical_rrule'; |
|
|
$this->additional_fields['start'] = 'start'; |
|
|
} |
|
|
|
|
|
function render($values) { |
|
|
parent::render($values); |
|
|
$ical_rrule = $values->{$this->aliases['ical_rrule']}; |
|
|
$start = $values->{$this->aliases['start']}; |
|
|
return date_repeat_rrule_description($ical_rrule, $start); |
|
|
} |
|
|
} |
|
|
|
|
|
class views_handler_field_bookings_record_statuses extends views_handler_field { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->additional_fields['status'] = 'status'; |
|
|
} |
|
|
|
|
|
function render($values) { |
|
|
parent::render($values); |
|
|
$status = $values->{$this->aliases['status']}; |
|
|
$status = bookingsapi_record_status(); |
|
|
// if using string ENUMs, do the necessary conversion |
|
|
if(is_string($status)) { |
|
|
$status = bookingsapi_record_status($status); |
|
|
} |
|
|
return $status[(int) $status]; |
|
|
} |
|
|
} |
|
|
|
|
|
class views_handler_filter_bookings_record_statuses extends views_handler_filter_in_operator { |
|
|
function construct() { |
|
|
parent::construct(); |
|
|
$this->definition['numeric'] = TRUE; |
|
|
} |
|
|
|
|
|
function get_value_options() { |
|
|
if (isset($this->value_options)) { |
|
|
return; |
|
|
} |
|
|
$this->value_options = array(); |
|
|
$status = bookingsapi_record_status(); |
|
|
foreach($status as $k => $v) { |
|
|
$this->value_options[$k] = $v; |
|
|
} |
|
|
} |
|
|
} |
|