<?php
/**
 * @file
 * Functions to expose storm dok module data to views
 */
function stormdok_views_data() {
  $data['stormdok']['table']['group']  = t('SuiteDesk Dok');
  $data['stormdok']['table']['join'] = array(
    'node' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
  );

  $data['stormdok']['organization_nid'] = array(
    'title' => t('Organization'),
    'help' => t('Dok -> Organization'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Dok -> Organization'),
    ),
  );

  $data['stormdok']['organization_title'] = array(
    'title' => t('Organization'),
    'help' => t('SuiteDesk Dok Organization (title only)'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['stormdok']['project_nid'] = array(
    'title' => t('Project'),
    'help' => t('Dok -> Project'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Dok -> Project'),
    ),
  );

  $data['stormdok']['project_title'] = array(
    'title' => t('Project'),
    'help' => t('SuiteDesk Dok Project (title only)'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['stormdok']['task_nid'] = array(
    'title' => t('Task'),
    'help' => t('Dok -> Task'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Dok -> Task'),
    ),
  );

  $data['stormdok']['task_stepno'] = array(
    'title' => t('Task step number'),
    'help' => t('SuiteDesk Dok Task Step Number'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['stormdok']['task_title'] = array(
    'title' => t('Task'),
    'help' => t('SuiteDesk Dok Task (title only)'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['stormdok']['operation'] = array(
    'field' => array(
      'title' => t('Edit/Delete link'),
      'help' => t('Provide a simple link to edit and delete the node.'),
      'handler' => 'storm_handler_field_operation',
      'type' => 'stormdok',
    ),
  );

  return $data;
}

function stormdok_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'storm'),
    ),
    'handlers' => array(
      'storm_handler_filter_attributes_domain' => array(
        'parent' => 'views_handler_filter_in_operator',
      ),
      'storm_handler_field_operation' => array(
        'parent' => 'views_handler_field_node_link',
        'path' => drupal_get_path('module', 'storm'),
      ),
    ),
  );
}
