function flag_views_tables in Flag 5
Implementation of hook_views_tables
File
- includes/
flag.views.inc, line 11 - Provides support for the Views module.
Code
function flag_views_tables() {
$flags = flag_get_flags('node');
// Views 1.x supports only nodes.
foreach ($flags as $flag) {
$table = array(
'name' => 'flag_content',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'content_id',
),
'extra' => array(
'fid' => $flag->fid,
),
),
'fields' => array(
'timestamp' => array(
'name' => t('Flag: @s Flagged Time', array(
'@s' => $flag
->get_title(),
)),
'sortable' => TRUE,
'handler' => views_handler_field_dates(),
'option' => 'string',
'help' => t('Display the time the node was flagged by a user.') . ' ' . t('The option field may be used to specify the custom date format as it\'s required by the date() function or if "as time ago" has been chosen to customize the granularity of the time interval.'),
),
),
'filters' => array(
'uid' => array(
'name' => t('Flag: @s', array(
'@s' => $flag
->get_title(),
)),
// Do not be concerned about reversal here. IS NOT NULL means flagged.
'operator' => array(
'IS NOT' => 'Is Flagged By',
),
'list' => array(
'***CURRENT_USER***' => t('Currently Logged In User'),
'uid' => t('Any User'),
),
'list-type' => 'select',
'handler' => 'flag_filter_handler_uid',
'help' => t('This will filter a only nodes that have the %s flag. If using <em>Any User</em>, often the <em>Node: Distinct</em> filter will also be desired. The <em>Any User</em> filter is not necessary if combining with other flag sorts or arguments.', array(
'%s' => $flag
->get_title(),
)),
'fid' => $flag->fid,
),
'timestamp' => array(
'name' => t('Flag: @s Flagged Time', array(
'@s' => $flag
->get_title(),
)),
'operator' => 'views_handler_operator_gtlt',
'value' => views_handler_filter_date_value_form(),
'handler' => 'views_handler_filter_timestamp',
'option' => 'string',
'help' => t('This filter allows nodes to be filtered by the time they were flagged by a user.') . ' ' . views_t_strings('filter date'),
),
),
'sorts' => array(
'timestamp' => array(
'name' => t('Flag: @s Flagged Time', array(
'@s' => $flag
->get_title(),
)),
'help' => t('Sort by the time a node was flagged using the %s flag.', array(
'%s' => $flag
->get_title(),
)),
),
),
);
$tables['flag_content_' . $flag->name] = $table;
$table = array(
'name' => 'users',
'join' => array(
'left' => array(
'table' => 'flag_content_' . $flag->name,
'field' => 'uid',
),
'right' => array(
'field' => 'uid',
),
),
'fields' => array(
'name' => array(
'name' => t('Flag: User for @s', array(
'@s' => $flag
->get_title(),
)),
'handler' => 'views_handler_field_username',
'sortable' => TRUE,
'help' => t('This will display the user who flagged the node.'),
'uid' => 'uid',
'addlfields' => array(
'uid',
),
),
),
'sorts' => array(
'name' => array(
'name' => t('Flag: User for @s', array(
'@s' => $flag
->get_title(),
)),
'help' => t('Sort by the the name of the users who flagged the node using the %s flag. This probably makes sense only when the list is filtered for a single node; e.g., on a "Who\'s flagged this" tab.', array(
'%s' => $flag
->get_title(),
)),
),
),
);
$tables["flag_users_" . $flag->name] = $table;
$table = array(
'name' => 'flag_types',
'provider' => 'flag',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'type',
),
'right' => array(
'field' => 'type',
),
'extra' => array(
'fid' => $flag->fid,
),
),
);
$tables['flag_types_' . $flag->name] = $table;
$table = array(
'name' => 'flag_counts',
'provider' => 'flag',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'content_id',
),
'extra' => array(
'fid' => $flag->fid,
),
),
'fields' => array(
'count' => array(
'name' => t('Flag: Count for @s', array(
'@s' => $flag
->get_title(),
)),
'sortable' => true,
'handler' => array(
'views_handler_field_int' => t('Display the count as an integer'),
'flag_field_handler_count' => t('Display the count in a phrase'),
),
'option' => 'string',
'help' => t('If you choose <em>Display the count in a phrase</em>, use the Option field plus the <code>@count</code> placeholder to craft your phrase. A pipe character may separate the singular form from the plural form. Another pipe may separate a leading zero phrase --which may well be an empty string-- from the aforementioned two. Examples: <code>"@count", "1 vote|@count votes", "needs voting|1 vote|@count votes", "|1 vote|@count votes", "|@count|@count"</code>.'),
),
),
'filters' => array(
'count' => array(
'name' => t('Flag: Count for @s', array(
'@s' => $flag
->get_title(),
)),
'help' => t('This will filter by the number of times that a node has been flagged.'),
'operator' => 'views_handler_operator_gtlt',
'option' => 'integer',
),
),
'sorts' => array(
'count' => array(
'name' => t('Flag: @s Count', array(
'@s' => $flag
->get_title(),
)),
'help' => t('Sort by the total flag count for each node.'),
),
),
);
$tables['flag_counts_' . $flag->name] = $table;
$table = array(
'name' => 'flag_content',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'content_id',
),
'extra' => array(
'fid' => $flag->fid,
'uid' => $flag->global ? 0 : '***CURRENT_USER***',
),
),
'fields' => array(
'ops' => array(
'field' => 'uid',
'name' => t('Flag: Ops for @s', array(
'@s' => $flag
->get_title(),
)),
'help' => t('Display an AJAX link to flag, or unflag, the node. Note that the operation is made on behalf of the user who <em>browses the page</em> and not the user whose name happens to appear adjacent to the link.'),
'handler' => 'flag_field_handler_ops',
'query_handler' => 'flag_query_handler_ops',
'fid' => $flag->fid,
'option' => array(
'#type' => 'select',
'#options' => array(
'' => t('Use flag link settings'),
) + _flag_link_type_options(),
),
),
),
);
$tables["flag_ops_" . $flag->name] = $table;
}
return $tables;
}