You are here

function webform_views_data in Webform 7.4

Same name and namespace in other branches
  1. 6.3 views/webform.views.inc \webform_views_data()
  2. 7.3 views/webform.views.inc \webform_views_data()

Implements hook_views_data().

File

views/webform.views.inc, line 11
Views hooks implemented for the Webform module.

Code

function webform_views_data() {

  // Webform table definitions.
  $data['webform']['table']['group'] = t('Webform');
  $data['webform']['table']['base'] = array(
    'field' => 'nid',
    'title' => t('Webform nodes'),
    'help' => t('Nodes which have webforms.'),
  );
  $data['webform']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'nid',
      'type' => 'INNER',
    ),
  );

  // NID.
  $data['webform']['nid'] = array(
    'title' => t('Node'),
    'help' => t('The node this webform is part of.'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Node for webform'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_node_nid',
      // The field to display in the summary.
      'name field' => 'title',
      'numeric' => TRUE,
      'validate type' => 'nid',
    ),
  );

  // Status.
  $data['webform']['status'] = array(
    'title' => t('Status'),
    'help' => t('The open or closed status of a webform.'),
    'field' => array(
      'handler' => 'webform_handler_field_webform_status',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'label' => t('Status'),
      'handler' => 'webform_handler_filter_webform_status',
      'type' => 'open-closed',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Submissions table definitions.
  $data['webform_submissions']['table']['group'] = t('Webform submissions');
  $data['webform_submissions']['table']['base'] = array(
    'field' => 'sid',
    'title' => t('Webform submissions'),
    'help' => t('Submissions generated from Webform forms.'),
  );

  // Serial number.
  $data['webform_submissions']['serial'] = array(
    'title' => t('Serial number'),
    'help' => t('The serial number of the submission.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Serial number'),
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  // SID.
  $data['webform_submissions']['sid'] = array(
    'title' => t('Sid'),
    'help' => t('The submission ID of the submission.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Sid'),
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  // Submission data as a field loads the entire submission.
  $data['webform_submissions']['value'] = array(
    'title' => t('Value'),
    'help' => t('The value of a component as submitted by a user.'),
    'real field' => 'sid',
    'group' => t('Webform submission data'),
    'field' => array(
      'handler' => 'webform_handler_field_submission_data',
      'webform_expand' => FALSE,
      'click sortable' => TRUE,
    ),
  );

  // Expanded to generate a field for every viewable component.
  $data['webform_submissions']['webform_all_fields'] = array(
    'title' => t('All values'),
    'help' => t('Displays all values as submitted by a user.'),
    'real field' => 'sid',
    'group' => t('Webform submission data'),
    'field' => array(
      'handler' => 'webform_handler_field_submission_data',
      'webform_expand' => TRUE,
      'click sortable' => TRUE,
    ),
  );

  // NID.
  $data['webform_submissions']['nid'] = array(
    'title' => t('Node'),
    'help' => t('The webform node this submission was generated from.'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Webform Node'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_node_nid',
      // The field to display in the summary.
      'name field' => 'title',
      'numeric' => TRUE,
      'validate type' => 'nid',
    ),
  );

  // UID.
  $data['webform_submissions']['uid'] = array(
    'title' => t('User'),
    'help' => t('The user who sent the webform submission.'),
    'relationship' => array(
      'base' => 'users',
      'field' => 'uid',
      'handler' => 'views_handler_relationship',
      'label' => t('Webform Submission User'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_user_name',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'field' => array(
      'handler' => 'views_handler_field_user',
    ),
  );

  // Is draft.
  $data['webform_submissions']['is_draft'] = array(
    'title' => t('Draft'),
    'help' => t('Whether or not the submission is a draft.'),
    'field' => array(
      'handler' => 'webform_handler_field_is_draft',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'webform_handler_filter_is_draft',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Submitted timestamp.
  $data['webform_submissions']['submitted'] = array(
    'title' => t('Submitted'),
    'help' => t('Timestamp when the form was first saved as draft or submitted.'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Submitted'),
      'handler' => 'views_handler_filter_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_date',
    ),
  );

  // Completed timestamp.
  $data['webform_submissions']['completed'] = array(
    'title' => t('Completed'),
    'help' => t('Timestamp when the form was submitted as complete (not draft).'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Completed'),
      'handler' => 'views_handler_filter_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_date',
    ),
  );

  // Modified timestamp.
  $data['webform_submissions']['modified'] = array(
    'title' => t('Modified'),
    'help' => t('Timestamp when the form was last saved (complete or draft).'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Modified'),
      'handler' => 'views_handler_filter_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_date',
    ),
  );

  // IP Address (remote_addr).
  $data['webform_submissions']['remote_addr'] = array(
    'title' => t('Remote address'),
    'help' => t('The remote IP address of the user that submitted this submission.'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'title' => t('Remote address'),
      'handler' => 'views_handler_filter_string',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // View submission link.
  $data['webform_submissions']['view_submission'] = array(
    'title' => t('View link'),
    'help' => t('Provide a simple link to view the submission.'),
    'real field' => 'serial',
    'field' => array(
      'handler' => 'webform_handler_field_submission_link',
      'click sortable' => TRUE,
      'real field' => 'serial',
      'link_type' => 'view',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Edit submission link.
  $data['webform_submissions']['edit_submission'] = array(
    'title' => t('Edit link'),
    'help' => t('Provide a simple link to edit the submission.'),
    'real field' => 'serial',
    'field' => array(
      'handler' => 'webform_handler_field_submission_link',
      'click sortable' => TRUE,
      'link_type' => 'edit',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Delete submission link.
  $data['webform_submissions']['delete_submission'] = array(
    'title' => t('Delete link'),
    'help' => t('Provide a simple link to delete the submission.'),
    'real field' => 'serial',
    'field' => array(
      'handler' => 'webform_handler_field_submission_link',
      'click sortable' => TRUE,
      'link_type' => 'delete',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Relation to webform_submitted_data table.
  $data['webform_submissions']['data'] = array(
    'title' => t('Data'),
    'help' => t('Relates to a webform submission data'),
    'real field' => 'sid',
    'relationship' => array(
      'handler' => 'webform_handler_relationship_submission_data',
      'base' => 'webform_submitted_data',
      'base field' => 'sid',
      'label' => t('Submission Data'),
    ),
  );

  // Submission data table definitions.
  $data['webform_submitted_data']['table']['group'] = t('Webform submission data');

  // Raw access to the submitted values. This usually will only be used for
  // sorts and filters, since the 'value' field for the submission will often
  // be faster and easier to configure than the raw values.
  $data['webform_submitted_data']['data'] = array(
    'table' => 'webform_submitted_data',
    'title' => t('Data field'),
    'help' => t('The value of a component as submitted by a user.'),
    'real field' => 'data',
    'field' => array(
      // Distinguish from the normal value handler.
      'title' => t('Value (raw)'),
      'help' => t('The raw value from the database as submitted by a user. Use only when needing to sort on a field value.'),
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'filter' => array(
      'handler' => 'webform_handler_filter_submission_data',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Same as 'data', but handled as numeric data.
  $data['webform_submitted_data']['data_numeric'] = array(
    'table' => 'webform_submitted_data',
    'title' => t('Data field (numeric)'),
    'help' => t('The numeric value of a component as submitted by a user.'),
    'real field' => 'data',
    'field' => array(
      // Distinguish from the normal value handler.
      'title' => t('Numeric value (raw)'),
      'help' => t('The raw value from the database, cast to a number, as submitted by a user. Use only when needing to sort on a field value.'),
      'handler' => 'webform_handler_field_numeric_data',
      'click sortable' => TRUE,
      'float' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'webform_handler_filter_numeric_data',
    ),
    'sort' => array(
      'handler' => 'webform_handler_sort_numeric_data',
    ),
  );

  // Number field for multi-value fields.
  $data['webform_submitted_data']['no'] = array(
    'title' => t('Value delta'),
    'help' => t('The delta value of the submitted data in a multi value component (such as checkboxes).'),
    'real field' => 'no',
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  return $data;
}