You are here

rooms_unit.module in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Manage units - Units are things that can be booked on a nightly basis (e.g. rooms - but also villas bungalows, etc).

File

modules/rooms_unit/rooms_unit.module
View source
<?php

/**
 * @file
 * Manage units - Units are things that can be booked on a nightly basis
 * (e.g. rooms - but also villas bungalows, etc).
 */

/**
 * Defining some room states that will be used throughout.
 */
define('ROOMS_NOT_AVAILABLE', 0);
define('ROOMS_AVAILABLE', 1);
define('ROOMS_ON_REQUEST', 2);
define('ROOMS_ANON_BOOKED', 3);
define('ROOMS_UNCONFIRMED_BOOKINGS', -1);

/**
 * Defining responses for Calendar Updated.
 */
define('ROOMS_BLOCKED', 100);
define('ROOMS_UPDATED', 200);
define('ROOMS_WRONG_UNIT', 300);

/**
 * Implements hook_menu().
 */
function rooms_unit_menu() {
  $items = array();
  $items['admin/rooms/unit-type/description-source'] = array(
    'title' => 'Unit type description source',
    'page callback' => 'rooms_unit_type_description_source',
    'access arguments' => array(
      'bypass rooms_unit entities access',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_entity_info().
 */
function rooms_unit_entity_info() {
  $return['rooms_unit'] = array(
    'label' => t('Bookable Units'),
    // The entity class and controller class extend the classes provided by the
    // Entity API.
    'entity class' => 'RoomsUnit',
    'controller class' => 'RoomsUnitController',
    'base table' => 'rooms_units',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'unit_id',
      'bundle' => 'type',
      'label' => 'name',
    ),
    // Bundles are defined by the unit types below.
    'bundles' => array(),
    // Bundle keys tell the FieldAPI how to extract information from the bundle
    // objects.
    'bundle keys' => array(
      'bundle' => 'type',
    ),
    'view modes' => array(
      'display' => array(
        'label' => t('Display'),
        'custom settings' => FALSE,
      ),
    ),
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'creation callback' => 'rooms_unit_create',
    'access callback' => 'rooms_unit_access',
    'access arguments' => array(
      'user key' => 'uid',
      'access tag' => 'rooms_unit_access',
    ),
    'permission labels' => array(
      'singular' => t('bookable unit'),
      'plural' => t('bookable units'),
    ),
    'module' => 'rooms_unit',
    // The information below is used by the RoomsRoomUIController (which extends
    // the EntityDefaultUIController).
    'admin ui' => array(
      'path' => 'admin/rooms/units',
      'file' => 'rooms_unit.admin.inc',
      'controller class' => 'RoomsUnitUIController',
      'menu wildcard' => '%rooms_unit',
    ),
    'translation' => array(
      'entity_translation' => array(
        'base path' => 'admin/rooms/units/unit/%rooms_unit',
        'default settings' => array(
          'default_language' => LANGUAGE_NONE,
          'hide_language_selector' => FALSE,
        ),
      ),
    ),
  );

  // The entity that holds information about the entity types.
  $return['rooms_unit_type'] = array(
    'label' => t('Bookable Unit Type'),
    'entity class' => 'RoomsUnitType',
    'controller class' => 'RoomsUnitTypeController',
    'base table' => 'rooms_unit_type',
    'fieldable' => TRUE,
    'bundle of' => 'rooms_unit',
    'exportable' => TRUE,
    'entity keys' => array(
      'id' => 'id',
      'name' => 'type',
      'label' => 'label',
    ),
    'access callback' => 'rooms_unit_type_access',
    'module' => 'rooms_unit',
    // Enable the entity API's admin UI.
    'admin ui' => array(
      'path' => 'admin/rooms/units/unit-types',
      'file' => 'rooms_unit_type.admin.inc',
      'controller class' => 'RoomsUnitTypeUIController',
    ),
  );
  return $return;
}

/**
 * Implements hook_entity_info_alter().
 *
 * We are adding the info about the unit types via a hook to avoid a recursion
 * issue as loading the room types requires the entity info as well.
 *
 * @todo This needs to be improved
 */
function rooms_unit_entity_info_alter(&$entity_info) {
  foreach (rooms_unit_get_types() as $type => $info) {
    $entity_info['rooms_unit']['bundles'][$type] = array(
      'label' => $info->label,
      'admin' => array(
        'path' => 'admin/rooms/units/unit-types/manage/%rooms_unit_type',
        'real path' => 'admin/rooms/units/unit-types/manage/' . $type,
        'bundle argument' => 5,
        'access arguments' => array(
          'bypass rooms_unit entities access',
        ),
      ),
    );
  }

  // Create custom build mode.
  $entity_info['node']['view modes']['rooms_list'] = array(
    'label' => t('Rooms Results View'),
    'custom settings' => FALSE,
  );
}

/**
 * Implements hook_permission().
 */
function rooms_unit_permission() {
  $permissions = array(
    'administer rooms_unit_type entities' => array(
      'title' => t('Administer bookable unit types'),
      'description' => t('Allows users to add bookable unit types and configure their fields.'),
      'restrict access' => TRUE,
    ),
    'view any rooms_unit unpublished entity' => array(
      'title' => t('View any unpublished bookable unit'),
      'description' => t('Allows users to view any unpublished bookable unit.'),
      'restrict access' => TRUE,
    ),
    'view own rooms_unit unpublished entities' => array(
      'title' => t('View own unpublished bookable units'),
      'description' => t('Allows users to view own unpublished bookable units.'),
    ),
    'manage room units' => array(
      'title' => t('Manage Room Units'),
      'description' => t('Allows access to the Rooms Unit Admin'),
      'restrict access' => TRUE,
    ),
  );
  $permissions += rooms_entity_access_permissions('rooms_unit');

  // Override view permissions.
  $entity_info = entity_get_info('rooms_unit');
  foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
    $permissions['view own rooms_unit entities of bundle ' . $bundle_name] = array(
      'title' => t('View own published %bundle @entity_type', array(
        '@entity_type' => 'bookable units',
        '%bundle' => $bundle_info['label'],
      )),
    );
    $permissions['view any rooms_unit entity of bundle ' . $bundle_name] = array(
      'title' => t('View any published %bundle @entity_type', array(
        '@entity_type' => 'bookable unit',
        '%bundle' => $bundle_info['label'],
      )),
    );
  }
  return $permissions;
}

/**
 * Determines whether the given user has access to a bookable unit.
 *
 * @param string $op
 *   The operation being performed. One of 'view', 'update', 'create', 'delete'
 *   or just 'edit' (being the same as 'create' or 'update').
 * @param RoomsUnit $unit
 *   Optionally a unit or a unit type to check access for. If nothing is
 *   given, access for all units is determined.
 * @param object $account
 *   The user to check for. Leave it to NULL to check for the global user.
 *
 * @return boolean
 *   Whether access is allowed or not.
 */
function rooms_unit_access($op, $unit = NULL, $account = NULL) {
  return rooms_entity_access($op, $unit, $account, 'rooms_unit');
}

/**
 * Filters rooms unit based on permissions for multiple values.
 */
function rooms_unit_access_filter($op, $units = array(), $account = NULL) {
  $filtered_units = array();

  // If no user object is supplied, the access check is for the current user.
  if (empty($account)) {
    $account = $GLOBALS['user'];
  }
  foreach ($units as $key => $unit) {
    if (rooms_unit_access($op, $unit, $account)) {
      $filtered_units[$key] = $unit;
    }
  }
  return $filtered_units;
}

/**
 * Access callback for the entity API.
 */
function rooms_unit_type_access($op, $type = NULL, $account = NULL) {
  return user_access('administer rooms_unit_type entities', $account);
}

/**
 * Implements hook_query_TAG_alter().
 */
function rooms_unit_query_rooms_unit_access_alter(QueryAlterableInterface $query) {

  // Look for an unit base table to pass to the query altering function or else
  // assume we don't have the tables we need to establish order related altering
  // right now.
  foreach ($query
    ->getTables() as $table) {
    if ($table['table'] === 'rooms_units') {
      rooms_entity_access_query_alter($query, 'rooms_unit', $table['alias']);
      break;
    }
  }
}

/**
 * Implements hook_rooms_entity_access_OP_condition_ENTITY_TYPE_alter().
 */
function rooms_unit_rooms_entity_access_view_condition_rooms_unit_alter(&$conditions, $context) {
  $account = $context['account'];
  if (user_access('view any rooms_unit unpublished entity', $account)) {
    return;
  }
  $old_conditions = $conditions;
  if ($old_conditions
    ->count()) {
    $conditions = db_and();
    if ($account->uid && user_access('view own rooms_unit unpublished entities', $account)) {
      $or = db_and()
        ->condition($context['base_table'] . '.status', 0)
        ->condition($context['base_table'] . '.uid', $account->uid);
      $conditions
        ->condition(db_or()
        ->condition($or)
        ->condition($context['base_table'] . '.status', 1));
    }
    else {
      $conditions
        ->condition($context['base_table'] . '.status', 1);
    }
    $conditions
      ->condition($old_conditions);
  }
}

/**
 * Access callback: Checks whether the user has permission to add a unit.
 *
 * @return bool
 *   TRUE if the user has add permission, otherwise FALSE.
 *
 * @see node_menu()
 */
function _rooms_unit_add_access() {
  if (user_access('administer rooms_unit_type entities')) {

    // There are no bookable unit types defined that the user has permission to
    // create, but the user does have the permission to administer the content
    // types, so grant them access to the page anyway.
    return TRUE;
  }
  $types = rooms_unit_get_types();
  foreach ($types as $type) {
    if (rooms_unit_access('create', rooms_unit_create(array(
      'type' => $type->type,
      'uid' => 0,
    )))) {
      return TRUE;
    }
  }
  return FALSE;
}

/**
 * Gets an array of all unit types, keyed by the type name.
 *
 * @param string $type_name
 *   If set, the type with the given name is returned.
 * @param bool $reset
 *   A boolean indicating that the internal cache should be reset.
 *
 * @return RoomsUnitType[]
 *   Depending whether $type isset, an array of unit types or a single one.
 */
function rooms_unit_get_types($type_name = NULL, $reset = FALSE) {

  // entity_load() will get the Entity controller for our unit entity and call
  // the load function of that object.
  $types = entity_load_multiple_by_name('rooms_unit_type', isset($type_name) ? array(
    $type_name,
  ) : FALSE);
  return isset($type_name) ? reset($types) : $types;
}

/**
 * Helper function to easily get unit types in an array for use in forms, etc.
 *
 * @return array
 *  An array of unit types keyed by type name and labels
*/
function rooms_unit_types_ids() {
  $unit_types = array();
  $types = rooms_unit_get_types();
  foreach ($types as $type) {
    $unit_types[$type->type] = $type->label;
  }
  return $unit_types;
}

/**
 * Implements hook_entity_insert().
 */
function rooms_unit_entity_insert($entity, $type) {
  if ($type == 'rooms_unit_type') {

    // Create field ('rooms_booking_unit_options') if not exist.
    if (field_read_field('rooms_booking_unit_options') === FALSE) {
      $field = array(
        'field_name' => 'rooms_booking_unit_options',
        'type' => 'rooms_options',
        'cardinality' => -1,
      );
      field_create_field($field);
    }
    if (field_read_instance('rooms_unit', 'rooms_booking_unit_options', $entity->type) === FALSE) {

      // Create the instance on the bundle.
      $instance = array(
        'field_name' => 'rooms_booking_unit_options',
        'entity_type' => 'rooms_unit',
        'label' => 'Options',
        'bundle' => $entity->type,
        'required' => FALSE,
        'widget' => array(
          'type' => 'rooms_options',
        ),
      );
      field_create_instance($instance);
    }
  }
}

/**
 * Menu argument loader; Load a unit type by string.
 *
 * @param $type
 *   The machine-readable name of a unit type to load.
 * @param bool $reset
 *   A boolean indicating whether the internal cache should be reset.
 *
 * @return array|false
 *   A unit type array or FALSE if $type does not exist.
 */
function rooms_unit_type_load($type, $reset = FALSE) {
  return rooms_unit_get_types($type, $reset);
}

/**
 * Fetches a bookable unit object.
 *
 * @param int $unit_id
 *   Integer specifying the unit id.
 * @param bool $reset
 *   A boolean indicating whether the internal cache should be reset.
 * @return RoomsUnit|false
 *   A fully-loaded $unit object or FALSE if it cannot be loaded.
 *
 * @see rooms_unit_load_multiple()
 */
function rooms_unit_load($unit_id, $reset = FALSE) {
  $units = rooms_unit_load_multiple(array(
    $unit_id,
  ), array(), $reset);
  return reset($units);
}

/**
 * Loads multiple units based on certain conditions.
 *
 * @param array $unit_ids
 *   An array of unit IDs.
 * @param array $conditions
 *   An array of conditions to match against the {rooms_units} table.
 * @param bool $reset
 *   A boolean indicating that the internal cache should be reset.
 *
 * @return array
 *   An array of unit objects, indexed by unit_id.
 *
 * @see entity_load()
 * @see rooms_unit_load()
 */
function rooms_unit_load_multiple($unit_ids = array(), $conditions = array(), $reset = FALSE) {
  return entity_load('rooms_unit', $unit_ids, $conditions, $reset);
}

/**
 * Deletes a bookable unit.
 *
 * @param RoomsUnit $unit
 *   The RoomsUnit object that represents the unit to delete.
 */
function rooms_unit_delete(RoomsUnit $unit) {
  $unit
    ->delete();
}

/**
 * Deletes multiple units.
 *
 * @param array $unit_ids
 *   An array of unit IDs.
 */
function rooms_unit_delete_multiple(array $unit_ids) {
  entity_get_controller('rooms_unit')
    ->delete($unit_ids);
}

/**
 * Creates a room object.
 *
 * @param array $values
 *   The properties for the new unit type.
 */
function rooms_unit_create($values = array()) {
  return entity_get_controller('rooms_unit')
    ->create($values);
}

/**
 * Saves a unit to the database.
 *
 * @param RoomsUnit $unit
 *   The Unit object.
 */
function rooms_unit_save(RoomsUnit $unit) {
  return $unit
    ->save();
}

/**
 * Creates a room object.
 *
 * @param array $values
 *   The properties for the new unit type.
 */
function rooms_unit_type_create($values = array()) {
  return entity_get_controller('rooms_unit_type')
    ->create($values);
}

/**
 * Saves a unit type to the db.
 *
 * @param RoomsUnitType $type
 *   The unit type to save.
 */
function rooms_unit_type_save(RoomsUnitType $type) {
  $type
    ->save();
}

/**
 * Deletes a unit type from the db.
 */
function rooms_unit_type_delete(RoomsUnitType $type) {
  $type
    ->delete();
}

/**
 * URI callback for units.
 */
function rooms_unit_uri(RoomsUnit $unit) {
  return array(
    'path' => 'unit/' . $unit->unit_id,
  );
}

/**
 * Menu title callback for showing individual entities.
 */
function rooms_unit_page_title(RoomsUnit $unit) {
  return $unit->name;
}

/**
 * Gets a list of Units keyed by id and name in value.
 *
 * @todo - double check utility of this and perhaps use rooms_unit_load_multiple
 */
function rooms_unit_ids($bundle = '') {
  $units = array();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'rooms_unit');
  if ($bundle != '') {
    $query
      ->entityCondition('bundle', $bundle);
  }
  $result = $query
    ->execute();
  if (count($result) > 0) {
    $entities = entity_load('rooms_unit', array_keys($result['rooms_unit']));
    foreach ($entities as $unit) {
      $wrapper = entity_metadata_wrapper('rooms_unit', $unit);
      $units[$wrapper->unit_id
        ->value()] = $wrapper->name
        ->value();
    }
  }
  return $units;
}

