You are here

function uc_webform_views_data in Ubercart Webform Integration 7

@file Provide views data and handlers for uc_webform.module

File

views/uc_webform.views.inc, line 7
Provide views data and handlers for uc_webform.module

Code

function uc_webform_views_data() {
  $group = t('Ubercart Webform submissions');
  $data['uc_webform']['table']['group'] = t('Ubercart Webform');
  $data['uc_webform']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'nid',
    ),
  );
  $data['uc_webform']['webform_nid'] = array(
    'title' => t('Webform Nid'),
    'help' => t('The node ID of a webform associated with a node.'),
    // The help that appears on the UI,
    // Information for displaying the nid
    'field' => array(
      'handler' => 'views_handler_field_node',
      'click sortable' => TRUE,
    ),
    // Information for accepting a nid as an argument
    'argument' => array(
      'handler' => 'views_handler_argument_node_nid',
      'name field' => 'title',
      // the field to display in the summary.
      'numeric' => TRUE,
      'validate type' => 'nid',
    ),
    // Information for accepting a nid as a filter
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    // Information for sorting on a nid.
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['uc_webform_submission']['table']['group'] = $group;
  $data['uc_webform_submission']['table']['join'] = array(
    'webform_submissions' => array(
      'left_field' => 'sid',
      'field' => 'sid',
    ),
  );
  $data['uc_webform_submission']['order_id'] = array(
    'title' => t('Submission Order Id'),
    'base' => 'webform_submissions',
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Submission Order Id'),
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'relationship' => array(
      'base' => 'uc_orders',
      'field' => 'order_id',
    ),
  );
  $fields = array(
    'first_name' => t('First name'),
    'last_name' => t('Last name'),
    'phone' => t('Phone number'),
    'company' => t('Company'),
    'street1' => t('Street address 1'),
    'street2' => t('Street address 2'),
    'city' => t('City'),
    'postal_code' => t('Postal code'),
  );
  $prefix = 'application';
  $address = t('Application Information');
  foreach ($fields as $field => $label) {
    $data['uc_webform_submission'][$prefix . '_' . $field] = array(
      'group' => $group,
      'title' => $label,
      'help' => t('The !field of the !address of the order.', array(
        '!field' => strtolower($label),
        '!address' => strtolower($address),
      )),
      'field' => array(
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
      ),
    );
  }
  $data['uc_webform_submission'][$prefix . '_full_name'] = array(
    'group' => $group,
    'title' => t('Full name'),
    'help' => t('The !field of the !address of the order.', array(
      '!field' => t('full name'),
      '!address' => strtolower($address),
    )),
    'field' => array(
      'additional fields' => array(
        $prefix . '_first_name',
        $prefix . '_last_name',
      ),
      'handler' => 'uc_order_handler_field_order_fullname',
      'prefix' => $prefix,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
  );
  return $data;
}