src/Service/Subscription/Voter/SubscriptionVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\Subscription\Voter;
  3. use Harmonizely\Model\UserInterface;
  4. use Harmonizely\Service\Panel\AccessVoters\AbstractVoter;
  5. class SubscriptionVoter extends AbstractVoter
  6. {
  7.     const RESOURCE_NAME 'subscription';
  8.     const CUSTOM_DOMAIN 'custom_domain';
  9.     const CHANGE_TEMPLATE 'change_template';
  10.     const WHITE_LABEL 'white_label';
  11.     const ORGANIZATION 'organization';
  12.     const SMS 'sms';
  13.     const SMTP 'smtp';
  14.     const FLEXIBLE_DURATION 'flexible_duration';
  15.     const SBPAY_PRO 'sbpay_pro';
  16.     const MULTIPLE_MEETING 'multiple_meeting';
  17.     const MULTIPLE_EMAIL 'multiple_email';
  18.     const EVENT_TYPE_TAG 'event_type_tag';
  19.     const API 'api';
  20.     const USER_RELATION 'user_relation';
  21.     const ROUTING_FORM 'routing_form';
  22.     const AFFILIATE 'affiliate';
  23.     const APPROVE_EVENT 'approve_event';
  24.     /**
  25.      * @return string
  26.      */
  27.     function getResourceName(): string
  28.     {
  29.         return self::RESOURCE_NAME;
  30.     }
  31.     /**
  32.      * @return string[]
  33.      */
  34.     function getResourceAttributes(): array
  35.     {
  36.         return [
  37.             self::CUSTOM_DOMAIN,
  38.             self::WHITE_LABEL,
  39.             self::CHANGE_TEMPLATE,
  40.             self::ORGANIZATION,
  41.             self::SMS,
  42.             self::SMTP,
  43.             self::FLEXIBLE_DURATION,
  44.             self::SBPAY_PRO,
  45.             self::MULTIPLE_MEETING,
  46.             self::MULTIPLE_EMAIL,
  47.             self::EVENT_TYPE_TAG,
  48.             self::API,
  49.             self::USER_RELATION,
  50.             self::ROUTING_FORM,
  51.             self::AFFILIATE,
  52.             self::APPROVE_EVENT,
  53.         ];
  54.     }
  55.     /**
  56.      * @param UserInterface $user
  57.      * @param $subject
  58.      * @return array|string[]
  59.      */
  60.     function getAllowedAttributes(UserInterface $user$subject): array
  61.     {
  62.         if ($user->hasPaidSubscription(true)) {
  63.             return $this->getResourceAttributes();
  64.         }
  65.         if ($user->hasPaidSubscription()) {
  66.             return [
  67.                 self::CUSTOM_DOMAIN,
  68.                 self::WHITE_LABEL,
  69.                 self::ORGANIZATION,
  70.                 self::SMS,
  71.                 self::SMTP,
  72.                 self::FLEXIBLE_DURATION,
  73.                 self::SBPAY_PRO,
  74.                 self::MULTIPLE_MEETING,
  75.                 self::MULTIPLE_EMAIL,
  76.                 self::EVENT_TYPE_TAG,
  77.                 self::API,
  78.                 self::USER_RELATION,
  79.                 self::ROUTING_FORM,
  80.                 self::APPROVE_EVENT,
  81.             ];
  82.         }
  83.         if ($user->hasCurrentSubscription()) {
  84.             return [
  85.                 self::API,
  86.             ];
  87.         }
  88.         return [
  89.         ];
  90.     }
  91.     /**
  92.      * @param string $attribute
  93.      * @param mixed $subject
  94.      * @return bool
  95.      */
  96.     protected function supports($attribute$subject): bool
  97.     {
  98.         if (!in_array($attribute$this->getResourceAttributes())) {
  99.             return false;
  100.         }
  101.         return true;
  102.     }
  103.     /**
  104.      * @param string $attribute
  105.      * @param UserInterface $user
  106.      * @return bool
  107.      */
  108.     public static function staticVoteOnAttribute(string $attributeUserInterface $user): bool
  109.     {
  110.         $instance = new self();
  111.         if (!in_array($attribute$instance->getResourceAttributes())) {
  112.             return false;
  113.         }
  114.         return in_array($attribute$instance->getAllowedAttributes($usernull));
  115.     }
  116. }