Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Consolidated view of comments

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 260 Views
  • marc79
    Avatar
    Community Member
    65 Posts

    Consolidated view of comments Link to this post

    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

  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Consolidated view of comments Link to this post

    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

  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Consolidated view of comments Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Consolidated view of comments Link to this post

    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 %>

  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Consolidated view of comments Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5483 Posts
  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Consolidated view of comments Link to this post

    Nope. That's sorted it. Thanks Willr.

    260 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.