Conversations List

Permalink
I have been playing with Conversations a little and I am looking for a way to get the Conversations for a particular pages. It looks like I can get all the Conversations with:

$ml = new MessageList();
$messages = $ml->get();


I haven't found a way to filter those by a particular page (like you could if you were working with the page list).

Can anyone give me the correct way to get conversations for a particular page?

Thanks

pvernaglia
 
pvernaglia replied on at Permalink Reply
pvernaglia
bump.. Anyone have any help on retrieving just the conversations for a given page?
somesayinice replied on at Permalink Reply
Hey so so. Was pulling my hair out about this one too. Took a little bit but figured this out by looking through the controller. Essentially first I got the block ID then made a DB query. Here is the code. Hope it helps someone out later. (Maybe me :-) )

<?php
   $page = Page::getCurrentPage();
   $blocks = $page->getBlocks('Comment'); // getblocks by area.  You could probably get all the blocks from the page.
   if($blocks) {
      foreach ($blocks as $block) {
         $handle = $block->getBlockTypeHandle();
         if ($handle == 'core_conversation') { //check to see if this is a conversation block.
            $blockID = $block->getBlockID(); //If you have > 1 you may have to iterate over an array later on.
         }
      }
   }
   $db = Database::get();
   $cnvID = $db->GetOne('select cnvID from btCoreConversation where bID = ?', $blockID);  // this is where the magic happens.
   $conversation = Conversation::getByID($cnvID);
   $messageList = new \Concrete\Core\Conversation\Message\MessageList();


Maybe there's an easier way. But it's all I've found.
c5dragon replied on at Permalink Reply
c5dragon
For 5.7:http://documentation.concrete5.org/developers/concepts/conversation...
http://documentation.concrete5.org/api/class-Concrete.Core.Conversa...

But you have to make some changes:
Change:
$messageAuthor = $message->cnvMessageAuthor->getName();
$dh = Core::make('helper/date');
$timestamp = strtotime($message->getConversationMessageDateTime());
$timestamp = $dh->formatCustom('d M Y - H:i:s', $timestamp);

Add:
$messageBody = $message->getConversationMessageBody();

Remove:
//$authorFullName = $messageAuthor->getAttribute('first_name') . ' ' . $messageAuthor->getAttribute('last_name');

And echo what you want to show.