app/Entity/Schema/ORM/Workspace.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Sq\Entity\Schema\ORM;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping AS ORM;
  6. use Sq\Entity\Collection\ImprovedArrayCollection;
  7. use Sq\Entity\Enum;
  8. use Sq\Service\Repository\ORM\WorkspaceRepository;
  9. #[ORM\Entity(repositoryClassWorkspaceRepository::class)]
  10. #[ORM\Table(name'workspaces')]
  11. class Workspace implements BelongsToOrganizationInterface
  12. {
  13.     /**
  14.      *
  15.      * @var int|null
  16.      */
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue(strategy'AUTO')]
  19.     #[ORM\Column(name'ws_id'type'integer'nullablefalseoptions: ['unsigned' => true])]
  20.     private $id;
  21.     /**
  22.      *
  23.      * @var Organization
  24.      */
  25.     #[ORM\ManyToOne(targetEntityOrganization::class, inversedBy'workspaces')]
  26.     #[ORM\JoinColumn(name'ws_o_id'referencedColumnName'o_id'nullablefalse)]
  27.     private $organization;
  28.     /**
  29.      * @var WorkspaceSettings
  30.      */
  31.     #[ORM\OneToOne(targetEntityWorkspaceSettings::class, mappedBy'workspace'cascade: ['persist''remove'])]
  32.     private $settings;
  33.     /**
  34.      * @var Collection
  35.      */
  36.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy'workspaces')]
  37.     private $users;
  38.     /**
  39.      * @var string
  40.      */
  41.     #[ORM\Column(name'ws_name'type'string'nullablefalse)]
  42.     private $name;
  43.     /**
  44.      * @var string
  45.      */
  46.     #[ORM\Column(name'ws_timezone'type'string'length42nullablefalseoptions: ['default' => 'UTC'])]
  47.     private $timezone;
  48.     /**
  49.      * @var bool
  50.      */
  51.     #[ORM\Column(name'ws_deleted'type'boolean'nullablefalseoptions: ['default' => false])]
  52.     private $deleted false;
  53.     /**
  54.      * @var Collection
  55.      */
  56.     #[ORM\OneToMany(targetEntitySocialProfile::class, mappedBy'workspace')]
  57.     private $socialProfiles;
  58.     /**
  59.      * @var Collection
  60.      */
  61.     #[ORM\OneToMany(targetEntityPostCategory::class, mappedBy'workspace'cascade: ['persist''remove'], orphanRemovaltrue)]
  62.     private Collection $postCategories;
  63.     #[ORM\OneToMany(targetEntityQueueSchedule::class, mappedBy'workspace'cascade: ['persist''remove'])]
  64.     private Collection $timeslots;
  65.     /**
  66.      * @var Collection<Bitly>
  67.      */
  68.     #[ORM\OneToMany(targetEntityBitly::class, mappedBy'workspace')]
  69.     private Collection $bitlyAccounts;
  70.     #[ORM\OneToMany(targetEntitySnippet::class, mappedBy'workspace'cascade: ['persist''remove'])]
  71.     private Collection $snippets;
  72.     #[ORM\OneToMany(targetEntityImportSource::class, mappedBy'workspace'cascade: ['persist''remove'])]
  73.     private Collection $importSources;
  74.     #[ORM\OneToMany(targetEntityImportFolder::class, mappedBy'workspace'cascade: ['persist''remove'])]
  75.     private Collection $importFolders;
  76.     #[ORM\OneToOne(targetEntityLegacyAlphaMap::class, mappedBy'workspace')]
  77.     private $legacyAlphaMap;
  78.     public function __construct(
  79.         Organization $organization,
  80.         string $name,
  81.         \DateTimeZone $timezone,
  82.         ?Collection $initialCategories null,
  83.     ) {
  84.         $this->organization $organization;
  85.         $this->name trim($name);
  86.         $this->timezone $timezone->getName();
  87.         $this->settings = new WorkspaceSettings($this);
  88.         $this->users = new ArrayCollection;
  89.         $this->socialProfiles = new ArrayCollection;
  90.         $this->postCategories = new ArrayCollection;
  91.         $this->bitlyAccounts = new ArrayCollection;
  92.         $this->snippets = new ArrayCollection;
  93.         $this->importSources = new ArrayCollection;
  94.         $this->importFolders = new ArrayCollection;
  95.         if ($initialCategories === null)
  96.         {
  97.             $initialCategory = new PostCategory(
  98.                 name'General',
  99.                 colourHexEnum\CategoryColor::LIGHT_GREY,
  100.                 workspace$this,
  101.                 isOnboardingContenttrue
  102.             );
  103.             $this->addCategory($initialCategory);
  104.         }
  105.         else
  106.         {
  107.             foreach ($initialCategories as $category)
  108.             {
  109.                 $this->addCategory($category);
  110.             }
  111.         }
  112.         $organization->addWorkspace($this);
  113.     }
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getWorkspace(): Workspace
  119.     {
  120.         return $this;
  121.     }
  122.     public function getOrganization(): Organization
  123.     {
  124.         return $this->organization;
  125.     }
  126.     public function setOrganization(Organization $organization): self
  127.     {
  128.         $this->organization $organization;
  129.         return $this;
  130.     }
  131.     public function isLegacyWithoutOrganization(): bool
  132.     {
  133.         return false;
  134.     }
  135.     /**
  136.      * @return Collection|User[]
  137.      */
  138.     public function getUsers(): Collection
  139.     {
  140.         return $this->users;
  141.     }
  142.     public function getName(): string
  143.     {
  144.         return $this->name;
  145.     }
  146.     public function setName(string $name): self
  147.     {
  148.         $this->name trim($name);
  149.         return $this;
  150.     }
  151.     public function getTimezone(): \DateTimeZone
  152.     {
  153.         return new \DateTimeZone($this->timezone);
  154.     }
  155.     public function setTimezone(\DateTimeZone $timezone): self
  156.     {
  157.         $this->timezone $timezone->getName();
  158.         return $this;
  159.     }
  160.     public function isDeleted(): bool
  161.     {
  162.         return $this->deleted;
  163.     }
  164.     public function setDeleted(bool $deleted): self
  165.     {
  166.         $this->deleted $deleted;
  167.         return $this;
  168.     }
  169.     public function getSettings(): WorkspaceSettings
  170.     {
  171.         return $this->settings;
  172.     }
  173.     /**
  174.      * @return Collection<SocialProfile>
  175.      */
  176.     public function getSocialProfiles(bool $includeDeleted false): Collection
  177.     {
  178.         $socialProfiles $this->socialProfiles->filter(
  179.             fn (SocialProfile $profile): bool => !$profile->isLegacyOnly()
  180.         );
  181.         if ($includeDeleted)
  182.         {
  183.             return $socialProfiles;
  184.         }
  185.         return $socialProfiles->filter(function (SocialProfile $profile): bool
  186.         {
  187.             return !$profile->isDeleted();
  188.         });
  189.     }
  190.     public function addCategory(PostCategory $category): self
  191.     {
  192.         if (!$this->postCategories->contains($category))
  193.         {
  194.             $this->postCategories->add($category);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeCategory(PostCategory $category): self
  199.     {
  200.         if ($this->postCategories->contains($category))
  201.         {
  202.             $this->postCategories->removeElement($category);
  203.         }
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection|PostCategory[]
  208.      */
  209.     public function getCategories(bool $includeArchived false): Collection
  210.     {
  211.         if ($includeArchived)
  212.         {
  213.             return $this->postCategories;
  214.         }
  215.         return $this->postCategories->filter(function (PostCategory $category): bool
  216.         {
  217.             return !$category->isArchived();
  218.         });
  219.     }
  220.     /**
  221.      * NOTE: This will return timeslots that are attached to archived categories.
  222.      *
  223.      * @return Collection|QueueSchedule[]
  224.      */
  225.     public function getTimeslots(): Collection
  226.     {
  227.         return $this->timeslots;
  228.     }
  229.     /**
  230.      * @return Collection|Snippet[]
  231.      */
  232.     public function getSnippets(): Collection
  233.     {
  234.         return $this->snippets;
  235.     }
  236.     /**
  237.      * @return Collection|ImportSource[]
  238.      */
  239.     public function getImportSources(): Collection
  240.     {
  241.         return $this->importSources
  242.             ->filter(fn (ImportSource $importSource): bool => $importSource->getAutoImport() === null);
  243.     }
  244.     /**
  245.      * @return Collection|ImportFolder[]
  246.      */
  247.     public function getImportFolders(): Collection
  248.     {
  249.         return $this->importFolders;
  250.     }
  251.     /**
  252.      * NOTE: This will return Auto Imports that are attached to archived categories.
  253.      *
  254.      * @return Collection|AutoImport[]
  255.      */
  256.     public function getAutoImports(): Collection
  257.     {
  258.         return $this->importSources
  259.             ->map(fn (ImportSource $importSource): ?AutoImport => $importSource->getAutoImport())
  260.             ->filter(fn (?AutoImport $autoImport): bool => $autoImport !== null);
  261.     }
  262.     public function addSocialProfile(SocialNetwork $socialProfile)
  263.     {
  264.         if (!$this->socialProfiles->contains($socialProfile))
  265.         {
  266.             $this->socialProfiles->add($socialProfile);
  267.         }
  268.     }
  269.     public function removeSocialProfile(SocialNetwork $socialProfile)
  270.     {
  271.         if ($this->socialProfiles->contains($socialProfile))
  272.         {
  273.             $this->socialProfiles->removeElement($socialProfile);
  274.         }
  275.     }
  276.     public function getMobileApps(bool $onlyConnected true): Collection
  277.     {
  278.         $apps = new ImprovedArrayCollection();
  279.         foreach ($this->users as $user)
  280.         {
  281.             foreach ($user->getMobileApps($onlyConnected) as $app)
  282.             {
  283.                 $apps->add($app);
  284.             }
  285.         }
  286.         return $apps;
  287.     }
  288.     public function getAndroidApps(bool $onlyConnected true): Collection
  289.     {
  290.         $apps = new ImprovedArrayCollection();
  291.         foreach ($this->users as $user)
  292.         {
  293.             foreach ($user->getAndroidApps($onlyConnected) as $app)
  294.             {
  295.                 $apps->add($app);
  296.             }
  297.         }
  298.         return $apps;
  299.     }
  300.     public function getIosApps(bool $onlyConnected true): Collection
  301.     {
  302.         $apps = new ImprovedArrayCollection();
  303.         foreach ($this->users as $user)
  304.         {
  305.             foreach ($user->getIosApps($onlyConnected) as $app)
  306.             {
  307.                 $apps->add($app);
  308.             }
  309.         }
  310.         return $apps;
  311.     }
  312. }