/**
 * Sets up content to show an individual unit.
 * @todo - get rid of drupal_set_title();
 */
function rooms_unit_page_view($unit, $view_mode = 'full') {
  $controller = entity_get_controller('rooms_unit');
  $content = $controller
    ->view(array(
    $unit->unit_id => $unit,
  ), $view_mode);
  drupal_set_title($unit->name);
  return $content;
}

/**
 * Implements hook_views_api().
 */
function rooms_unit_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'rooms_unit') . '/views',
  );
}

/**
 * Implements hook_theme().
 */
function rooms_unit_theme() {
  return array(
    'rooms_unit_add_list' => array(
      'variables' => array(
        'content' => array(),
      ),
      'file' => 'rooms_unit.admin.inc',
    ),
    'rooms_unit' => array(
      'render element' => 'elements',
      'template' => 'rooms_unit',
    ),
    'rooms_unit_extra_data' => array(
      'variables' => array(
        'unit_extra_data',
        'unit' => NULL,
      ),
      'template' => 'rooms_unit-extra-data',
    ),
  );
}

/**
 * Helper function for Unit Description autocomplete.
 */
function rooms_unit_type_description_source($string = '') {
  $matches = array();
  if ($string) {
    $result = db_select('node', 'n')
      ->fields('n', array(
      'title',
      'nid',
    ))
      ->condition('title', db_like($string) . '%', 'LIKE')
      ->condition('n.type', 'unit_description')
      ->range(0, 10)
      ->execute();
    foreach ($result as $description) {
      $matches[$description->title . ':' . $description->nid] = check_plain($description->title);
    }
  }
  drupal_json_output($matches);
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function rooms_unit_menu_local_tasks_alter(&$data, $router_item, $root_path) {

  // Create an action link on the Rooms Units admin page for adding new units.
  if ($root_path == 'admin/rooms/units') {
    $item = menu_get_item('admin/rooms/units/add');
    if ($item['access']) {
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * FORM_ID = rooms_unit_type_operation_form
 * Prevent a unit type with associated units from being deleted.
 */
function rooms_unit_form_rooms_unit_type_operation_form_alter(&$form, &$form_state, $form_id) {

  // Check if units of a unit type exist before allowing deletion.
  if ($form_state['op'] == 'delete') {
    $unit_type = $form_state['rooms_unit_type'];

    // Load the units associated with this type.
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'rooms_unit')
      ->propertyCondition('type', $unit_type->type);
    $units = $query
      ->execute();
    if (isset($units['rooms_unit']) && count($units['rooms_unit'])) {

      // This type has associated units, don't allow deletion.
      form_set_error('confirm', t('This unit type has associated units. Please delete all units before attempting to delete this unit type.'));
      unset($form['description']);
      unset($form['actions']);
      unset($form['confirm']);
    }
  }
}

/**
 * Implements hook_module_implements_alter()
 *
 * This ensures that this hook is called after entity translation's alter hook.
 */
function rooms_unit_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'form_alter' && isset($implementations['rooms_unit'])) {
    $group = $implementations['rooms_unit'];
    unset($implementations['rooms_unit']);
    $implementations['rooms_unit'] = $group;
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * FORM_ID = rooms_unit_edit_form
 */
function rooms_unit_form_rooms_unit_edit_form_alter(&$form, &$form_state) {
  if (module_exists('entity_translation')) {
    if (isset($form['translation'])) {

      // "Translation" fieldset as a vertical tab.
      $form['translation']['#group'] = 'additional_settings';
    }
  }
}

/**
 * Helper function to generate a list of available unit states for select lists.
 *
 * @return array
 *   Array of available unit states keyed by id.
 */
function rooms_unit_state_options() {
  return array(
    ROOMS_NOT_AVAILABLE => t('Unavailable'),
    ROOMS_AVAILABLE => t('Available'),
    ROOMS_ON_REQUEST => t('On Request'),
    ROOMS_ANON_BOOKED => t('Anonymous Booking'),
  );
}

/**
 * Returns the available room options given a bookable unit.
 *
 * @param RoomsUnit $unit
 *   The bookable unit to get options.
 *
 * @return array
 *   The available options for the given bookable unit.
 */
function rooms_unit_get_unit_options($unit) {
  $options =& drupal_static(__FUNCTION__);
  if (isset($options['units'][$unit->unit_id])) {
    return $options['units'][$unit->unit_id];
  }
  if (isset($options['unit_types'][$unit->type])) {
    $unit_type_options = $options['unit_types'][$unit->type];
  }
  else {
    $unit_type = rooms_unit_type_load($unit->type);
    $unit_type_options = is_array(field_get_items('rooms_unit_type', $unit_type, 'rooms_booking_unit_options')) ? field_get_items('rooms_unit_type', $unit_type, 'rooms_booking_unit_options') : array();
    $options['unit_types'][$unit->type] = $unit_type_options;
  }
  $unit_options = is_array(field_get_items('rooms_unit', $unit, 'rooms_booking_unit_options')) ? field_get_items('rooms_unit', $unit, 'rooms_booking_unit_options') : array();
  $options['units'][$unit->unit_id] = array_merge($unit_type_options, $unit_options);
  return $options['units'][$unit->unit_id];
}

/**
 * The class used for room entities
 */
class RoomsUnit extends Entity {
  public function __construct($values = array()) {
    parent::__construct($values, 'rooms_unit');
  }

  /**
   * {@inheritdoc}
   */
  protected function defaultLabel() {
    return $this->name;
  }

  /**
   * {@inheritdoc}
   */
  protected function defaultUri() {
    return array(
      'path' => 'unit/' . $this->unit_id,
    );
  }

}

/**
 * The class used for room type entities
 */
class RoomsUnitType extends Entity {

  /**
   * The Bookable unit type.
   *
   * @var string
   */
  public $type;

  /**
   * The bookable unit type label.
   *
   * @var string
   */
  public $label;
  public function __construct($values = array()) {
    parent::__construct($values, 'rooms_unit_type');
  }

}

/**
 * The Controller for RoomsUnit entities
 */
class RoomsUnitController extends EntityAPIController {
  public function __construct($entityType) {
    parent::__construct($entityType);
  }

  /**
   * Creates a bookable unit.
   *
   * @param array $values
   *   The properties for the new unit type.
   *
   * @return RoomsUnit
   *   A unit object with all default fields initialized.
   */
  public function create(array $values = array()) {
    $unit_type = rooms_unit_type_load($values['type'], TRUE);

    // Add values that are specific to our Room.
    $values += array(
      'unit_id' => '',
      'is_new' => TRUE,
      'title' => '',
      'created' => '',
      'changed' => '',
      'base_price' => isset($unit_type->data['base_price']) ? $unit_type->data['base_price'] : 0,
      'min_sleeps' => isset($unit_type->data['min_sleeps']) ? $unit_type->data['min_sleeps'] : 0,
      'max_sleeps' => isset($unit_type->data['max_sleeps']) ? $unit_type->data['max_sleeps'] : 0,
      'min_children' => isset($unit_type->data['min_children']) ? $unit_type->data['min_children'] : 0,
      'max_children' => isset($unit_type->data['max_children']) ? $unit_type->data['max_children'] : 0,
      'data' => array(
        'cot_surcharge' => isset($unit_type->data['cot_surcharge']) ? $unit_type->data['cot_surcharge'] : 0,
      ),
    );
    $unit = parent::create($values);
    return $unit;
  }

  /**
   * Overriding the buildContent function to add entity specific fields.
   */
  public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array()) {
    $content = parent::buildContent($entity, $view_mode, $langcode, $content);
    $content['state'] = array(
      '#markup' => t('State') . ': ' . $entity->bookable . '<br/>',
    );
    $content['type'] = array(
      '#markup' => t('Type') . ': ' . $entity->type . '<br/>',
    );
    $content['sleeps'] = array(
      '#markup' => t('Sleeps') . ': ' . $entity->max_sleeps . '<br/>',
    );
    if (isset($entity->data['bed_arrangement'])) {
      $content['bed_arrangement'] = array(
        '#markup' => t('Double beds') . ': ' . $entity->data['bed_arrangement']['doubles'] . '<br/>' . t('Single beds') . ': ' . $entity->data['bed_arrangement']['singles'] . '<br/>',
      );
    }
    return $content;
  }

}

/**
 * The Controller for Room entities.
 */
class RoomsUnitTypeController extends EntityAPIControllerExportable {
  public function __construct($entityType) {
    parent::__construct($entityType);
  }

  /**
   * Creates a unit type.
   *
   * @param array $values
   *   The properties for the new unit type.
   *
   * @return RoomsUnitType
   *   A unit type object with all default fields initialized.
   */
  public function create(array $values = array()) {

    // Add values that are specific to our Unit.
    $values += array(
      'id' => '',
      'is_new' => TRUE,
      'data' => '',
    );
    $unit_type = parent::create($values);
    return $unit_type;
  }

}

Functions

Namesort descending Description
rooms_unit_access Determines whether the given user has access to a bookable unit.
rooms_unit_access_filter Filters rooms unit based on permissions for multiple values.
rooms_unit_create Creates a room object.
rooms_unit_delete Deletes a bookable unit.
rooms_unit_delete_multiple Deletes multiple units.
rooms_unit_entity_info Implements hook_entity_info().
rooms_unit_entity_info_alter Implements hook_entity_info_alter().
rooms_unit_entity_insert Implements hook_entity_insert().
rooms_unit_form_rooms_unit_edit_form_alter Implements hook_form_FORM_ID_alter().
rooms_unit_form_rooms_unit_type_operation_form_alter Implements hook_form_FORM_ID_alter().
rooms_unit_get_types Gets an array of all unit types, keyed by the type name.
rooms_unit_get_unit_options Returns the available room options given a bookable unit.
rooms_unit_ids Gets a list of Units keyed by id and name in value.
rooms_unit_load Fetches a bookable unit object.
rooms_unit_load_multiple Loads multiple units based on certain conditions.
rooms_unit_menu Implements hook_menu().
rooms_unit_menu_local_tasks_alter Implements hook_menu_local_tasks_alter().
rooms_unit_module_implements_alter Implements hook_module_implements_alter()
rooms_unit_page_title Menu title callback for showing individual entities.
rooms_unit_page_view Sets up content to show an individual unit. @todo - get rid of drupal_set_title();
rooms_unit_permission Implements hook_permission().
rooms_unit_query_rooms_unit_access_alter Implements hook_query_TAG_alter().
rooms_unit_rooms_entity_access_view_condition_rooms_unit_alter Implements hook_rooms_entity_access_OP_condition_ENTITY_TYPE_alter().
rooms_unit_save Saves a unit to the database.
rooms_unit_state_options Helper function to generate a list of available unit states for select lists.
rooms_unit_theme Implements hook_theme().
rooms_unit_types_ids Helper function to easily get unit types in an array for use in forms, etc.
rooms_unit_type_access Access callback for the entity API.
rooms_unit_type_create Creates a room object.
rooms_unit_type_delete Deletes a unit type from the db.
rooms_unit_type_description_source Helper function for Unit Description autocomplete.
rooms_unit_type_load Menu argument loader; Load a unit type by string.
rooms_unit_type_save Saves a unit type to the db.
rooms_unit_uri URI callback for units.
rooms_unit_views_api Implements hook_views_api().
_rooms_unit_add_access Access callback: Checks whether the user has permission to add a unit.

Constants

Namesort descending Description
ROOMS_ANON_BOOKED
ROOMS_AVAILABLE
ROOMS_BLOCKED Defining responses for Calendar Updated.
ROOMS_NOT_AVAILABLE Defining some room states that will be used throughout.
ROOMS_ON_REQUEST
ROOMS_UNCONFIRMED_BOOKINGS
ROOMS_UPDATED
ROOMS_WRONG_UNIT

Classes

Namesort descending Description
RoomsUnit The class used for room entities
RoomsUnitController The Controller for RoomsUnit entities
RoomsUnitType The class used for room type entities
RoomsUnitTypeController The Controller for Room entities.