Page List - number of comments/messages on a page

Permalink
Prior to 5.7 one could fetch the number of comments on a blog page, for display in a page list, with something like this:

$cch = Loader::helper('comment_count');
$comments = $cch->comment_count_string($cobj);


This has clearly all changed with 5.7, but I can't for the life of me find out how to now go about fetching this data ...anyone, please?

 
hutman replied on at Permalink Reply
hutman
What package were you using to create your blog pages/comments? This is not a default function of 5.6
losttheplot replied on at Permalink Reply
I hand-coded my own 5.6 blocks, as I am doing now with 5.7. The trouble is, I can't find any documentation for the 5.7 equivalent of the 'comment_count' helper and its methods.
hutman replied on at Permalink Reply
hutman
I'm looking through a 5.6.3.4 site that I have installed on my local dev environment and I don't see any mention in the core of a comment_count helper anywhere. Is is possible that helper was something you created (or another dev) or possibly part of a package that you had installed?
losttheplot replied on at Permalink Reply
I'm just looking through a 5.6.3.4 instal myself, and so far I can't find that helper, so you could be right. Looking...
losttheplot replied on at Permalink Reply
OK, I've found my helper override, which my notes tell me was written with the help of a post athttp://www.concrete5.org/community/forums/customizing_c5/comment-co... Yes, I can even see my own post on that thread, thanking the OP.

I guess I'll need to try and update this helper for 5.7 ...unless you know of an easier solution?
hutman replied on at Permalink Reply
hutman
With 5.7 are you using the Conversation block for your comments or do you have an internal system for it?
losttheplot replied on at Permalink Reply
I am indeed using the conversation block.
hutman replied on at Permalink Reply
hutman
Unfortunately, either way I think you are going to have to convert your comment_count helper over to 5.7. I'm sure if you do that other people would love to see how you do it too.
losttheplot replied on at Permalink Reply
The db schema looks similar to 5.6 so I guess I just need to work out where to place my override, and which namespace to use ...not easy when you've already hit the wine for Friday night!
losttheplot replied on at Permalink Reply
A post here >https://www.concrete5.org/community/forums/5-7-discussion/migrating-... explains how to migrate 5.6 helpers over to 5.7, which is very straightforward once it's explained. Now I just need to work out how to find the relevant collection object IDs for the conversation blocks in each page as they are iterated through within the Page List view. I guess this is going to have to wait until next week now. Thanks for your help and have a good weekend :)
losttheplot replied on at Permalink Reply
OK, so with a clear head, I studied the 5.7 Conversation class and found a method called getConversationMessagesTotal(). I also found a static function called getByID(). I put these together to get:

$conversation = Conversation::getByID($cnvID);
$comments = $conversation->getConversationMessagesTotal();

So next we need the conversation ID from the block ID from the collection ID. Google led me to this post, which has a crude but effective solution >https://www.concrete5.org/community/forums/5-7-discussion/conversati... (thanks somesayinice).

The end result is the following snippet that can run from within the pages iteration loop in a page_list template. Bare in mind that my template is specifically for blog pages that have a conversation block in the Main Content area. It's not true MVC, but it'll do for now (deadlines looming) and I would welcome any suggestions for improvement:

// find out number of approved comments from the page's conversation block
        $blocks = $page->getBlocks('Main Content');
        if ($blocks) {
           foreach ($blocks as $block) {
              $handle = $block->getBlockTypeHandle();
              if ($handle == 'core_conversation') {
                 $blockID = $block->getBlockID();
              }
           }
        }
        $db = Database::get();
        $cnvID = $db->GetOne('select cnvID from btCoreConversation where bID = ?', $blockID);
        $conversation = Conversation::getByID($cnvID);
        $comments = $conversation->getConversationMessagesTotal();
        // tidy-up the output