src/Security/BFAdminLicencesVoter.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use App\Entity\BFFestival;
  4. use App\Entity\BFEdition;
  5. use App\Entity\BFChallenge;
  6. use App\Entity\BFChallengeEdition;
  7. use App\Entity\BFOption;
  8. use App\Utilities\OptionUtilities;
  9. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  10. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  11. use Symfony\Component\Security\Core\Security;
  12. class BFAdminLicencesVoter extends Voter
  13. {
  14.     private $security;
  15.     //the string options are managed by the utility
  16.     
  17.     public function __construct(Security $security)
  18.     {
  19.         $this->security $security;
  20.     }
  21.     protected function supports($attribute$subject)
  22.     {
  23.         
  24.         // if the attribute isn't one we support, return false
  25.         if (!in_array($attributeOptionUtilities::OptionArray)) {
  26.             return false;
  27.         }
  28.         
  29.         // only vote on `BFFestival` objects
  30.         if (($subject instanceof BFEdition) || ($subject instanceof BFFestival || ($subject instanceof BFChallenge) || ($subject instanceof BFChallengeEdition))) { // ||
  31.             return true;
  32.         }
  33.         return false;
  34.     }
  35.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  36.     {            
  37.         $bfadminlicences $subject->getBFAdminLicences();
  38.         $datetimenow \DateTime::createFromFormat('Y-m-d'date('Y-m-d'));
  39.         
  40.         foreach($bfadminlicences as $bfadminlicence)
  41.         {
  42.             //check options
  43.             if($bfadminlicence->getOptionname() == $attribute
  44.                && $bfadminlicence->getValiditydate()>=$datetimenow)
  45.             {
  46.                 return true;
  47.             }
  48.             
  49.             //check offer
  50.             if(in_array($bfadminlicence->getOptionname(), OptionUtilities::OfferArray//check is offer
  51.                && in_array($attributeOptionUtilities::OfferArray['$bfadminlicence->getOptionname()']) //check offer options
  52.                && $bfadminlicence->getValiditydate()>=$datetimenow //check date
  53.               )
  54.             {
  55.                 return true;
  56.             }
  57.         }
  58.         
  59.        return false;
  60.     }
  61. }
  62. ?>