src/Entity/Tenant.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TenantRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=TenantRepository::class)
  9.  *
  10.  * @ORM\HasLifecycleCallbacks()
  11.  *
  12.  * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
  13.  * @SuppressWarnings(PHPMD.TooManyPublicMethods)
  14.  */
  15. class Tenant {
  16.     use MetaTrait;
  17.     /**
  18.      * @ORM\Id
  19.      *
  20.      * @ORM\GeneratedValue
  21.      *
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=255)
  27.      */
  28.     private $name;
  29.     /**
  30.      * @ORM\Column(type="string", length=255)
  31.      */
  32.     private $hostname;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     private $uploadDirectory;
  37.     /**
  38.      * @ORM\OneToOne(targetEntity=TenantConfig::class, mappedBy="tenant", cascade={"persist", "remove"})
  39.      */
  40.     private $tenantConfig;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity=Faq::class, mappedBy="tenant")
  43.      */
  44.     private $faqs;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="tenant")
  47.      */
  48.     private $products;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity=TextTemplate::class, mappedBy="tenant", orphanRemoval=true, fetch="EXTRA_LAZY")
  51.      */
  52.     private $textTemplates;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=Category::class, mappedBy="tenant", orphanRemoval=true)
  55.      */
  56.     private $categories;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="tenant", orphanRemoval=true)
  59.      */
  60.     private $orders;
  61.     /**
  62.      * @ORM\Column(type="string", length=255)
  63.      */
  64.     private $email;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private $dvoEmail;
  69.     private $initialUser;
  70.     public function __construct() {
  71.         $this->faqs = new ArrayCollection();
  72.         $this->products = new ArrayCollection();
  73.         $this->textTemplates = new ArrayCollection();
  74.         $this->categories = new ArrayCollection();
  75.         $this->orders = new ArrayCollection();
  76.     }
  77.     /**
  78.      * @return string
  79.      */
  80.     public function __toString(): string {
  81.         return $this->getName();
  82.     }
  83.     /**
  84.      * @return int|null
  85.      */
  86.     public function getId(): ?int {
  87.         return $this->id;
  88.     }
  89.     /**
  90.      * @return string
  91.      */
  92.     public function getName(): string {
  93.         return $this->name;
  94.     }
  95.     /**
  96.      * @param string $name
  97.      *
  98.      * @return self
  99.      */
  100.     public function setName(string $name): self {
  101.         $this->name $name;
  102.         return $this;
  103.     }
  104.     /**
  105.      * @return string
  106.      */
  107.     public function getHostname(): string {
  108.         return $this->hostname;
  109.     }
  110.     /**
  111.      * @param string $hostname
  112.      *
  113.      * @return self
  114.      */
  115.     public function setHostname(string $hostname): self {
  116.         $this->hostname $hostname;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return string
  121.      */
  122.     public function getUploadDirectory(): string {
  123.         return $this->uploadDirectory;
  124.     }
  125.     /**
  126.      * @param string $uploadDirectory
  127.      *
  128.      * @return self
  129.      */
  130.     public function setUploadDirectory(string $uploadDirectory): self {
  131.         $this->uploadDirectory $uploadDirectory;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return TenantConfig|null
  136.      */
  137.     public function getTenantConfig(): ?TenantConfig {
  138.         return $this->tenantConfig;
  139.     }
  140.     /**
  141.      * @return bool
  142.      */
  143.     public function hasTenangConfig(): bool {
  144.         return $this->tenantConfig !== null;
  145.     }
  146.     /**
  147.      * @param TenantConfig $tenantConfig
  148.      *
  149.      * @return self
  150.      */
  151.     public function setTenantConfig(TenantConfig $tenantConfig): self {
  152.         // set the owning side of the relation if necessary
  153.         if ($tenantConfig->getTenant() !== $this) {
  154.             $tenantConfig->setTenant($this);
  155.         }
  156.         $this->tenantConfig $tenantConfig;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection|Faq[]
  161.      */
  162.     public function getFaqs(): Collection {
  163.         return $this->faqs;
  164.     }
  165.     /**
  166.      * @param Faq $faq
  167.      *
  168.      * @return self
  169.      */
  170.     public function addFaq(Faq $faq): self {
  171.         if (!$this->faqs->contains($faq)) {
  172.             $this->faqs[] = $faq;
  173.             $faq->setTenant($this);
  174.         }
  175.         return $this;
  176.     }
  177.     /**
  178.      * @param Faq $faq
  179.      *
  180.      * @return self
  181.      */
  182.     public function removeFaq(Faq $faq): self {
  183.         if ($this->faqs->removeElement($faq)) {
  184.             // set the owning side to null (unless already changed)
  185.             if ($faq->getTenant() === $this) {
  186.                 $faq->setTenant(null);
  187.             }
  188.         }
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return Collection|Product[]
  193.      */
  194.     public function getProducts(): Collection {
  195.         return $this->products;
  196.     }
  197.     /**
  198.      * @param Product $product
  199.      *
  200.      * @return self
  201.      */
  202.     public function addProduct(Product $product): self {
  203.         if (!$this->products->contains($product)) {
  204.             $this->products[] = $product;
  205.             $product->setTenant($this);
  206.         }
  207.         return $this;
  208.     }
  209.     /**
  210.      * @param Product $product
  211.      *
  212.      * @return self
  213.      */
  214.     public function removeProduct(Product $product): self {
  215.         if ($this->products->removeElement($product)) {
  216.             // set the owning side to null (unless already changed)
  217.             if ($product->getTenant() === $this) {
  218.                 $product->setTenant(null);
  219.             }
  220.         }
  221.         return $this;
  222.     }
  223.     /**
  224.      * @return Collection|TextTemplate[]
  225.      */
  226.     public function getTextTemplates(): Collection {
  227.         return $this->textTemplates;
  228.     }
  229.     /**
  230.      * @param TextTemplate $textTemplate
  231.      *
  232.      * @return self
  233.      */
  234.     public function addTextTemplate(TextTemplate $textTemplate): self {
  235.         if (!$this->textTemplates->contains($textTemplate)) {
  236.             $this->textTemplates[] = $textTemplate;
  237.             $textTemplate->setTenant($this);
  238.         }
  239.         return $this;
  240.     }
  241.     /**
  242.      * @param TextTemplate $textTemplate
  243.      *
  244.      * @return self
  245.      */
  246.     public function removeTextTemplate(TextTemplate $textTemplate): self {
  247.         if ($this->textTemplates->removeElement($textTemplate)) {
  248.             // set the owning side to null (unless already changed)
  249.             if ($textTemplate->getTenant() === $this) {
  250.                 $textTemplate->setTenant(null);
  251.             }
  252.         }
  253.         return $this;
  254.     }
  255.     /**
  256.      * @ORM\PrePersist
  257.      */
  258.     public function setDefaults(): self {
  259.         return $this
  260.             ->setCreatedAt(new \DateTime());
  261.     }
  262.     /**
  263.      * @ORM\PreUpdate
  264.      */
  265.     public function setModified(): self {
  266.         return $this
  267.             ->setModifiedAt(new \DateTime());
  268.     }
  269.     /**
  270.      * @return Collection<int, Category>
  271.      */
  272.     public function getCategories(): Collection {
  273.         return $this->categories;
  274.     }
  275.     /**
  276.      * @param Category $category
  277.      *
  278.      * @return self
  279.      */
  280.     public function addCategory(Category $category): self {
  281.         if (!$this->categories->contains($category)) {
  282.             $this->categories[] = $category;
  283.             $category->setTenant($this);
  284.         }
  285.         return $this;
  286.     }
  287.     /**
  288.      * @param Category $category
  289.      *
  290.      * @return self
  291.      */
  292.     public function removeCategory(Category $category): self {
  293.         if ($this->categories->removeElement($category)) {
  294.             // set the owning side to null (unless already changed)
  295.             if ($category->getTenant() === $this) {
  296.                 $category->setTenant(null);
  297.             }
  298.         }
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return Collection<int, Order>
  303.      */
  304.     public function getOrders(): Collection {
  305.         return $this->orders;
  306.     }
  307.     /**
  308.      * @param Order $order
  309.      *
  310.      * @return self
  311.      */
  312.     public function addOrder(Order $order): self {
  313.         if (!$this->orders->contains($order)) {
  314.             $this->orders[] = $order;
  315.             $order->setTenant($this);
  316.         }
  317.         return $this;
  318.     }
  319.     /**
  320.      * @param Order $order
  321.      *
  322.      * @return self
  323.      */
  324.     public function removeOrder(Order $order): self {
  325.         if ($this->orders->removeElement($order)) {
  326.             // set the owning side to null (unless already changed)
  327.             if ($order->getTenant() === $this) {
  328.                 $order->setTenant(null);
  329.             }
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return string|null
  335.      */
  336.     public function getEmail(): ?string {
  337.         return $this->email;
  338.     }
  339.     /**
  340.      * @param string $email
  341.      *
  342.      * @return self
  343.      */
  344.     public function setEmail(string $email): self {
  345.         $this->email $email;
  346.         return $this;
  347.     }
  348.     /**
  349.      * @return string|null
  350.      */
  351.     public function getDvoEmail(): ?string {
  352.         return $this->dvoEmail;
  353.     }
  354.     /**
  355.      * @param string $dvoEmail
  356.      *
  357.      * @return self
  358.      */
  359.     public function setDvoEmail(string $dvoEmail): self {
  360.         $this->dvoEmail $dvoEmail;
  361.         return $this;
  362.     }
  363.     /**
  364.      * @return User|null
  365.      */
  366.     public function getInitialUser(): ?User {
  367.         return $this->initialUser;
  368.     }
  369.     /**
  370.      * @param User|null $initialUser
  371.      *
  372.      * @return self
  373.      */
  374.     public function setInitialUser(?User $initialUser): self {
  375.         $this->initialUser $initialUser;
  376.         return $this;
  377.     }
  378. }