You are here

availability_calendars.module in Availability Calendars 6.2

Availability Calendars module. Allows for availability information to be displayed using calendars on specified content types.

Originally based on the Availability Module.

This file contains the hooks and other functions that must be present in the .module file

@author Dan Karran (geodaniel) <dan at karran dot net> @author Nicholas Alipaz (nicholas.alipaz) @author Erwin Derksen (http://drupal.org/user/750928)

File

availability_calendars.module
View source
<?php

/**
 * @file
 * Availability Calendars module. Allows for availability information to be
 * displayed using calendars on specified content types.
 *
 * Originally based on the Availability Module.
 *
 * This file contains the hooks and other functions that must be present in the .module file
 *
 * @author Dan Karran (geodaniel) <dan at karran dot net>
 * @author Nicholas Alipaz (nicholas.alipaz)
 * @author Erwin Derksen (http://drupal.org/user/750928)
 */

/**
 * Implements hook_init().
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_init/6
 * Currently just adds our css/js files to pages.
 */
function availability_calendars_init() {

  // CSS is added to all pages to allow for aggregation.
  // Base css.
  drupal_add_css(drupal_get_path('module', 'availability_calendars') . '/availability_calendars.base.css');

  // Generated CSS.
  $file = file_directory_path() . '/availability_calendars/availability_calendars.css';
  if (is_readable($file)) {
    drupal_add_css($file);
  }
}

/**
 * Implements hook_views_api().
 */
function availability_calendars_views_api() {
  return array(
    'api' => '2.0',
  );
}

/**
 * Implements hook_menu().
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_menu/6
 */
function availability_calendars_menu() {
  $items = array();
  $items['admin/settings/availability-calendars'] = array(
    'title' => 'Availability Calendars',
    'description' => 'Configure global settings for availability calendars module.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'availability_calendars_admin_settings',
    ),
    'access arguments' => array(
      'edit availability calendars',
    ),
    'file' => 'availability_calendars.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/settings/availability-calendars/settings'] = array(
    'title' => 'Settings',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/settings/availability-calendars/styling'] = array(
    'title' => 'Styling',
    'description' => 'Define CSS styles for Availability Calendars.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'availability_calendars_styles',
    ),
    'access arguments' => array(
      'edit availability calendars',
    ),
    'file' => 'availability_calendars.styles.inc',
    'type' => MENU_LOCAL_TASK,
  );
  $items['availability-calendars/%node'] = array(
    'title' => 'Availability calendar',
    'page callback' => 'availability_calendars_edit_calendar',
    'page arguments' => array(
      1,
    ),
    'access callback' => 'availability_calendars_can_edit',
    'access arguments' => array(
      1,
    ),
    'file' => 'availability_calendars.node.inc',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_perm().
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_perm/6
 */
function availability_calendars_perm() {
  return array(
    'edit own availability calendars',
    'edit availability calendars',
  );
}

/**
 * A callback function to see if user should be allowed to edit the calendar.
 *
 * @global object $user
 * @param int $nid
 * @return boolean
 */
function availability_calendars_can_edit($node) {
  $result = FALSE;
  if (user_access('edit availability calendars')) {
    $result = TRUE;
  }
  elseif (user_access('edit own availability calendars')) {
    if ($node) {
      global $user;
      $result = $user->uid == $node->uid;
    }
  }
  return $result;
}

/**
 * Implements hook_theme().
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_theme/6
 */
function availability_calendars_theme() {
  $today = getdate();
  return array(
    'availability_calendars_node' => array(
      'arguments' => array(
        'node' => NULL,
        'year' => $today['year'],
        'month' => $today['mon'],
        'settings' => NULL,
      ),
      'file' => 'availability_calendars.page.inc',
    ),
    'availability_calendars_month' => array(
      'arguments' => array(
        'node' => NULL,
        'year' => $today['year'],
        'month' => $today['mon'],
        'settings' => NULL,
      ),
      'file' => 'availability_calendars.page.inc',
    ),
    'availability_calendars_key' => array(
      'arguments' => array(),
      'file' => 'availability_calendars.page.inc',
    ),
  );
}

/**
 * Implements hook_form_alter(). Alters node edit forms for supported content types
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_form_alter/6
 */
function availability_calendars_form_alter(&$form, &$form_state, $form_id) {

  // Alter node edit form if availability support is enabled for that content type
  if (availability_calendars_override_per_node() && isset($form['type']['#value']) && $form['type']['#value'] . '_node_form' == $form_id && availability_calendars_is_supported_type($form['type']['#value'])) {
    module_load_include('inc', 'availability_calendars', 'availability_calendars.node');
    return availability_calendars_node_edit_form_alter($form, $form_state, $form_id);
  }
}

/**
 * Implements D6 hook_nodeapi(): forward to D7 hook_node_$op().
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_nodeapi/6
 */
function availability_calendars_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if (availability_calendars_is_supported_type($node->type)) {
    switch ($op) {
      case 'view':
        availability_calendars_node_view($node, $a3 ? 'teaser' : 'full');
        break;
      case 'insert':
        availability_calendars_node_insert($node);
        break;
      case 'update':
        availability_calendars_node_update($node);
        break;
      case 'delete':
        availability_calendars_node_delete($node);
        break;
    }
  }
}

