You are here

function og_views_tables in Organic groups 5

Same name and namespace in other branches
  1. 5.8 og_views.inc \og_views_tables()
  2. 5.2 og_views.inc \og_views_tables()
  3. 5.3 og_views.inc \og_views_tables()
  4. 5.7 og_views.inc \og_views_tables()

Implementation of the hook_views_tables()

File

./og_views.inc, line 6

Code

function og_views_tables() {
  $languages = module_invoke('locale', 'supported_languages', FALSE, TRUE);
  $group_post_type_options = $group_type_options = array();
  foreach (og_get_types('group') as $type) {
    $group_type_options[$type] = node_get_types('name', $type);
  }
  foreach (og_get_types('group_post') as $type) {
    $group_post_type_options[$type] = node_get_types('name', $type);
  }
  return array(
    'og' => array(
      'name' => 'og',
      'join' => array(
        'left' => array(
          'table' => 'node',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
      ),
      'fields' => array(
        'description' => array(
          'name' => t('OG: Group: Description'),
        ),
        'count' => array(
          'name' => t('OG: Group: Members count'),
          'handler' => 'og_handler_field_count',
          'help' => t('Number of members for a group. Excludes memberships which are pending approval.'),
          'sortable' => FALSE,
          'notafield' => TRUE,
        ),
        'post_count' => array(
          'name' => t('OG: Group: Post count'),
          'handler' => 'og_handler_post_count',
          'sortable' => FALSE,
          'notafield' => TRUE,
          'help' => t('Number of published posts in a group. Can be restricted by node type using the <em>Option</em> dropdown.'),
          'option' => array(
            '#type' => 'select',
            '#options' => array_merge(array(
              'all' => t('All'),
            ), $group_post_type_options),
            '#default_value' => 'all',
          ),
        ),
        'post_count_new' => array(
          'name' => t('OG: Group: Post count *new*'),
          'handler' => 'og_handler_post_count_new',
          'sortable' => FALSE,
          'notafield' => TRUE,
          'help' => t('Number of new posts in a group for the current user. The <em>new</em> indicator may be optionally appended using the <em>Option</em> dropdown.'),
          'option' => array(
            '#type' => 'select',
            '#options' => array(
              'normal' => t('Normal'),
              'withmark' => t('With new mark'),
            ),
          ),
        ),
        'selective' => array(
          'name' => t('OG: Group: Selective'),
        ),
        'private' => array(
          'name' => t('OG: Group: Private'),
        ),
        'subscribe' => array(
          'name' => t('OG: Group: Join Link'),
          'handler' => 'og_handler_field_subscribe',
          'addlfields' => array(
            'selective',
          ),
          'sortable' => FALSE,
          'notafield' => TRUE,
          'help' => t('Displays a links for joining a group when a user is not already a member.'),
        ),
        'notification' => array(
          'name' => t('OG: Group: Notification'),
          'handler' => 'og_handler_field_yesempty',
          'help' => t('Displays <em>yes</em> if group automatically sends email notifications to members'),
        ),
        'language' => array(
          'name' => t('OG: Group: Language'),
          'handler' => 'og_handler_field_language',
          'sortable' => TRUE,
          'help' => t('Displays the language selected for a given group.'),
        ),
      ),
      'filters' => array(
        'directory' => array(
          'name' => t('OG: Group: List in directory'),
          'operator' => array(
            '=' => 'Is',
          ),
          'list' => 'views_handler_operator_yesno',
          'list-type' => 'select',
          'help' => t('Admin specifies whether or not a group appears in the public listings.'),
        ),
        'private' => array(
          'name' => t('OG: Group: Private'),
          'operator' => array(
            '=' => 'Is',
          ),
          'list' => 'views_handler_operator_yesno',
          'list-type' => 'select',
          'help' => t('Is the group home page private or not.'),
        ),
        'selective' => array(
          'name' => t('OG: Group: Selective'),
          'operator' => 'views_handler_operator_or',
          'list-type' => 'list',
          'list' => array(
            OG_OPEN => t('Open'),
            OG_MODERATED => t('Moderated'),
            OG_INVITE_ONLY => t('Invite Only'),
            OG_CLOSED => t('Closed'),
          ),
          'help' => t('The group preference which determines how membership requests are managed (moderated, invite only, etc.).'),
        ),
        'language' => array(
          'name' => t('OG: Group: Language'),
          'operator' => 'views_handler_operator_andor',
          'option' => 'string',
          'value-type' => 'array',
          'value' => array(
            '#type' => 'select',
            '#options' => $languages['name'],
            '#multiple' => TRUE,
          ),
          'help' => t('Restrict groups to specific languages.'),
        ),
      ),
    ),
    'og_ancestry' => array(
      'name' => 'og_ancestry',
      'join' => array(
        'left' => array(
          'table' => 'node',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
      ),
      'filters' => array(
        'gid' => array(
          'name' => t('OG: Post in specified group (by number)'),
          'handler' => 'og_handler_filter_gid',
          'operator' => array(
            '=' => 'Is',
          ),
          'help' => t('Filter for posts in specified organic groups. <em>Value</em> should be a one or more node ids (i.e. integers), separated by commas or pluses. Like taxonomy, pluses indicate that the post must appear in one of the specified groups, whereas commas indicate that the post must appear in every specified group. The page context (if View is a page) will be set to the first listed group. That means that blocks and breadcrumbs (and theme and locale, if applicable) will be based upon the first specified node id.'),
        ),
        'group_name_like' => array(
          // this filter does not set any context because i am delegating filtering to built
          // in views like handler. i can't easily learn which groups matched later.
          'name' => t('OG: Post in specified groups (by name)'),
          'handler' => 'og_handler_filter_group_name_like',
          'operator' => 'views_handler_operator_like',
          'help' => t('Filter for posts in specified organic groups. Value should be a one or more group names (partial name is supported), separated by commas or pluses. Like taxonomy, pluses indicate that the post must appear in one of the specified groups, whereas commas indicate that the post must appear in every specified group. The page context is <strong>not</strong> be set the the first specified group (unfortunately, you must use <em>OG: Post in specified group (by number)</em> for that).'),
        ),
        'gtype' => array(
          'name' => t('OG: Post in specified group type'),
          'list' => $group_type_options,
          'list-type' => 'list',
          'operator' => 'views_handler_operator_or',
          'value-type' => 'array',
          'field' => 'group_nid',
          'handler' => 'og_handler_filter_post_og_type',
          'help' => t('Filter for a given organic group type.'),
        ),
        'picg' => array(
          'name' => t('OG: Posts in current group'),
          'help' => t('Posts in current group. Useful for blocks where determining context is hard. If page is not in any group context, no nodes are listed and thus a block would not appear.'),
          'operator' => 'views_handler_operator_eqneq',
          'list' => 'views_handler_filter_groupcurrent',
          'list-type' => 'select',
          'handler' => 'og_handler_filter_picg',
        ),
        'is_public' => array(
          'name' => t('OG: Public'),
          'help' => t('Posts marked as Public, which are viewable by non group members as well.'),
          'operator' => array(
            '=' => t('Is'),
          ),
          'list' => 'views_handler_operator_yesno',
          'list-type' => 'select',
          'field' => 'is_public',
          'handler' => 'og_handler_filter_public',
        ),
      ),
      'fields' => array(
        'is_public' => array(
          'name' => t('OG: Public'),
          'handler' => 'og_handler_field_yesempty',
          'help' => t('Displays <em>yes</em> if post is public according to OG.'),
        ),
      ),
    ),
    'og_node_data' => array(
      'name' => 'node',
      'join' => array(
        'left' => array(
          'table' => 'og_ancestry',
          'field' => 'group_nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
      ),
      'fields' => array(
        'title' => array(
          'name' => t('OG: Group names'),
          'handler' => 'og_handler_field_nodelink',
          'notafield' => TRUE,
          'help' => t('Display links to any groups that are affiliated with a post.'),
        ),
      ),
    ),
    'og_uid' => array(
      'name' => 'og_uid',
      'join' => array(
        'left' => array(
          'table' => 'node',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
        'extra' => array(
          'is_active' => 1,
        ),
      ),
      'fields' => array(
        'mail_type' => array(
          'name' => t('OG: Subscription email'),
          'handler' => 'og_handler_field_yesempty',
          'sortable' => false,
          'help' => t('Does member receive email notifications for a group.'),
        ),
        'managelink' => array(
          'name' => t('OG: Manage membership link'),
          'handler' => 'og_handler_field_managelink',
          'sortable' => FALSE,
          'notafield' => TRUE,
        ),
        'is_admin' => array(
          'name' => t('OG: Is member an admin in a group'),
          'handler' => 'og_handler_field_yesempty',
          'sortable' => FALSE,
        ),
      ),
      'filters' => array(
        'currentuidsimple' => array(
          'field' => 'uid',
          'name' => t("OG: Group in user's groups"),
          'operator' => 'views_handler_operator_eqneq',
          'list' => 'views_handler_filter_usercurrent',
          'list-type' => 'select',
          'help' => t('Groups are filtered to where current user is a member.'),
        ),
      ),
    ),
    'og_uid_node' => array(
      'name' => 'og_uid',
      'join' => array(
        'left' => array(
          'table' => 'og_node_data',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
        'extra' => array(
          'is_active' => 1,
        ),
      ),
      'filters' => array(
        'currentuid' => array(
          'field' => 'uid',
          'name' => t('OG: Post in User Subbed Groups'),
          'operator' => 'views_handler_operator_eqneq',
          'list' => 'views_handler_filter_usercurrent',
          'list-type' => 'select',
          'help' => t('Posts are filtered to groups that current user is a member of.'),
        ),
      ),
    ),
    // pseudotable for adding filter on node table and eventually more
    'og_views' => array(
      'name' => 'node',
      'join' => array(
        'left' => array(
          'table' => 'node',
          'field' => 'nid',
        ),
        'right' => array(
          'field' => 'nid',
        ),
      ),
      // here's a filter that is limited to og content types to be used for exposed filters that should not contain other values
      'filters' => array(
        'og_type_selector' => array(
          'field' => 'type',
          'name' => t('OG: node type (selector)'),
          'list' => $group_type_options,
          'list-type' => 'list',
          'operator' => 'views_handler_operator_or',
          'value-type' => 'array',
          'help' => t('A node type selector that is limited to og-enabled node types. Use as exposed filter that only contains og node types.'),
        ),
        'og_type' => array(
          'field' => 'type',
          'name' => t('OG: type'),
          'operator' => array(
            '=' => t('Is'),
          ),
          'list' => array(
            'a group node',
          ),
          'list-type' => 'select',
          'handler' => 'og_handler_filter_og_type',
          'help' => t('Restrict to node types which have been designated behave as groups.'),
        ),
      ),
    ),
  );
}