src/Entity/Workspace.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\StripeTransactionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\WorkspaceRepository")
  9.  * @ORM\HasLifecycleCallbacks()
  10.  */
  11. class Workspace
  12. {
  13.     public const PAYMENT_NOT_SELECTED 0;
  14.     public const PAYMENT_TYPE_PAYPAL 1;
  15.     public const PAYMENT_TYPE_STRIPE 2;
  16.     /**
  17.      * @ORM\Id()
  18.      * @ORM\GeneratedValue()
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\OneToOne(targetEntity="App\Entity\User")
  24.      */
  25.     private $owner;
  26.     /**
  27.      * @ORM\OneToMany(targetEntity="App\Entity\UserGroup", mappedBy="workspace")
  28.      */
  29.     private $userGroup;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="workspace")
  32.      */
  33.     private $users;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity="App\Entity\Rollout", mappedBy="workspace")
  36.      */
  37.     private $rollouts;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity="App\Entity\DeviceGroup", mappedBy="workspace")
  40.      */
  41.     private $deviceGroups;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity="App\Entity\Device", mappedBy="workspace")
  44.      */
  45.     private $devices;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity="App\Entity\Invoice", mappedBy="workspace")
  48.      */
  49.     private $invoices;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity="App\Entity\FileGroup", mappedBy="workspace")
  52.      */
  53.     private $fileGroups;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity="App\Entity\File", mappedBy="workspace")
  56.      */
  57.     private $files;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity="App\Entity\Support", mappedBy="workspace")
  60.      */
  61.     private $supports;
  62.     /**
  63.      * @ORM\Column(type="string", nullable=true)
  64.      */
  65.     private $customerKey;
  66.     /**
  67.      * @ORM\OneToMany(targetEntity="App\Entity\DeviceKey", mappedBy="workspace")
  68.      */
  69.     private $deviceKeys;
  70.     /**
  71.      * @ORM\OneToMany(targetEntity="App\Entity\SandboxRollout", mappedBy="workspace")
  72.      */
  73.     private $sandboxRollouts;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity="App\Entity\SandboxDeviceGroup", mappedBy="workspace")
  76.      */
  77.     private $sandboxDeviceGroups;
  78.     /**
  79.      * @ORM\OneToMany(targetEntity="App\Entity\SandboxDevice", mappedBy="workspace")
  80.      */
  81.     private $sandboxDevices;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity="App\Entity\SandboxFileGroup", mappedBy="workspace")
  84.      */
  85.     private $sandboxFileGroups;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity="App\Entity\SandboxFile", mappedBy="workspace")
  88.      */
  89.     private $sandboxFiles;
  90.     /**
  91.      * @ORM\Column(type="boolean", options={"default" : false}))
  92.      */
  93.     private $disabled false;
  94.     /**
  95.      * @ORM\Column(type="boolean", options={"default" : false}))
  96.      */
  97.     private $deleted false;
  98.     /**
  99.      * @ORM\ManyToMany(targetEntity="App\Entity\Plan")
  100.      * @ORM\JoinTable(name="workspace_plan",
  101.      *      joinColumns={@ORM\JoinColumn(name="workspace_id", referencedColumnName="id")},
  102.      *      inverseJoinColumns={@ORM\JoinColumn(name="plan_id", referencedColumnName="id")}
  103.      *      )
  104.      */
  105.     private $plans;
  106.     /**
  107.      * @ORM\OneToMany(targetEntity=PayPalTransaction::class, mappedBy="workspace", orphanRemoval=true)
  108.      */
  109.     private $payPalTransactions;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity=StripeTransaction::class, mappedBy="workspace", orphanRemoval=true)
  112.      */
  113.     private $stripeTransactions;
  114.     /**
  115.      * @ORM\OneToMany(targetEntity=PlanChange::class, mappedBy="workspace", orphanRemoval=true)
  116.      */
  117.     private $planChanges;
  118.     /**
  119.      * @ORM\Column(type="datetime", nullable=true)
  120.      */
  121.     private $lastAvailableUpdatesMailSent null;
  122.     /**
  123.      * @ORM\Column(type="integer", options={"default": 0}))
  124.      */
  125.     private $paymentType 0;
  126.     public function __construct()
  127.     {
  128.         $this->userGroup = new ArrayCollection();
  129.         $this->users = new ArrayCollection();
  130.         $this->rollouts = new ArrayCollection();
  131.         $this->deviceGroups = new ArrayCollection();
  132.         $this->devices = new ArrayCollection();
  133.         $this->invoices = new ArrayCollection();
  134.         $this->fileGroups = new ArrayCollection();
  135.         $this->files = new ArrayCollection();
  136.         $this->supports = new ArrayCollection();
  137.         $this->sandboxRollouts = new ArrayCollection();
  138.         $this->sandboxDeviceGroups = new ArrayCollection();
  139.         $this->sandboxDevices = new ArrayCollection();
  140.         $this->sandboxFileGroups = new ArrayCollection();
  141.         $this->sandboxFiles = new ArrayCollection();
  142.         $this->plans = new ArrayCollection();
  143.         $this->payPalTransactions = new ArrayCollection();
  144.         $this->planChanges = new ArrayCollection();
  145.         $this->deviceKeys = new ArrayCollection();
  146.     }
  147.     public function getId(): ?int
  148.     {
  149.         return $this->id;
  150.     }
  151.     public function getOwner(): ?User
  152.     {
  153.         return $this->owner;
  154.     }
  155.     public function setOwner(?User $owner): self
  156.     {
  157.         $this->owner $owner;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection|UserGroup[]
  162.      */
  163.     public function getUserGroup(): Collection
  164.     {
  165.         return $this->userGroup;
  166.     }
  167.     public function addUserGroup(UserGroup $userGroup): self
  168.     {
  169.         if (!$this->userGroup->contains($userGroup)) {
  170.             $this->userGroup[] = $userGroup;
  171.             $userGroup->setWorkspace($this);
  172.         }
  173.         return $this;
  174.     }
  175.     public function removeUserGroup(UserGroup $userGroup): self
  176.     {
  177.         if ($this->userGroup->contains($userGroup)) {
  178.             $this->userGroup->removeElement($userGroup);
  179.             // set the owning side to null (unless already changed)
  180.             if ($userGroup->getWorkspace() === $this) {
  181.                 $userGroup->setWorkspace(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return Collection|User[]
  188.      */
  189.     public function getUsers(): Collection
  190.     {
  191.         return $this->users;
  192.     }
  193.     public function addUser(User $user): self
  194.     {
  195.         if (!$this->users->contains($user)) {
  196.             $this->users->add($user);
  197.             $user->setWorkspace($this);
  198.         }
  199.         return $this;
  200.     }
  201.     public function removeUser(User $user): self
  202.     {
  203.         if ($this->users->contains($user)) {
  204.             $this->users->removeElement($user);
  205.             // set the owning side to null (unless already changed)
  206.             if ($user->getWorkspace() === $this) {
  207.                 $user->setWorkspace(null);
  208.             }
  209.         }
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return int
  214.      */
  215.     public function getAvailableUpdates(): int
  216.     {
  217.         if (is_object($this->getPlan())) {
  218.             $allowed $this->getPlan()->getAllowedDevices();
  219.             $countDevices count($this->getFilteredUsedDevices());
  220.             return ((($allowed $countDevices) < 0) ? : ($allowed $countDevices));
  221.         }
  222.         return 0;
  223.     }
  224.     /**
  225.      * @return int
  226.      */
  227.     public function getActiveDevices(): int
  228.     {
  229.         return count($this->getFilteredUsedDevices());
  230.     }
  231.     /**
  232.      * @return int
  233.      */
  234.     public function getUsedDevices(): int
  235.     {
  236.         if (is_object($this->getPlan())) {
  237.             return count($this->getFilteredUsedDevices());
  238.         }
  239.         return 0;
  240.     }
  241.     /**
  242.      * @return Collection
  243.      */
  244.     private function getFilteredUsedDevices(): Collection
  245.     {
  246.         return $this->getDevices()->filter(function (Device $device) {
  247.             return (
  248.                 ($device->getBlackListed() === false && $device->getTransactionId() !== null)
  249.                 or
  250.                 ($device->getBlackListed() === false && $device->getDeviceGroup() !== null)
  251.             );
  252.         });
  253.     }
  254.     /**
  255.      * @return Collection|Rollout[]
  256.      */
  257.     public function getRollouts(): Collection
  258.     {
  259.         return $this->rollouts;
  260.     }
  261.     /**
  262.      * @param Rollout $rollout
  263.      * @return $this
  264.      */
  265.     public function addRollout(Rollout $rollout): self
  266.     {
  267.         if (!$this->rollouts->contains($rollout)) {
  268.             $this->rollouts->add($rollout);
  269.             $rollout->setWorkspace($this);
  270.         }
  271.         return $this;
  272.     }
  273.     public function removeRollout(Rollout $rollout): self
  274.     {
  275.         if ($this->rollouts->contains($rollout)) {
  276.             $this->rollouts->removeElement($rollout);
  277.             // set the owning side to null (unless already changed)
  278.             if ($rollout->getWorkspace() === $this) {
  279.                 $rollout->setWorkspace(null);
  280.             }
  281.         }
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection|DeviceGroup[]
  286.      */
  287.     public function getDeviceGroups(): Collection
  288.     {
  289.         return $this->deviceGroups;
  290.     }
  291.     /**
  292.      * @param DeviceGroup $deviceGroup
  293.      * @return $this
  294.      */
  295.     public function addDeviceGroup(DeviceGroup $deviceGroup): self
  296.     {
  297.         if (!$this->deviceGroups->contains($deviceGroup)) {
  298.             $this->deviceGroups->add($deviceGroup);
  299.             $deviceGroup->setWorkspace($this);
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @param DeviceGroup $deviceGroup
  305.      * @return $this
  306.      */
  307.     public function removeDeviceGroup(DeviceGroup $deviceGroup): self
  308.     {
  309.         if ($this->deviceGroups->contains($deviceGroup)) {
  310.             $this->deviceGroups->removeElement($deviceGroup);
  311.             if ($deviceGroup->getWorkspace() === $this) {
  312.                 $deviceGroup->setWorkspace(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|Device[]
  319.      */
  320.     public function getDevices(): Collection
  321.     {
  322.         return $this->devices;
  323.     }
  324.     /**
  325.      * @param Device $device
  326.      * @return $this
  327.      */
  328.     public function addDevice(Device $device): self
  329.     {
  330.         if (!$this->devices->contains($device)) {
  331.             $this->devices->add($device);
  332.             $device->setWorkspace($this);
  333.         }
  334.         return $this;
  335.     }
  336.     /**
  337.      * @param Device $device
  338.      * @return $this
  339.      */
  340.     public function removeDevice(Device $device): self
  341.     {
  342.         if ($this->devices->contains($device)) {
  343.             $this->devices->removeElement($device);
  344.             if ($device->getWorkspace() === $this) {
  345.                 $device->setWorkspace(null);
  346.             }
  347.         }
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return Collection|FileGroup[]
  352.      */
  353.     public function getFileGroups(): Collection
  354.     {
  355.         return $this->fileGroups;
  356.     }
  357.     /**
  358.      * @param FileGroup $fileGroup
  359.      * @return $this
  360.      */
  361.     public function addFileGroup(FileGroup $fileGroup): self
  362.     {
  363.         if (!$this->fileGroups->contains($fileGroup)) {
  364.             $this->fileGroups->add($fileGroup);
  365.             $fileGroup->setWorkspace($this);
  366.         }
  367.         return $this;
  368.     }
  369.     /**
  370.      * @param FileGroup $fileGroup
  371.      * @return $this
  372.      */
  373.     public function removeFileGroup(FileGroup $fileGroup): self
  374.     {
  375.         if ($this->fileGroups->contains($fileGroup)) {
  376.             $this->fileGroups->removeElement($fileGroup);
  377.             if ($fileGroup->getWorkspace() === $this) {
  378.                 $fileGroup->setWorkspace(null);
  379.             }
  380.         }
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return Collection|File[]
  385.      */
  386.     public function getFiles(): Collection
  387.     {
  388.         return $this->files;
  389.     }
  390.     /**
  391.      * @param File $file
  392.      * @return $this
  393.      */
  394.     public function addFile(File $file): self
  395.     {
  396.         if (!$this->files->contains($file)) {
  397.             $this->files->add($file);
  398.             $file->setWorkspace($this);
  399.         }
  400.         return $this;
  401.     }
  402.     /**
  403.      * @param File $file
  404.      * @return $this
  405.      */
  406.     public function removeFile(File $file): self
  407.     {
  408.         if ($this->files->contains($file)) {
  409.             $this->files->removeElement($file);
  410.             if ($file->getWorkspace() === $this) {
  411.                 $file->setWorkspace(null);
  412.             }
  413.         }
  414.         return $this;
  415.     }
  416.     public function getCustomerKey(): ?string
  417.     {
  418.         return $this->customerKey;
  419.     }
  420.     public function setCustomerKey(?string $customerKey): self
  421.     {
  422.         $this->customerKey $customerKey;
  423.         return $this;
  424.     }
  425.     public function getDeviceKey(): ?string
  426.     {
  427.         if (count($this->deviceKeys) > 0) {
  428.             /** @var DeviceKey $deviceKey */
  429.             $deviceKey $this->deviceKeys->first();
  430.             return $deviceKey->getDeviceKey();
  431.         }
  432.         return null;
  433.     }
  434.     /**
  435.      * @return Collection|Support[]
  436.      */
  437.     public function getSupports(): Collection
  438.     {
  439.         return $this->supports;
  440.     }
  441.     /**
  442.      * @param Support $support
  443.      * @return $this
  444.      */
  445.     public function addSupport(Support $support): self
  446.     {
  447.         if (!$this->supports->contains($support)) {
  448.             $this->supports->add($support);
  449.             $support->setWorkspace($this);
  450.         }
  451.         return $this;
  452.     }
  453.     /**
  454.      * @param Support $support
  455.      * @return $this
  456.      */
  457.     public function removeSupport(Support $support): self
  458.     {
  459.         if ($this->supports->contains($support)) {
  460.             $this->supports->removeElement($support);
  461.             if ($support->getWorkspace() === $this) {
  462.                 $support->setWorkspace(null);
  463.             }
  464.         }
  465.         return $this;
  466.     }
  467.     /**
  468.      * @return Collection|SandboxRollout[]
  469.      */
  470.     public function getSandboxRollouts(): Collection
  471.     {
  472.         return $this->sandboxRollouts;
  473.     }
  474.     /**
  475.      * @param SandboxRollout $sandboxRollout
  476.      * @return $this
  477.      */
  478.     public function addSandboxRollout(SandboxRollout $sandboxRollout): self
  479.     {
  480.         if (!$this->sandboxRollouts->contains($sandboxRollout)) {
  481.             $this->sandboxRollouts->add($sandboxRollout);
  482.             $sandboxRollout->setWorkspace($this);
  483.         }
  484.         return $this;
  485.     }
  486.     /**
  487.      * @param SandboxRollout $sandboxRollout
  488.      * @return $this
  489.      */
  490.     public function removeSandboxRollout(SandboxRollout $sandboxRollout): self
  491.     {
  492.         if ($this->sandboxRollouts->contains($sandboxRollout)) {
  493.             $this->sandboxRollouts->removeElement($sandboxRollout);
  494.             // set the owning side to null (unless already changed)
  495.             if ($sandboxRollout->getWorkspace() === $this) {
  496.                 $sandboxRollout->setWorkspace(null);
  497.             }
  498.         }
  499.         return $this;
  500.     }
  501.     /**
  502.      * @return Collection|SandboxDeviceGroup[]
  503.      */
  504.     public function getSandboxDeviceGroups(): Collection
  505.     {
  506.         return $this->sandboxDeviceGroups;
  507.     }
  508.     /**
  509.      * @param SandboxDeviceGroup $sandboxDeviceGroup
  510.      * @return $this
  511.      */
  512.     public function addSandboxDeviceGroup(SandboxDeviceGroup $sandboxDeviceGroup): self
  513.     {
  514.         if (!$this->sandboxDeviceGroups->contains($sandboxDeviceGroup)) {
  515.             $this->sandboxDeviceGroups->add($sandboxDeviceGroup);
  516.             $sandboxDeviceGroup->setWorkspace($this);
  517.         }
  518.         return $this;
  519.     }
  520.     /**
  521.      * @param SandboxDeviceGroup $sandboxDeviceGroup
  522.      * @return $this
  523.      */
  524.     public function removeSandboxDeviceGroup(SandboxDeviceGroup $sandboxDeviceGroup): self
  525.     {
  526.         if ($this->sandboxDeviceGroups->contains($sandboxDeviceGroup)) {
  527.             $this->sandboxDeviceGroups->removeElement($sandboxDeviceGroup);
  528.             if ($sandboxDeviceGroup->getWorkspace() === $this) {
  529.                 $sandboxDeviceGroup->setWorkspace(null);
  530.             }
  531.         }
  532.         return $this;
  533.     }
  534.     /**
  535.      * @return Collection|SandboxDeviceGroup[]
  536.      */
  537.     public function getSandboxDevices(): Collection
  538.     {
  539.         return $this->sandboxDevices;
  540.     }
  541.     /**
  542.      * @param SandboxDevice $sandboxDevice
  543.      * @return $this
  544.      */
  545.     public function addSandboxDevice(SandboxDevice $sandboxDevice): self
  546.     {
  547.         if (!$this->sandboxDevices->contains($sandboxDevice)) {
  548.             $this->sandboxDevices->add($sandboxDevice);
  549.             $sandboxDevice->setWorkspace($this);
  550.         }
  551.         return $this;
  552.     }
  553.     /**
  554.      * @param SandboxDevice $sandboxDevice
  555.      * @return $this
  556.      */
  557.     public function removeSandboxDevice(SandboxDevice $sandboxDevice): self
  558.     {
  559.         if ($this->sandboxDevices->contains($sandboxDevice)) {
  560.             $this->sandboxDevices->removeElement($sandboxDevice);
  561.             if ($sandboxDevice->getWorkspace() === $this) {
  562.                 $sandboxDevice->setWorkspace(null);
  563.             }
  564.         }
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return Collection|SandboxFileGroup[]
  569.      */
  570.     public function getSandboxFileGroups(): Collection
  571.     {
  572.         return $this->sandboxFileGroups;
  573.     }
  574.     /**
  575.      * @param SandboxFileGroup $sandboxFileGroup
  576.      * @return $this
  577.      */
  578.     public function addSandboxFileGroup(SandboxFileGroup $sandboxFileGroup): self
  579.     {
  580.         if (!$this->sandboxFileGroups->contains($sandboxFileGroup)) {
  581.             $this->sandboxFileGroups->add($sandboxFileGroup);
  582.             $sandboxFileGroup->setWorkspace($this);
  583.         }
  584.         return $this;
  585.     }
  586.     /**
  587.      * @param SandboxFileGroup $sandboxFileGroup
  588.      * @return $this
  589.      */
  590.     public function removeSandboxFileGroup(SandboxFileGroup $sandboxFileGroup): self
  591.     {
  592.         if ($this->sandboxFileGroups->contains($sandboxFileGroup)) {
  593.             $this->sandboxFileGroups->removeElement($sandboxFileGroup);
  594.             if ($sandboxFileGroup->getWorkspace() === $this) {
  595.                 $sandboxFileGroup->setWorkspace(null);
  596.             }
  597.         }
  598.         return $this;
  599.     }
  600.     /**
  601.      * @return Collection|SandboxFile[]
  602.      */
  603.     public function getSandboxFiles(): Collection
  604.     {
  605.         return $this->sandboxFiles;
  606.     }
  607.     /**
  608.      * @param SandboxFile $sandboxFile
  609.      * @return $this
  610.      */
  611.     public function addSandboxFile(SandboxFile $sandboxFile): self
  612.     {
  613.         if (!$this->sandboxFiles->contains($sandboxFile)) {
  614.             $this->sandboxFiles->add($sandboxFile);
  615.             $sandboxFile->setWorkspace($this);
  616.         }
  617.         return $this;
  618.     }
  619.     /**
  620.      * @param SandboxFile $sandboxFile
  621.      * @return $this
  622.      */
  623.     public function removeSandboxFile(SandboxFile $sandboxFile): self
  624.     {
  625.         if ($this->sandboxFiles->contains($sandboxFile)) {
  626.             $this->sandboxFiles->removeElement($sandboxFile);
  627.             if ($sandboxFile->getWorkspace() === $this) {
  628.                 $sandboxFile->setWorkspace(null);
  629.             }
  630.         }
  631.         return $this;
  632.     }
  633.     /**
  634.      * @return bool
  635.      */
  636.     public function isDisabled(): bool
  637.     {
  638.         return $this->disabled;
  639.     }
  640.     /**
  641.      * @param bool $disabled
  642.      */
  643.     public function setDisabled(bool $disabled): void
  644.     {
  645.         $this->disabled $disabled;
  646.     }
  647.     /**
  648.      * @return Plan|null
  649.      */
  650.     public function getPlan(): ?Plan
  651.     {
  652.         if (count($this->plans) > 0) {
  653.             return $this->plans->first();
  654.         }
  655.         return null;
  656.     }
  657.     /**
  658.      * @param Plan $plan
  659.      * @return $this
  660.      */
  661.     public function setPlan(Plan $plan): self
  662.     {
  663.         if (!$this->plans->contains($plan)) {
  664.             $this->plans->clear();
  665.             $this->plans->add($plan);
  666.         }
  667.         return $this;
  668.     }
  669.     /**
  670.      * @return Collection|PayPalTransaction[]
  671.      */
  672.     public function getPayPalTransactions(): Collection
  673.     {
  674.         return $this->payPalTransactions;
  675.     }
  676.     public function addPayPalTransaction(PayPalTransaction $payPalTransaction): self
  677.     {
  678.         if (!$this->payPalTransactions->contains($payPalTransaction)) {
  679.             $this->payPalTransactions[] = $payPalTransaction;
  680.             $payPalTransaction->setWorkspace($this);
  681.         }
  682.         return $this;
  683.     }
  684.     public function removePayPalTransaction(PayPalTransaction $payPalTransaction): self
  685.     {
  686.         if ($this->payPalTransactions->removeElement($payPalTransaction)) {
  687.             // set the owning side to null (unless already changed)
  688.             if ($payPalTransaction->getWorkspace() === $this) {
  689.                 $payPalTransaction->setWorkspace(null);
  690.             }
  691.         }
  692.         return $this;
  693.     }
  694.     /**
  695.      * @param string|null $planId
  696.      * @return bool
  697.      */
  698.     public function hasAuthorization(?string $planId): bool
  699.     {
  700.         if ($this->getPaymentType() == Workspace::PAYMENT_TYPE_PAYPAL) {
  701.             /** @var PayPalTransaction $transaction */
  702.             foreach ($this->payPalTransactions as $transaction) {
  703.                 if (
  704.                     $transaction->getStatus() === PayPalTransaction::STATUS_SUCCESS
  705.                     && $transaction->getType() === PayPalTransaction::AUTHORIZE &&
  706.                     $transaction->getPayPalPlanId() === $planId
  707.                     &&
  708.                     !empty($transaction->getAuthId())
  709.                 ) {
  710.                     return true;
  711.                 }
  712.             }
  713.         } elseif ($this->getPaymentType() == Workspace::PAYMENT_TYPE_STRIPE) {
  714.                 /** @var StripeTransaction $transaction */
  715.                 foreach ($this->stripeTransactions as $transaction) {
  716.                     if (
  717.                         $transaction->getStatus() === StripeTransaction::STATUS_SUCCESS
  718.                         && $transaction->getType() === StripeTransaction::AUTHORIZE &&
  719.                         $transaction->getStripePlanId() === $planId
  720.                         &&
  721.                         !empty($transaction->getSessionId())
  722.                     ) {
  723.                         return true;
  724.                     }
  725.             }
  726.         }
  727.         return false;
  728.     }
  729.     /**
  730.      * @param string|null $planId
  731.      * @return PayPalTransaction|StripeTransaction|null
  732.      */
  733.     public function getActiveAuthorization(?string $planId)
  734.     {
  735.         if ($this->getPaymentType() == Workspace::PAYMENT_TYPE_PAYPAL) {
  736.             /** @var PayPalTransaction $transaction */
  737.             foreach ($this->payPalTransactions as $transaction) {
  738.                 if (
  739.                     $transaction->getStatus() === PayPalTransaction::STATUS_SUCCESS
  740.                     && $transaction->getType() === PayPalTransaction::AUTHORIZE &&
  741.                     $transaction->getPayPalPlanId() === $planId
  742.                     &&
  743.                     !empty($transaction->getAuthId())
  744.                 ) {
  745.                     return $transaction;
  746.                 }
  747.             }
  748.         } elseif ($this->getPaymentType() == Workspace::PAYMENT_TYPE_STRIPE) {
  749.             /** @var StripeTransaction $transaction */
  750.             foreach ($this->stripeTransactions as $transaction) {
  751.                 if (
  752.                     $transaction->getStatus() === StripeTransaction::STATUS_SUCCESS
  753.                     && $transaction->getType() === StripeTransaction::AUTHORIZE &&
  754.                     $transaction->getStripePlanId() === $planId
  755.                     &&
  756.                     !empty($transaction->getSessionId())
  757.                 ) {
  758.                     return $transaction;
  759.                 }
  760.             }
  761.         }
  762.         return null;
  763.     }
  764.     /**
  765.      * @param string|null $payPalPlanId
  766.      * @return PayPalTransaction|null
  767.      */
  768.     public function getPendingAuthorization(?string $payPalPlanId): ?PayPalTransaction
  769.     {
  770.         /** @var PayPalTransaction $transaction */
  771.         foreach ($this->payPalTransactions as $transaction) {
  772.             if (
  773.                 $transaction->getStatus() === PayPalTransaction::STATUS_PENDING
  774.                 && $transaction->getType() === PayPalTransaction::AUTHORIZE &&
  775.                 $transaction->getPayPalPlanId() === $payPalPlanId &&
  776.                 !empty($transaction->getAuthId())
  777.             ) {
  778.                 return $transaction;
  779.             }
  780.         }
  781.         return null;
  782.     }
  783.     /**
  784.      * @return Collection|PlanChange[]
  785.      */
  786.     public function getPlanChanges(): Collection
  787.     {
  788.         return $this->planChanges;
  789.     }
  790.     public function addPlanChange(PlanChange $planChange): self
  791.     {
  792.         if (!$this->planChanges->contains($planChange)) {
  793.             $this->planChanges[] = $planChange;
  794.             $planChange->setWorkspace($this);
  795.         }
  796.         return $this;
  797.     }
  798.     public function removePlanChange(PlanChange $planChange): self
  799.     {
  800.         if ($this->planChanges->removeElement($planChange)) {
  801.             // set the owning side to null (unless already changed)
  802.             if ($planChange->getWorkspace() === $this) {
  803.                 $planChange->setWorkspace(null);
  804.             }
  805.         }
  806.         return $this;
  807.     }
  808.     /**
  809.      * @return bool
  810.      */
  811.     public function hasOpenedPlanChange(): bool
  812.     {
  813.         /** @var PlanChange $planChange */
  814.         foreach ($this->planChanges as $planChange) {
  815.             if ($planChange->getClosed() === false) {
  816.                 return true;
  817.             }
  818.         }
  819.         return false;
  820.     }
  821.     /**
  822.      * @return PlanChange|null
  823.      */
  824.     public function getOpenedPlanChange(): ?PlanChange
  825.     {
  826.         /** @var PlanChange $planChange */
  827.         foreach ($this->planChanges as $planChange) {
  828.             if ($planChange->getClosed() === false) {
  829.                 return $planChange;
  830.             }
  831.         }
  832.         return null;
  833.     }
  834.     /**
  835.      * @return Collection|Invoice[]
  836.      */
  837.     public function getInvoices(): Collection
  838.     {
  839.         return $this->invoices;
  840.     }
  841.     /**
  842.      * @param Invoice $invoice
  843.      * @return $this
  844.      */
  845.     public function addInvoice(Invoice $invoice): self
  846.     {
  847.         if (!$this->invoices->contains($invoice)) {
  848.             $this->invoices->add($invoice);
  849.             $invoice->setWorkspace($this);
  850.         }
  851.         return $this;
  852.     }
  853.     /**
  854.      * @param Invoice $invoice
  855.      * @return $this
  856.      */
  857.     public function removeInvoice(Invoice $invoice): self
  858.     {
  859.         if ($this->invoices->contains($invoice)) {
  860.             $this->invoices->removeElement($invoice);
  861.             if ($invoice->getWorkspace() === $this) {
  862.                 $invoice->setWorkspace(null);
  863.             }
  864.         }
  865.         return $this;
  866.     }
  867.     /**
  868.      * @return bool
  869.      */
  870.     public function isDeleted(): bool
  871.     {
  872.         return $this->deleted;
  873.     }
  874.     /**
  875.      * @param bool $deleted
  876.      */
  877.     public function setDeleted(bool $deleted): void
  878.     {
  879.         $this->deleted $deleted;
  880.     }
  881.     /**
  882.      * @return null
  883.      */
  884.     public function getLastAvailableUpdatesMailSent()
  885.     {
  886.         return $this->lastAvailableUpdatesMailSent;
  887.     }
  888.     /**
  889.      * @param null $lastAvailableUpdatesMailSent
  890.      */
  891.     public function setLastAvailableUpdatesMailSent($lastAvailableUpdatesMailSent): void
  892.     {
  893.         $this->lastAvailableUpdatesMailSent $lastAvailableUpdatesMailSent;
  894.     }
  895.     /**
  896.      * @return Collection|DeviceKey[]
  897.      */
  898.     public function getDeviceKeys(): Collection
  899.     {
  900.         return $this->deviceKeys;
  901.     }
  902.     /**
  903.      * @param DeviceKey $deviceKey
  904.      * @return $this
  905.      */
  906.     public function addDeviceKey(DeviceKey $deviceKey): self
  907.     {
  908.         if (!$this->deviceKeys->contains($deviceKey)) {
  909.             $this->deviceKeys->add($deviceKey);
  910.             $deviceKey->setWorkspace($this);
  911.         }
  912.         return $this;
  913.     }
  914.     /**
  915.      * @param DeviceKey $deviceKey
  916.      * @return $this
  917.      */
  918.     public function removeDeviceKey(DeviceKey $deviceKey): self
  919.     {
  920.         if ($this->deviceKeys->contains($deviceKey)) {
  921.             $this->deviceKeys->removeElement($deviceKey);
  922.         }
  923.         return $this;
  924.     }
  925.     /**
  926.      * @return mixed
  927.      */
  928.     public function getStripeTransactions()
  929.     {
  930.         return $this->stripeTransactions;
  931.     }
  932.     /**
  933.      * @param mixed $stripeTransactions
  934.      */
  935.     public function setStripeTransactions($stripeTransactions): void
  936.     {
  937.         $this->stripeTransactions $stripeTransactions;
  938.     }
  939.     /**
  940.      * @return mixed
  941.      */
  942.     public function getPaymentType()
  943.     {
  944.         return $this->paymentType;
  945.     }
  946.     /**
  947.      * @param mixed $paymentType
  948.      */
  949.     public function setPaymentType($paymentType): void
  950.     {
  951.         $this->paymentType $paymentType;
  952.     }
  953. }