<?php
/**
 * @version 7.9 [rev.7.9.01]
 */
if ($sale instanceof \Ppb\Db\Table\Row\Sale) {
    /** @var \Ppb\Db\Table\Row\User $user */
    $user = $this->userDetails($this->loggedInUser['id'])->getUser();
    $active = $user->isActive();
    ?>
    <?php echo $this->partial('partials/sale.phtml', array(
        'sale'                => $sale,
        'postageDesc'         => ($active) ? true : false,
        'caption'             => ($active) ? true : false,
        'directPaymentButton' => ($active) ? true : false,
        'type'                => $this->loggedInUser['id'] == $sale['seller_id'] ? 'sold' : 'bought')); ?>
<?php }
else {
    // TODO: not an ideal solution
    $topicTitle = $message->getTopicTitle();
    @preg_match('#Private Message - Listing ID: \#(.*)#', $topicTitle, $matches);
    if (count($matches) > 1) {
        if (!empty($matches[1])) {
            $listingsService = new \Ppb\Service\Listings();
            $listing = $listingsService->findBy('id', intval($matches[1]));
            if (count($listing) > 0) {
                echo $this->partial('partials/listing-box.phtml', array(
                        'listing' => $listing)) . '<br>';
            }
        }
    }
}
?>


<h4 class="headline">
    <span><?php echo $this->_('Message Board'); ?></span>
</h4>

<?php echo ($message['topic_id'] != null) ? $this->partial('partials/messages.phtml', array(
    'message' => $message)) : null; ?>
<?php echo $this->action('create', 'messaging', 'members', array(
    'receiver_id' => ($this->loggedInUser['id'] == $message['sender_id']) ?
        $message['receiver_id'] : $message['sender_id'],
    'sale_id'     => $message['sale_id'],
    'topic_id'    => $message['topic_id'])); ?>
