File size: 1.22Kb
<?php
namespace MMO\Hide\BbCode\Traits;
use XF\Finder\PostFinder;
trait HasReplyTrait
{
/**
* @param $options
* @return bool
*/
public function canReplyView($options)
{
$threadId = 0;
if (isset($options['thread_id']))
{
$threadId = $options['thread_id'];
}
elseif (isset($options['entity']['thread_id']))
{
$threadId = $options['entity']['thread_id'];
}
$addOns = $this->app->container('addon.cache');
if (array_key_exists('XFRM', $addOns))
{
if (isset($options['entity']) && !empty($options['entity']->Resource->discussion_thread_id))
{
$threadId = $options['entity']->Resource->discussion_thread_id;
}
}
if (!$threadId)
{
return false;
}
/** @var PostFinder $finder */
$finder = $this->finder(PostFinder::class);
$posts = $finder->where([
['thread_id', $threadId],
['user_id', \XF::visitor()->user_id],
['message_state', 'visible']
])->limit(1)->fetch();
return $posts->count();
}
}