You are here

function activity_views_data in Activity 7

Same name and namespace in other branches
  1. 8 activity.views.inc \activity_views_data()
  2. 6.2 views/activity.views.inc \activity_views_data()
  3. 6 activity.views.inc \activity_views_data()

Implementation of hook_views_data().

File

views/activity.views.inc, line 10
: provides views data integration for activity module as the base table

Code

function activity_views_data() {
  $data['activity']['table']['group'] = t('Activity');
  $data['activity']['table']['base'] = array(
    'field' => 'aid',
    'title' => t('Activity'),
    'help' => t('Activity are items that are recorded for a users activity within the site'),
  );

  // Database columns
  $data['activity']['aid'] = array(
    'title' => t('Activity Unique ID'),
    'help' => t('The unique id for each activity'),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['activity']['uid'] = array(
    'title' => t('Activity Actor'),
    'help' => t('The ID of the person who recorded the activity'),
    'argument' => array(
      'handler' => 'views_handler_argument_user_uid',
    ),
    'filter' => array(
      'title' => t('Name'),
      'handler' => 'views_handler_filter_user_name',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['activity']['type'] = array(
    'title' => t('Type'),
    'help' => t('The hook that generated the Activity'),
    'field' => array(
      'handler' => 'activity_views_handler_field_type',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_in_operator',
      'options callback' => 'activity_form_options_hooks',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );
  $data['activity']['created'] = array(
    'title' => t('Activity Creation Date'),
    'help' => t('The time that the activity was created'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
  );
  $data['activity']['status'] = array(
    'title' => t('Published'),
    'help' => t('Whether or not the activity is published'),
    'field' => array(
      'handler' => 'views_handler_field_boolean',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_boolean_operator',
      'label' => t('Published'),
      'type' => 'yes-no',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['activity']['actions_id'] = array(
    'title' => t('Template'),
    'help' => t('The template that produced the message'),
    'filter' => array(
      'handler' => 'activity_views_handler_filter_actions_id',
    ),
  );
  $data['activity_access']['table']['group'] = t('Activity Access');
  $data['activity_access']['table']['join'] = array(
    'activity' => array(
      // We cannot guarantee that there is activity_access records.
      'type' => 'LEFT',
      'left_field' => 'aid',
      'field' => 'aid',
    ),
  );

  // Create a fake table that tells Views how to join to the actions table for
  // the label.
  $data['activity_actions']['table'] = array(
    'group' => t('Activity'),
    'join' => array(
      'activity' => array(
        'type' => 'INNER',
        'field' => 'aid',
        'left_field' => 'actions_id',
        'table' => 'actions',
      ),
    ),
  );
  $data['activity_actions']['label'] = array(
    'title' => t('Activity Label'),
    'help' => t('Label assigned by the admin to this template'),
    'field' => array(
      'handler' => 'views_handler_field',
    ),
  );

  // Sets the context accound for all access filters going forward
  $data['activity_access']['context_user'] = array(
    'title' => t('Activity Context User'),
    'help' => t('This sets Activity User context so all the access filters can key off of it'),
    'argument' => array(
      'handler' => 'activity_views_handler_argument_activity_user',
    ),
  );
  $data['activity_access']['access_filter'] = array(
    'title' => t('Access Filters'),
    'help' => t('Applies Activity Access control based on the selected realms for the current user'),
    'filter' => array(
      'handler' => 'activity_views_handler_filter_access',
      'options callback' => 'activity_realm_options',
    ),
  );

  // describe the targets table so Views knows how to join it in
  // this table will be used to join the activity table to the message table
  $data['activity_targets']['table'] = array(
    'group' => t('Activity'),
    'join' => array(
      'activity' => array(
        'type' => 'INNER',
        'left_field' => 'aid',
        'field' => 'aid',
        'extra' => array(
          array(
            'value' => 0,
            // grab the non-personal message
            'numeric' => TRUE,
            'field' => 'uid',
          ),
          array(
            'value' => '***CURRENT_LANGUAGE***',
            'field' => 'language',
          ),
        ),
      ),
    ),
  );

  // describe the personal targets table so Views knows how to join it in
  // this table will be used to join the activity table to the personal message table
  $data['activity_personal_targets']['table'] = array(
    'group' => t('Activity'),
    'join' => array(
      'activity' => array(
        'type' => 'LEFT',
        'left_field' => 'aid',
        'field' => 'aid',
        'extra' => array(
          array(
            'value' => '***CURRENT_USER***',
            // grab the personal message
            'numeric' => TRUE,
            'field' => 'uid',
          ),
          array(
            'value' => '***CURRENT_LANGUAGE***',
            'field' => 'language',
          ),
        ),
        'table' => 'activity_targets',
      ),
    ),
  );

  // add in the activity message table
  $data['activity_messages']['table']['group'] = t('Activity');
  $data['activity_messages']['table']['join'] = array(
    'activity' => array(
      'left_table' => 'activity_targets',
      'left_field' => 'amid',
      'field' => 'amid',
      'type' => 'INNER',
    ),
  );

  // create a faux table, that is really activity messages
  $data['activity_personal_messages']['table']['join'] = array(
    'activity' => array(
      'left_table' => 'activity_personal_targets',
      'left_field' => 'amid',
      'field' => 'amid',
      'type' => 'LEFT',
      'table' => 'activity_messages',
    ),
  );
  $data['activity_messages']['message'] = array(
    'title' => t('Message'),
    'help' => t('The message may or may not be personalized for the user. Just depends on if the user was involved in the Action'),
    'field' => array(
      'handler' => 'activity_views_handler_field_message',
    ),
  );

  // Links to operate upon the activity records
  $data['activity']['delete_activity'] = array(
    'field' => array(
      'title' => t('Delete link'),
      'help' => t('Provide a simple link to delete the activity.'),
      'handler' => 'activity_views_handler_field_activity_link_delete',
      'real field' => 'aid',
    ),
  );

  // Relationships to other base tables
  $data['activity']['nid']['relationship'] = array(
    'group' => t('Activity'),
    'title' => t('Node'),
    'help' => t('Join the node table to the Activity table'),
    'handler' => 'views_handler_relationship',
    'base' => 'node',
    'base field' => 'nid',
    'label' => t('Node'),
  );
  $data['activity']['uid']['relationship'] = array(
    'group' => t('Activity'),
    'title' => t('User'),
    'help' => t('Join the users table to the Activity table'),
    'handler' => 'views_handler_relationship',
    'base' => 'users',
    'base field' => 'uid',
    'label' => t('User'),
  );
  return $data;
}