/**
 * Implements D7 hook_node_view.
 * @see http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_node_view/7
 */
function availability_calendars_node_view($node, $view_mode = 'full', $langcode = NULL) {
  if (availability_calendars_is_supported_type($node->type)) {
    module_load_include('inc', 'availability_calendars', 'availability_calendars.page');
    availability_calendars_page_node_view($node, $view_mode);
  }
}

/**
 * Implements D7 hook_node_insert.
 * @see http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_node_insert/7
 */
function availability_calendars_node_insert($node) {
  if (availability_calendars_override_per_node() && availability_calendars_is_supported_type($node->type)) {
    module_load_include('inc', 'availability_calendars', 'availability_calendars.node');
    availability_calendars_save_node_settings($node);
  }
}

/**
 * Implements D7 hook_node_update.
 * @see http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_node_update/7
 */
function availability_calendars_node_update($node) {
  if (availability_calendars_override_per_node() && availability_calendars_is_supported_type($node->type)) {
    module_load_include('inc', 'availability_calendars', 'availability_calendars.node');
    availability_calendars_save_node_settings($node);
  }
}

/**
 * Implements D7 hook_node_delete.
 * @see http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_node_delete/7
 */
function availability_calendars_node_delete($node) {
  if (availability_calendars_is_supported_type($node->type)) {
    module_load_include('inc', 'availability_calendars', 'availability_calendars');
    availability_calendars_delete_node($node->nid);
  }
}

/**
 * Implements D6 hook_block(): forward to D7 hook_block_$op().
 * Generates a block for the legend that can be shown when on availability calendar nodes.
 * @see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_block/6
 */
function availability_calendars_block($op = 'list', $delta = 0, $edit = array()) {

  // The $op parameter determines what piece of information is being requested.
  switch ($op) {
    case 'list':
      return availability_calendars_block_info();
    case 'view':
      return availability_calendars_block_view($delta);
  }
}

/**
 * Implements D7 hook_block_info().
 * @see http://api.drupal.org/api/drupal/modules--block--block.api.php/function/hook_block_info/7
 */
function availability_calendars_block_info() {
  $blocks = array(
    'key' => array(
      'info' => t('Availability Calendar Key'),
      'cache' => BLOCK_CACHE_GLOBAL,
    ),
  );
  return $blocks;
}

/**
 * Implements D7 hook_block_view().
 * @see http://api.drupal.org/api/drupal/modules--block--block.api.php/function/hook_block_view/7
 */
function availability_calendars_block_view($delta = '') {
  if ($delta == 'key') {
    $block = array(
      'subject' => t('Availability Key'),
      'content' => theme('availability_calendars_key'),
    );
    return $block;
  }
}

/**
 * Indicates whether overriding settings on a per node basis is allowed.
 *
 * @return boolean
 */
function availability_calendars_override_per_node() {
  return variable_get('availability_calendars_settings_system_pernodeoverride', 0) != 0;
}

/**
 * Indicates whether the given content type supports availability calendars.
 *
 * @param string $type
 * @return boolean
 */
function availability_calendars_is_supported_type($type) {
  return in_array($type, variable_get('availability_calendars_settings_content_types', array()));
}

Functions

Namesort descending Description
availability_calendars_block Implements D6 hook_block(): forward to D7 hook_block_$op(). Generates a block for the legend that can be shown when on availability calendar nodes.
availability_calendars_block_info Implements D7 hook_block_info().
availability_calendars_block_view Implements D7 hook_block_view().
availability_calendars_can_edit A callback function to see if user should be allowed to edit the calendar.
availability_calendars_form_alter Implements hook_form_alter(). Alters node edit forms for supported content types
availability_calendars_init Implements hook_init(). Currently just adds our css/js files to pages.
availability_calendars_is_supported_type Indicates whether the given content type supports availability calendars.
availability_calendars_menu Implements hook_menu().
availability_calendars_nodeapi Implements D6 hook_nodeapi(): forward to D7 hook_node_$op().
availability_calendars_node_delete Implements D7 hook_node_delete.
availability_calendars_node_insert Implements D7 hook_node_insert.
availability_calendars_node_update Implements D7 hook_node_update.
availability_calendars_node_view Implements D7 hook_node_view.
availability_calendars_override_per_node Indicates whether overriding settings on a per node basis is allowed.
availability_calendars_perm Implements hook_perm().
availability_calendars_theme Implements hook_theme().
availability_calendars_views_api Implements hook_views_api().