src/Cms/TenantBundle/Entity/Tenant.php line 28

Open in your IDE?
  1. <?php
  2. namespace Cms\TenantBundle\Entity;
  3. use App\Entity\Shared\UlidTransitionalInterface;
  4. use App\Entity\Shared\UlidTransitionalTrait;
  5. use App\Util\Locales;
  6. use Cms\CoreBundle\Entity\LocaleSettings;
  7. use Cms\CoreBundle\Model\CustomDataTrait;
  8. use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
  9. use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableTrait;
  10. use Cms\CoreBundle\Model\Interfaces\Timestampable\TimestampableInterface;
  11. use Cms\CoreBundle\Model\Interfaces\Timestampable\TimestampableTrait;
  12. use Cms\TenantBundle\Model\ProductsBitwise;
  13. use Cms\TenantBundle\Model\SimpleTenantableInterface;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use DateTime;
  16. use Products\AdaBundle\Entity\AdaSettingsEmbeddable;
  17. use Reinder83\BinaryFlags\Bits;
  18. /**
  19.  * Class Tenant
  20.  * @package Cms\TenantBundle\Entity
  21.  *
  22.  * @ORM\Entity(repositoryClass = "Cms\TenantBundle\Doctrine\TenantRepository")
  23.  * @ORM\Table(name = "cms__tenant__tenant")
  24.  */
  25. class Tenant
  26.     implements
  27.         IdentifiableInterface,
  28.         TimestampableInterface,
  29.         SimpleTenantableInterface,
  30.         UlidTransitionalInterface
  31. {
  32.     use IdentifiableTrait;
  33.     use TimestampableTrait;
  34.     use CustomDataTrait;
  35.     use TenantAuthenticationTrait;
  36.     use UlidTransitionalTrait;
  37.     const STATUS__OK 'OK';
  38.     const STATUS__SUSPENDED 'suspended';
  39.     const STATUS__INACTIVE 'inactive';
  40.     const STAGE__PROVISIONED 0;
  41.     const STAGE__BUILD 1;
  42.     const STAGE__LIVE 2;
  43.     const STAGE__DEFUNCT 3;
  44.     const EMAILS__SHOW Bits::BIT_1;
  45.     const EMAILS__OBFUSCATE Bits::BIT_2;
  46.     const EMAILS__HIDE Bits::BIT_3;
  47.     /**
  48.      * @var string
  49.      *
  50.      * @ORM\Column(type = "string", nullable = false, unique = true)
  51.      */
  52.     protected $name;
  53.     /**
  54.      * @var string
  55.      *
  56.      * @ORM\Column(type = "string", nullable = false, unique = true)
  57.      */
  58.     protected $slug;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @ORM\Column(type = "string", nullable = false)
  63.      */
  64.     protected $status;
  65.     /**
  66.      * @var int
  67.      *
  68.      * @ORM\Column(
  69.      *     type = "integer",
  70.      *     nullable = false,
  71.      *     options = {
  72.      *         "default" = Tenant::EMAILS__SHOW
  73.      *     }
  74.      * )
  75.      */
  76.     protected $emailsDisplay self::EMAILS__SHOW;
  77.     /**
  78.      * @var LocaleSettings
  79.      *
  80.      * @ORM\Embedded(class = "Cms\CoreBundle\Entity\LocaleSettings", columnPrefix = "locale_")
  81.      */
  82.     protected $locale;
  83.     /**
  84.      * @var DateTime
  85.      * @ORM\Column(type = "datetime", nullable = true)
  86.      */
  87.     protected $policy;
  88.     /**
  89.      * @var string
  90.      *
  91.      * @ORM\Column(type = "string", nullable = true)
  92.      */
  93.     protected $disqusId;
  94.     /**
  95.      * @var string
  96.      *
  97.      * @ORM\Column(
  98.      *     type = "string",
  99.      *     nullable = true
  100.      * )
  101.      */
  102.     protected $googleToken;
  103.     /**
  104.      * @var string
  105.      *
  106.      * @ORM\Column(type = "integer", length=1, nullable = false, options={"default" = Tenant::STAGE__PROVISIONED})
  107.      */
  108.     protected $stage self::STAGE__PROVISIONED;
  109.     /**
  110.      * @var integer
  111.      *
  112.      * @ORM\Column(type = "integer", nullable = true)
  113.      */
  114.     protected $teamworkTasklist;
  115.     /**
  116.      * @var string
  117.      *
  118.      * @ORM\Column(type = "string", nullable = true)
  119.      */
  120.     protected $latitude;
  121.     /**
  122.      * @var string
  123.      *
  124.      * @ORM\Column(type = "string", nullable = true)
  125.      */
  126.     protected $longitude;
  127.     /**
  128.      * @var bool
  129.      *
  130.      * @ORM\Column(
  131.      *     type = "boolean",
  132.      *     nullable = false,
  133.      *     options = {
  134.      *         "default" = false
  135.      *     }
  136.      * )
  137.      */
  138.     protected $redirects false;
  139.     /**
  140.      * @var bool
  141.      *
  142.      * @ORM\Column(
  143.      *     type = "boolean",
  144.      *     nullable = false,
  145.      *     options = {
  146.      *         "default" = false,
  147.      *     },
  148.      * )
  149.      */
  150.     protected bool $redirectCodes false;
  151.     /**
  152.      * @var bool
  153.      *
  154.      * @ORM\Column(
  155.      *     type = "boolean",
  156.      *     nullable = false,
  157.      *     options = {
  158.      *         "default" = false
  159.      *     }
  160.      * )
  161.      */
  162.     protected $debugging false;
  163.     /**
  164.      * @var ProductsBitwise
  165.      *
  166.      * @ORM\Column(
  167.      *     type = "bitwise_products",
  168.      *     nullable = false,
  169.      *     options = {
  170.      *         "default" = 0
  171.      *     }
  172.      * )
  173.      */
  174.     protected $products;
  175.     /**
  176.      * @var AdaSettingsEmbeddable
  177.      *
  178.      * @ORM\Embedded(
  179.      *     class = "Products\AdaBundle\Entity\AdaSettingsEmbeddable",
  180.      *     columnPrefix = "ada_"
  181.      * )
  182.      */
  183.     protected $adaSettings;
  184.     /**
  185.      * @var TenantTypeEmbeddable
  186.      *
  187.      * @ORM\Embedded(
  188.      *     class = "Cms\TenantBundle\Entity\TenantTypeEmbeddable",
  189.      *     columnPrefix = "type_"
  190.      * )
  191.      */
  192.     protected $type;
  193.     /**
  194.      * @var string|null
  195.      *
  196.      * @ORM\Column(
  197.      *     type = "string",
  198.      *     nullable = true,
  199.      *     unique = true
  200.      * )
  201.      */
  202.     protected $hubspotId;
  203.     /**
  204.      * @var string|null
  205.      *
  206.      * @ORM\Column(
  207.      *     type = "string",
  208.      *     nullable = true,
  209.      * )
  210.      */
  211.     protected ?string $weglotId null;
  212.     /**
  213.      * @var array|string[]
  214.      */
  215.     protected array $locales = [];
  216.     /**
  217.      * Tenant constructor.
  218.      */
  219.     public function __construct()
  220.     {
  221.         $this->locale = new LocaleSettings();
  222.         $this->adaSettings = new AdaSettingsEmbeddable();
  223.         $this->type = new TenantTypeEmbeddable();
  224.     }
  225.     /**
  226.      * @return bool
  227.      */
  228.     public function hasRedirectCodes(): bool
  229.     {
  230.         return $this->redirectCodes;
  231.     }
  232.     /**
  233.      * @param bool $redirectCodes
  234.      * @return $this
  235.      */
  236.     public function setRedirectCodes(bool $redirectCodes): self
  237.     {
  238.         $this->redirectCodes $redirectCodes;
  239.         return $this;
  240.     }
  241.     /**
  242.      * @return string|null
  243.      */
  244.     public function getWeglotId(): ?string
  245.     {
  246.         return $this->weglotId;
  247.     }
  248.     /**
  249.      * @param string|null $weglotId
  250.      * @return $this
  251.      */
  252.     public function setWeglotId(?string $weglotId): self
  253.     {
  254.         $this->weglotId $weglotId;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return int
  259.      */
  260.     public function getEmailsDisplay(): int
  261.     {
  262.         return $this->emailsDisplay;
  263.     }
  264.     /**
  265.      * @param int $value
  266.      * @return $this
  267.      */
  268.     public function setEmailsDisplay(int $value): self
  269.     {
  270.         $this->emailsDisplay $value;
  271.         return $this;
  272.     }
  273.     /**
  274.      * @param string|int $value
  275.      * @return bool
  276.      */
  277.     public function isEmailsDisplay($value): bool
  278.     {
  279.         if (is_string($value)) {
  280.             $value constant(self::class.'::'.$value);
  281.         }
  282.         if ( ! is_int($value)) {
  283.             throw new \Exception();
  284.         }
  285.         return ($this->getEmailsDisplay() === $value);
  286.     }
  287.     /**
  288.      * @return TenantTypeEmbeddable
  289.      */
  290.     public function getType()
  291.     {
  292.         return $this->type;
  293.     }
  294.     /**
  295.      * @param TenantTypeEmbeddable $value
  296.      * @return $this
  297.      */
  298.     public function setType(TenantTypeEmbeddable $value)
  299.     {
  300.         $this->type $value;
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return ProductsBitwise
  305.      */
  306.     public function getProducts()
  307.     {
  308.         return $this->products;
  309.     }
  310.     /**
  311.      * @param ProductsBitwise $value
  312.      * @return $this
  313.      */
  314.     public function setProducts(ProductsBitwise $value)
  315.     {
  316.         if ( ! $this->products instanceof ProductsBitwise) {
  317.             $this->products = new ProductsBitwise();
  318.         }
  319.         $this->products $this->products->orm($value);
  320.         return $this;
  321.     }
  322.     /**
  323.      * @return string
  324.      */
  325.     public function getName()
  326.     {
  327.         return $this->name;
  328.     }
  329.     /**
  330.      * @return string
  331.      */
  332.     public function getSlug()
  333.     {
  334.         return $this->slug;
  335.     }
  336.     /**
  337.      * @return string
  338.      */
  339.     public function getStatus()
  340.     {
  341.         return $this->status;
  342.     }
  343.     /**
  344.      * @param string $value
  345.      * @return $this
  346.      */
  347.     public function setName($value)
  348.     {
  349.         $this->name $value;
  350.         return $this;
  351.     }
  352.     /**
  353.      * @param string $value
  354.      * @return $this
  355.      */
  356.     public function setSlug($value)
  357.     {
  358.         $this->slug $value;
  359.         return $this;
  360.     }
  361.     /**
  362.      * @param string $value
  363.      * @return $this
  364.      */
  365.     public function setStatus($value)
  366.     {
  367.         $this->status $value;
  368.         return $this;
  369.     }
  370.     /**
  371.      * @return LocaleSettings
  372.      */
  373.     public function getLocale()
  374.     {
  375.         return $this->locale;
  376.     }
  377.     /**
  378.      * @param LocaleSettings $locale
  379.      * @return $this
  380.      */
  381.     public function setLocale(LocaleSettings $locale)
  382.     {
  383.         $this->locale $locale;
  384.         return $this;
  385.     }
  386.     /**
  387.      * @return DateTime
  388.      */
  389.     public function getPolicy()
  390.     {
  391.         return $this->policy;
  392.     }
  393.     /**
  394.      * @param DateTime $policy
  395.      * @return $this
  396.      */
  397.     public function setPolicy(DateTime $policy)
  398.     {
  399.         $this->policy $policy;
  400.         return $this;
  401.     }
  402.     /**
  403.      * @return string
  404.      */
  405.     public function getDisqusId()
  406.     {
  407.         return $this->disqusId;
  408.     }
  409.     /**
  410.      * @param string $disqusId
  411.      * @return $this
  412.      */
  413.     public function setDisqusId($disqusId)
  414.     {
  415.         $this->disqusId $disqusId;
  416.         return $this;
  417.     }
  418.     /**
  419.      * @return string
  420.      */
  421.     public function getGoogleToken()
  422.     {
  423.         return $this->googleToken;
  424.     }
  425.     /**
  426.      * @param string $value
  427.      * @return $this
  428.      */
  429.     public function setGoogleToken($value null)
  430.     {
  431.         $this->googleToken $value;
  432.         return $this;
  433.     }
  434.     /**
  435.      * @return string
  436.      */
  437.     public function getStage()
  438.     {
  439.         return $this->stage;
  440.     }
  441.     /**
  442.      * @param string $stage
  443.      * @return $this
  444.      */
  445.     public function setStage($stage)
  446.     {
  447.         $this->stage $stage;
  448.         return $this;
  449.     }
  450.     /**
  451.      * @return int
  452.      */
  453.     public function getTeamworkTasklist()
  454.     {
  455.         return $this->teamworkTasklist;
  456.     }
  457.     /**
  458.      * @param int $teamworkTasklist
  459.      * @return $this
  460.      */
  461.     public function setTeamworkTasklist($teamworkTasklist)
  462.     {
  463.         $this->teamworkTasklist $teamworkTasklist;
  464.         return $this;
  465.     }
  466.     /**
  467.      * @return string
  468.      */
  469.     public function getLatitude()
  470.     {
  471.         return $this->latitude;
  472.     }
  473.     /**
  474.      * @param string $value
  475.      * @return $this
  476.      */
  477.     public function setLatitude($value)
  478.     {
  479.         $this->latitude $value;
  480.         return $this;
  481.     }
  482.     /**
  483.      * @return string
  484.      */
  485.     public function getLongitude()
  486.     {
  487.         return $this->longitude;
  488.     }
  489.     /**
  490.      * @param string $value
  491.      * @return $this
  492.      */
  493.     public function setLongitude($value)
  494.     {
  495.         $this->longitude $value;
  496.         return $this;
  497.     }
  498.     /**
  499.      * @return bool
  500.      */
  501.     public function getRedirects()
  502.     {
  503.         return ($this->redirects === true);
  504.     }
  505.     /**
  506.      * @param bool $value
  507.      * @return $this
  508.      */
  509.     public function setRedirects($value)
  510.     {
  511.         $this->redirects = ($value === true);
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return bool
  516.      */
  517.     public function getDebugging()
  518.     {
  519.         return ($this->debugging === true);
  520.     }
  521.     /**
  522.      * @param bool $value
  523.      * @return $this
  524.      */
  525.     public function setDebugging($value)
  526.     {
  527.         $this->debugging = ($value === true);
  528.         return $this;
  529.     }
  530.     /**
  531.      * @return AdaSettingsEmbeddable
  532.      */
  533.     public function getAdaSettings()
  534.     {
  535.         return $this->adaSettings;
  536.     }
  537.     /**
  538.      * @return string|null
  539.      */
  540.     public function getHubspotId(): ?string
  541.     {
  542.         return $this->hubspotId;
  543.     }
  544.     /**
  545.      * @param string|null $hubspotId
  546.      * @return $this
  547.      */
  548.     public function setHubspotId(?string $hubspotId): self
  549.     {
  550.         $this->hubspotId $hubspotId;
  551.         return $this;
  552.     }
  553.     /**
  554.      * {@inheritDoc}
  555.      */
  556.     public function getTenant(): ?Tenant
  557.     {
  558.         return $this;
  559.     }
  560.     /**
  561.      * @return bool
  562.      */
  563.     public function isSchoolNow(): bool
  564.     {
  565.         return $this->getProducts()->hasFlag(ProductsBitwise::SCHOOLNOW__MIGRATED);
  566.     }
  567.     public function getLocales(): array
  568.     {
  569.         return $this->locales;
  570.     }
  571.     public function setLocales(array $locales): self
  572.     {
  573.         $locales array_values(array_filter(array_unique(
  574.             $locales
  575.         )));
  576.         foreach ($locales as $locale) {
  577.             if ( ! Locales::isLocale($locale)) {
  578.                 throw new \Exception();
  579.             }
  580.         }
  581.         $primary null;
  582.         if ($locales) {
  583.             $primary $locales[0];
  584.         }
  585.         usort($locales, function (string $astring $b) use ($primary) {
  586.             if ($a === $b) {
  587.                 return 0;
  588.             }
  589.             if ($a === $primary) {
  590.                 return 1;
  591.             }
  592.             if ($b === $primary) {
  593.                 return -1;
  594.             }
  595.             return $a <=> $b;
  596.         });
  597.         $this->locales $locales;
  598.         return $this;
  599.     }
  600.     public function isPrimaryLocale(string $locale): bool
  601.     {
  602.         return $this->getPrimaryLocale() === $locale;
  603.     }
  604.     public function getPrimaryLocale(): string
  605.     {
  606.         return $this->locales $this->locales[0] : Locales::RFC4646_DEFAULT;
  607.     }
  608.     public function setPrimaryLocale(string $locale): self
  609.     {
  610.         if ( ! Locales::isLocale($locale)) {
  611.             throw new \Exception();
  612.         }
  613.         $locales $this->getLocales();
  614.         $index array_search($locale$locales);
  615.         if ($index !== false) {
  616.             $locales[$index] = null;
  617.         }
  618.         array_unshift($this->locales$locale);
  619.         return $this->setLocales($locales);
  620.     }
  621.     public function isSecondaryLocale(string $locale): bool
  622.     {
  623.         return in_array($locale$this->getSecondaryLocales());
  624.     }
  625.     public function getSecondaryLocales(): array
  626.     {
  627.         return array_slice($this->locales1);
  628.     }
  629.     /**
  630.      * @return string
  631.      */
  632.     public function getTimezone(): string
  633.     {
  634.         if (($locale $this->getLocale()) && ($timezone $locale->getTimezone())) {
  635.             return $timezone;
  636.         }
  637.         return 'UTC';
  638.     }
  639. }