<?php

/**
 * @file
 * Notify Views Integration provides integartion with the Views module.
 *
 * Tells the Views module about the Notify database so you can create
 * listings of users by Notify subscriptions status for export or
 * administration.
 */

/**
 * Implements hook_help().
 */
function notify_viewsintegration_help($path, $arg) {
  switch ($path) {
    case 'admin/help#notify_viewsintegration':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This submodule of <strong>Notify</strong> provides integration with the Views module.') . '</p>';
      $output .= '<p>' . t('It tells the Views module about the Notify database so you can create listings of users by Notify subscriptions status for export or administration.') . '</p>';
      $output .= '<p>' . t('There is no configuration page for this submodule.  Simply create a view of type <em>User</em> and you\'ll see that under <em>Fields</em> and <em>Filters</em> there are additional options under the category <em>Notify.</em>') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_views_api().
 */
function notify_viewsintegration_views_api() {
  return array('api' => 3);
}

/**
 * Implements hook_views_data().
 */
function notify_viewsintegration_views_data() {
  
  $data = array();

  $data['notify'] = array(
    // Table info.
    'table' => array(
      'group' => t('Notify'),
      'base' => array(
        'field' => 'uid',
        'title' => t('Notify'),
        'help' => t('This isn\'t really used. Create a view of \'Users\' and you\'ll see a new field and filter group called \'Notify.\'.'),
        'weight' => 0,
      ),
    ),
  );

  $data['notify']['uid'] = array(
    'title' => t('UID'),
    'help' => t('The ID of the user'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  $data['notify']['status'] = array(
    'title' => t('Master switch status'),
    'help' => t('Set to “1” for enabled,  “0” or blank for disabled.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
	  'filter' => array(
	    'handler' => 'views_handler_filter_numeric',
	  ),
  );

  $data['notify']['node'] = array(
    'title' => t('New content'),
    'help' => t('Set to “1” for enabled,  “0” or blank for disabled.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
	  'filter' => array(
	    'handler' => 'views_handler_filter_numeric',
	  ),
  );

  $data['notify']['comment'] = array(
    'title' => t('New comments'),
    'help' => t('Set to “1” for enabled,  “0” or blank for disabled.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
	  'filter' => array(
	    'handler' => 'views_handler_filter_numeric',
	  ),
  );

  $data['notify']['attempts'] = array(
    'title' => t('Number of failed attempts'),
    'help' => t('Indicates whether there has been any failed sends for this user.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
	  'filter' => array(
	    'handler' => 'views_handler_filter_numeric',
	  ),
  );

  $data['notify']['teasers'] = array(
    'title' => t('How much to notify about'),
    'help' => t('Set to: “0” for Title only,  “1” for Title + Teaser,  “2” for Title + Body,  “3” for Title + Body + Fields.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
	  'filter' => array(
	    'handler' => 'views_handler_filter_numeric',
	  ),
  );


  $data['notify']['table']['join'] = array(
    'users' => array(
      'table' => 'notify',
      'left_field' => 'uid',
      'field' => 'uid',
      'left_table' => 'users',
    ),
  );

  
  return $data;
}
