By effebi on
I need to create a page where, once logged, are able to see the list of his/her own comments.
I already created a recent-comments (Views2) page, in this page every user can see all recent comments, now I have to limit this view to logged user:
while user X wrote 12 comments and user Y just 5, then user X can see domain.com/recent-comments with her 12 comments and user Y his own 5 on the same page.
I tried to add a new filter (Node) User: Current Yes but page show all comments, while with (Node) User: Current No everything disappear.
here's my Views2 code:
$view = new view;
$view->name = 'incontri';
$view->description = 'Incontri';
$view->tag = 'default';
$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(
'nid' => array(
'id' => 'nid',
'table' => 'comments',
'field' => 'nid',
'label' => 'Node',
'required' => FALSE,
),
));
$handler->override_option('fields', array(
'subject' => array(
'id' => 'subject',
'table' => 'comments',
'field' => 'subject',
'label' => '',
'link_to_comment' => 1,
'relationship' => 'none',
),
'timestamp' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'medium',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'timestamp' => array(
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'order' => 'DESC',
'granularity' => 'second',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'uid_current' => array(
'operator' => '=',
'value' => '0',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => '',
'label' => 'Is the logged in user',
'identifier' => 'uid_current',
'optional' => 0,
'remember' => 0,
),
'id' => 'uid_current',
'table' => 'users',
'field' => 'uid_current',
'relationship' => 'nid',
'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', 'list');
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('fields', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Reply to',
'relationship' => 'nid',
'link_to_node' => 1,
),
'timestamp' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'medium',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
'subject' => array(
'id' => 'subject',
'table' => 'comments',
'field' => 'subject',
'label' => '',
'link_to_comment' => 1,
'relationship' => 'none',
),
'name' => array(
'label' => 'Author',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_user' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'comments',
'field' => 'name',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('row_options', array(
'inline' => array(
'title' => 'title',
'timestamp' => 'timestamp',
),
'separator' => ' ',
));
$handler->override_option('path', 'incontri');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
Comments
I just added relationships
I just added relationships comment:User along with comment:Node and filter (User) User: Current Yes.
Try below code:
$view = new view;
$view->name = 'test';
$view->description = 'Incontri';
$view->tag = 'default';
$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(
'uid_1' => array(
'label' => 'User',
'required' => 0,
'id' => 'uid_1',
'table' => 'comments',
'field' => 'uid',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'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',
),
'timestamp' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'medium',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'timestamp' => array(
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'order' => 'DESC',
'granularity' => 'second',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'uid_current_1' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'uid_current_1',
'table' => 'users',
'field' => 'uid_current',
'relationship' => 'uid_1',
'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', 'list');
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('fields', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Reply to',
'relationship' => 'nid',
'link_to_node' => 1,
),
'timestamp' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'medium',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
'subject' => array(
'id' => 'subject',
'table' => 'comments',
'field' => 'subject',
'label' => '',
'link_to_comment' => 1,
'relationship' => 'none',
),
'name' => array(
'label' => 'Author',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_user' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'comments',
'field' => 'name',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('row_options', array(
'inline' => array(
'title' => 'title',
'timestamp' => 'timestamp',
),
'separator' => ' ',
));
$handler->override_option('path', 'comments');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
Thanks
it works,
thank you! :)