ChangeApprovalPolicy.php 824 Bytes
<?php

namespace FootyRoom\Core\Comment;

use FootyRoom\Core\AuthException;
use FootyRoom\User\User;

class ChangeApprovalPolicy
{
    /**
     * Decides whether user can moderate specific comment.
     *
     * @param \FootyRoom\User\User $user
     * @param string $discussionId
     * @param bool $throw
     *
     * @throws \FootyRoom\Core\AuthException
     *
     * @return bool
     */
    public static function check(User $user, $discussionId = '', $throw = false)
    {
        if (substr($discussionId, 0, 5) === 'wall:' && (int) substr($discussionId, 5) === $user->getUserId()) {
            return true;
        }

        if (CommentPolicy::canModerate($user, $throw)) {
            return true;
        }

        if ($throw) {
            throw new AuthException();
        }

        return false;
    }
}