Here is a default View for comments. There is a lot of intelligence here - 3 relationships! You might want to tweak slightly before commit. Add that $flag->name look that you do for the node default View. Search for abuse_comments to see the hard coded flag name.


$view = new view;
$view->name = 'abuse_comments';
$view->description = '';
$view->tag = 'mw';
$view->view_php = '';
$view->base_table = 'comments';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'flag_content_rel' => array(
    'label' => 'flag',
    'required' => 1,
    'flag' => 'abuse_comments',
    'user_scope' => 'any',
    'id' => 'flag_content_rel',
    'table' => 'comments',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
  ),
  'uid' => array(
    'id' => 'uid',
    'table' => 'flag_content',
    'field' => 'uid',
    'relationship' => 'flag_content_rel',
  ),
  'nid' => array(
    'label' => 'Node',
    'required' => 0,
    'id' => 'nid',
    'table' => 'comments',
    'field' => 'nid',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'subject' => array(
    'id' => 'subject',
    'table' => 'comments',
    'field' => 'subject',
    'label' => '',
    'link_to_comment' => 1,
    'relationship' => 'none',
  ),
  'name' => array(
    'label' => 'Name',
    'link_to_user' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'uid',
  ),
));
$handler->override_option('sorts', array(
  'timestamp' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'timestamp',
    'table' => 'flag_content',
    'field' => 'timestamp',
    'relationship' => 'flag_content_rel',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('title', 'Recent comments');
$handler->override_option('items_per_page', 5);
$handler->override_option('use_more', 1);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 0,
  'sticky' => 1,
  'order' => 'asc',
  'columns' => array(
    'subject' => 'subject',
    'name' => 'name',
    'timestamp' => 'timestamp',
    'ops' => 'ops',
    'delete_comment' => 'ops',
    'edit_comment' => 'ops',
  ),
  'info' => array(
    'subject' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'name' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'timestamp' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'ops' => array(
      'separator' => '  | ',
    ),
    'delete_comment' => array(
      'separator' => '',
    ),
    'edit_comment' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('fields', array(
  'subject' => array(
    'label' => 'Comment',
    'link_to_comment' => 1,
    'exclude' => 0,
    'id' => 'subject',
    'table' => 'comments',
    'field' => 'subject',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'title' => array(
    'label' => 'Post',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'nid',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'name' => array(
    'label' => 'Flagged by',
    'link_to_user' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'uid',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'timestamp' => array(
    'id' => 'timestamp',
    'table' => 'flag_content',
    'field' => 'timestamp',
  ),
  'ops' => array(
    'label' => 'Operations',
    'exclude' => 0,
    'id' => 'ops',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'delete_comment' => array(
    'label' => 'Delete',
    'text' => '',
    'exclude' => 0,
    'id' => 'delete_comment',
    'table' => 'comments',
    'field' => 'delete_comment',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
  'edit_comment' => array(
    'label' => 'Edit',
    'text' => '',
    'exclude' => 0,
    'id' => 'edit_comment',
    'table' => 'comments',
    'field' => 'edit_comment',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('path', 'abuse/comments');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler = $view->new_display('block', 'Block', 'block');
$handler->override_option('block_description', 'Recent comments view');
$handler->override_option('block_caching', -1);

CommentFileSizeAuthor
#4 comments_default_view.diff6.56 KBmooffie

Comments

mooffie’s picture

Assigned: moshe weitzman » mooffie

I'm tending to this.

mooffie’s picture

Moshe, thanks.

mooffie’s picture

That's a starting patch.

I wonder. This view lists all comments together with the user(s) who flagged them. This will cause duplicate records. Won't it be more useful to list the "flag counter" instead of the user who flagged the comment? OTOH, perhaps in communities where the administrator knows the participants, the names could be meaningful.

mooffie’s picture

StatusFileSize
new6.56 KB

I forgot to attach the patch. (It's Moshe's, with some cleanups.)

quicksketch’s picture

It seems like a count would be more universally useful than the individual names of the user, imo. Nice work on cleaning up this view also mooffie, it's much better not being tied to an existing flag.

moshe weitzman’s picture

I agree that count is usually more useful. So, here is the same view but without the relationship to from flag to user and without username field. i added the relationship for flag comment count and the flag count field. Hopefully Moofie work the same magic he did last time to make it generic. Thanks.


$view = new view;
$view->name = 'flag_abuse_comments';
$view->description = '';
$view->tag = 'flag';
$view->view_php = '';
$view->base_table = 'comments';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'flag_content_rel' => array(
    'label' => 'abuse_comments',
    'required' => 1,
    'flag' => 'abuse_comments',
    'user_scope' => 'any',
    'id' => 'flag_content_rel',
    'table' => 'comments',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
  ),
  'nid' => array(
    'label' => 'Node',
    'required' => 0,
    'id' => 'nid',
    'table' => 'comments',
    'field' => 'nid',
    'relationship' => 'none',
  ),
  'flag_count_rel' => array(
    'label' => 'counter',
    'required' => 1,
    'flag' => 'abuse_comments',
    'id' => 'flag_count_rel',
    'table' => 'comments',
    'field' => 'flag_count_rel',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'subject' => array(
    'id' => 'subject',
    'table' => 'comments',
    'field' => 'subject',
    'label' => '',
    'link_to_comment' => 1,
    'relationship' => 'none',
  ),
  'count' => array(
    'label' => 'Flag count',
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'exclude' => 0,
    'id' => 'count',
    'table' => 'flag_counts',
    'field' => 'count',
    'relationship' => 'flag_count_rel',
  ),
));
$handler->override_option('sorts', array(
  'timestamp' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'timestamp',
    'table' => 'flag_content',
    'field' => 'timestamp',
    'relationship' => 'flag_content_rel',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('title', 'Flagged comments');
$handler->override_option('items_per_page', 5);
$handler->override_option('use_more', 1);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 0,
  'sticky' => 1,
  'order' => 'asc',
  'columns' => array(
    'subject' => 'subject',
    'name' => 'name',
    'timestamp' => 'timestamp',
    'ops' => 'ops',
    'delete_comment' => 'ops',
    'edit_comment' => 'ops',
  ),
  'info' => array(
    'subject' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'name' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'timestamp' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'ops' => array(
      'separator' => '  | ',
    ),
    'delete_comment' => array(
      'separator' => '',
    ),
    'edit_comment' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('fields', array(
  'subject' => array(
    'label' => 'Comment',
    'link_to_comment' => 1,
    'exclude' => 0,
    'id' => 'subject',
    'table' => 'comments',
    'field' => 'subject',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => 'Post',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'nid',
  ),
  'count' => array(
    'label' => 'Flag counter',
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'exclude' => 0,
    'id' => 'count',
    'table' => 'flag_counts',
    'field' => 'count',
    'relationship' => 'flag_count_rel',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'timestamp' => array(
    'id' => 'timestamp',
    'table' => 'flag_content',
    'field' => 'timestamp',
  ),
  'ops' => array(
    'label' => 'Operations',
    'exclude' => 0,
    'id' => 'ops',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel',
  ),
  'delete_comment' => array(
    'label' => 'Delete',
    'text' => '',
    'exclude' => 0,
    'id' => 'delete_comment',
    'table' => 'comments',
    'field' => 'delete_comment',
    'relationship' => 'none',
  ),
  'edit_comment' => array(
    'label' => 'Edit',
    'text' => '',
    'exclude' => 0,
    'id' => 'edit_comment',
    'table' => 'comments',
    'field' => 'edit_comment',
    'relationship' => 'none',
  ),
));
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('path', 'flags/abuse_comments');
$handler->override_option('menu', array(
  'type' => 'normal',
  'title' => 'Abuse',
  'weight' => '0',
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler = $view->new_display('block', 'Block', 'block');
$handler->override_option('block_description', 'Flagged comments view');
$handler->override_option('block_caching', -1);


mooffie’s picture

This won't be so simple.

The "Flag link" field (that is, the "Ops" field) is useless when the flag isn't 'global'. OTOH, when the flag is 'global', it's the "counter" field that's useless (because it'd always show "1").

We can fix this, but tomorrow we'll find some other problem ("Hey, shouldn't we sort by the flag counter, descending?").

In other words, the problem is: Programmers need to work quite hard to convert an "exported view" to a "default view". There's some cleaning up to do. And when they discover some error, they need to repeat this tedious process.

Remember that we've yet to provide a "Who's bookmarked this" view.

So I think a better approach is to stop and instead build some tool to automate the process of converting an exported view to a default view that can be shipped.

moshe weitzman’s picture

Yeah, I feel a similar pain in og module. Perhaps you are willing to commit the original View that you converted since thats still valid? If not, we can wait for the arrival of your export tweaker. No big deal.

mooffie’s picture

Perhaps you are willing to commit the original View that you converted since thats still valid?

Its "flag/unflag" link doesn't make sense for non-global flags. The admin would exect this link to remove a comment from the "spam" list, but it wouldn't.

[...] the arrival of your export tweaker

I believe it will be quite soon, because, I believe, it'd be a very simple script ("Famous Last Words"? :-).

mooffie’s picture

Perhaps you are willing to commit the original View that you converted since thats still valid?

Its "flag/unflag" link doesn't make sense for non-global flags. The admin would exect this link to remove a comment from the "spam" list, but it wouldn't.

BTW, there's an issue discussing this limitation in our module:
#327901: Action: clearing a node's flaggings

(In short: admin has no way to clear a node's flaggings.)

mooffie’s picture

Status: Needs work » Needs review

So I think a better approach is to stop and instead build some tool to automate the process of converting an exported view to a default view that can be shipped.

[...]

I believe it will be quite soon, because, I believe, it'd be a very simple script ("Famous Last Words"? :-).

No, I decided not to execute this "ingenious" plan of mine. Programmers will have to waste their time studying my tool (and they probably won't be inclined to do this) instead of wasting it tweaking Views' exported views. So no time will be saved.

mooffie’s picture

Assigned: mooffie » Unassigned
Status: Needs review » Needs work

We'll have to provide two views: one for global flags, one for non-globals.

quicksketch’s picture

Status: Needs review » Closed (won't fix)

Now that we have the ability to expose default flags, I'd encourage this to be a "prepackaged" module that simply defines an offensive flag and the default views to match it. We're moving in the other direction of simplifying and reducing the default views, rather than bundling several more.

mooffie’s picture

Great.

Alternatively, this issue could be regarded as a duplicate of #327901: Action: clearing a node's flaggings.

sirkitree’s picture

I've also used this to provide offensive flags, for node, user and comment along with default views.

The admin clearing functionality still exists, but at least they're aware of what is going on and can edit the flagged item if needed thus far. I can attach what I've done so far if anyone is interested.

dnewkerk’s picture

Since I'm looking to test any patch that comes out for this, just following this issue as well in case anything further gets discussed here.