<?php
namespace ForumBundle\Security;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use CoreBundle\Entity\Category;
use CoreBundle\Entity\Tutor;
use CoreBundle\Entity\Student;
class ForumVoter extends Voter
{
public function __construct()
{
}
protected function supports($attribute, $subject)
{
// if the attribute isn't one we support, return false
if (! in_array($attribute, array('view'))) {
return false;
}
if ($subject !== 'forum') {
return false;
}
return true;
}
/**
* Droit d'accès au forum
*
* {@inheritDoc}
* @see \Symfony\Component\Security\Core\Authorization\Voter\Voter::voteOnAttribute()
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
// les tables tutor et student n'ont pas évoluées ensemble, elles présentent pas mal de différences.
if ($user instanceof Tutor) {
return true;
} elseif ($user instanceof Student) {
/*if ($user->getBranche()->getId() === 1) {
if ($user->getIsPau()) {
return true;
}
return false;
}*/
return true;
}
return true;
}
}