Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Consolidated view of comments


Reply

7 Posts   316 Views

Avatar
marc79

10 January 2014 at 6:20am Community Member, 65 Posts

Hello all,

Is it possible to show a consolidated view of all comments across a number of pages?

I have a site with comments enabled on a number of pages which is working really well. Now to make it easier to get an overview of all the comments I would like to show all comments for these pages on the PageHolder page. Is this possible?

thanks
Marc

Avatar
marc79

10 January 2014 at 10:36pm Community Member, 65 Posts

Have tried using the below:

function AllComments($num=200) {
return DataObject::get("Comment", "ParentID >= 1", "Created DESC", "", $num);
}

But I need to filter the results where the ParentIDs ParentID = $this

Avatar
marc79

10 January 2014 at 11:33pm (Last edited: 11 January 2014 1:37am), Community Member, 65 Posts

Tried getting the ID of the children for the holder page but not sure how to relate the two functions:

function SortedChildren() {
    $dosChildren = $this->Children();    
    if ($dosChildren)
    return $dosChildren;
   }
   
function AllComments() {
   return DataObject::get("Comment", "ParentID = $dosChildren.ID", "Created DESC");
   }

Is this along the right lines?

To clarify the scenario is:

PageHolder

- Page 1
- Comment 1
- Comment 2

- Page 2
- Comment 3
- Comment 4
- Comment 5

- Page 3
- Comment 6
- Comment 7

I want to show all comments on the Page holder.

Avatar
Willr

11 January 2014 at 5:37pm Forum Moderator, 5511 Posts

In your case as you described you don't need to write any functions, you could do something like the following in your holder template

<% loop Children %>
<h2>$Title</h2>
<% if Comments %>
<% loop Comments.Sort('Created DESC') %>
<% include CommentsInterface_singlecomment %>
<% end_loop %>
<% else %>
<p>No comments</p>
<% end_if %>
<% end_loop %>

Avatar
marc79

15 January 2014 at 5:36am (Last edited: 15 January 2014 6:13am), Community Member, 65 Posts

Thanks Willr but I'm getting a Server error - Sorry, there was a problem handling your request.

Switch on dev mode it seems that I need to add a has_one relationship between the Page and the Comment DataObject but adding this just throws another error.

Uncaught Exception: No has_one found on class 'Comment', the has_many relation from 'ScreenPage' to 'Comment' requires a has_one on 'Comment'

Do I need to add a relationship back to the page?

Avatar
Willr

15 January 2014 at 8:28am Forum Moderator, 5511 Posts

Got the latest version of comments? That was fixed in https://github.com/silverstripe/silverstripe-comments/commit/5cfa476264658b75c7d28e3b86b003aa81149aac

Avatar
marc79

16 January 2014 at 12:25am Community Member, 65 Posts

Nope. That's sorted it. Thanks Willr.