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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Consolidated view of comments


Go to End


7 Posts   1532 Views

Avatar
marc79

Community Member, 65 Posts

10 January 2014 at 6:20am

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

Community Member, 65 Posts

10 January 2014 at 10:36pm

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

Community Member, 65 Posts

10 January 2014 at 11:33pm

Edited: 11/01/2014 1:37am

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

Forum Moderator, 5523 Posts

11 January 2014 at 5:37pm

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

Community Member, 65 Posts

15 January 2014 at 5:36am

Edited: 15/01/2014 6:13am

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

Forum Moderator, 5523 Posts

15 January 2014 at 8:28am

Avatar
marc79

Community Member, 65 Posts

16 January 2014 at 12:25am

Nope. That's sorted it. Thanks Willr.