ViewedBy.php 612 Bytes
<?php

namespace FootyRoom\Queries\Comment;

use FootyRoom\Core\Comment\CommentPolicy;

trait ViewedBy
{
    /**
     * Sets up query according to user role to make sure right data is
     * requested.
     *
     * @param int $userRole
     *
     * @return self
     */
    public function viewedBy($userRole)
    {
        if (property_exists($this, 'unpublished')) {
            $this->unpublished = CommentPolicy::seeUnpublished($userRole);
        }

        if (property_exists($this, 'meta')) {
            $this->meta = CommentPolicy::getVisibleMeta($userRole);
        }

        return $this;
    }
}