Commit 136e57e5 authored by nicola85's avatar nicola85

ROOMS-82: Use the "Services" module

parent f8298bb0
name = Booking and Availability Management API
description = Provides API access to Rooms for Drupal 7 and BAM for Drupal 8
core = 7.x
php = 5.5.0
php = 5.3.9
package = BAM
\ No newline at end of file
package = BAM
dependencies[] = rooms_availability
dependencies[] = rest_server
dependencies[] = services
files[] = includes/bam_api.rooms_unit_field_handler.inc
This diff is collapsed.
<?php
/**
* Implements hook_default_services_endpoint().
*/
function bam_api_default_services_endpoint() {
$export = array();
$endpoint = new stdClass();
$endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */
$endpoint->api_version = 3;
$endpoint->name = 'bam_api';
$endpoint->server = 'rest_server';
$endpoint->path = 'bam/v1';
$endpoint->authentication = array(
'services' => 'services',
);
$endpoint->server_settings = array(
'formatters' => array(
'json' => TRUE,
'bencode' => FALSE,
'jsonp' => FALSE,
'php' => FALSE,
'xml' => FALSE,
'yaml' => FALSE,
),
'parsers' => array(
'application/json' => TRUE,
'application/vnd.php.serialized' => TRUE,
'application/x-www-form-urlencoded' => TRUE,
'application/x-yaml' => TRUE,
'application/xml' => TRUE,
'multipart/form-data' => TRUE,
'text/xml' => TRUE,
),
);
$endpoint->resources = array(
'units' => array(
'operations' => array(
'index' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
),
'actions' => array(
'add' => array(
'enabled' => '1',
),
),
),
'availability' => array(
'operations' => array(
'index' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
),
),
'pricing' => array(
'operations' => array(
'index' => array(
'enabled' => '1',
),
'update' => array(
'enabled' => '1',
),
),
),
'booking' => array(
'operations' => array(
'index' => array(
'enabled' => '1',
),
),
'actions' => array(
'add' => array(
'enabled' => '1',
),
),
),
);
$endpoint->debug = 0;
$export['bam_api'] = $endpoint;
return $export;
}
<?php
interface RoomsUnitFieldHandlerInterface {
public function getFieldType();
public function getFieldInfo();
}
abstract class RoomsUnitFieldHandlerBase implements RoomsUnitFieldHandlerInterface {
protected $unit;
public function __construct(RoomsUnit $unit) {
$this->unit = $unit;
}
}
<?php
$plugin = array(
'label' => t('Commerce Price'),
'handler' => array(
'class' => 'RoomsUnitFieldHandlerCommercePrice',
),
);
class RoomsUnitFieldHandlerCommercePrice extends RoomsUnitFieldHandlerBase {
public function getFieldType() {
return 'commerce_price';
}
public function getFieldInfo() {
$price_fields = array();
$fields = field_info_instances('rooms_unit', $this->unit->type);
foreach ($fields as $field) {
$field_info = field_info_field($field['field_name']);
if ($field_info['type'] == 'commerce_price') {
$field_array = $this->unit->{$field['field_name']};
$price_fields[$field['field_name']] = array(
'amount' => $field_array[LANGUAGE_NONE][0]['amount'],
'currency_code' => $field_array[LANGUAGE_NONE][0]['currency_code'],
);
}
}
return $price_fields;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment