Reputation:
<?php
namespace Test\Demo\XF\Entity;
use XF\Mvc\Entity\Entity;
class Post extends XFCP_Post
{
public function canView(&$error = null)
{
//get visitor
$visitor = \XF::visitor();
//get parent method
$canView = parent::canView();
if (!$canView)
{
if (!$this->Thread || !$this->Thread->canView($error))
{
return false;
}
if ($visitor->user_id == $this->Thread->user_id)
{
// view moderated posts
if ($this->message_state == 'moderated')
{
return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission');
}
// view deleted posts
if ($this->message_state == 'deleted')
{
return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission');
}
}
}
return $canView;
}
Reputation:
u can make it easy with \XF\Entity
You need to extend XFCP_Post
it's for examplePHP:<?php namespace Test\Demo\XF\Entity; use XF\Mvc\Entity\Entity; class Post extends XFCP_Post { public function canView(&$error = null) { //get visitor $visitor = \XF::visitor(); //get parent method $canView = parent::canView(); if (!$canView) { if (!$this->Thread || !$this->Thread->canView($error)) { return false; } if ($visitor->user_id == $this->Thread->user_id) { // view moderated posts if ($this->message_state == 'moderated') { return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission'); } // view deleted posts if ($this->message_state == 'deleted') { return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission'); } } } return $canView; }