<?php
namespace App\Entity;
use App\Filter\CompanyFilter;
use App\Annotation\EsUploadable;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CompanyRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\ClientMappedInterface;
use App\Entity\Interfaces\UploadMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_SUPER_ADMIN')", "filters"={"translation.groups"}},
* normalizationContext={"groups"={"Company:Read"}, "skip_null_values"=false, "enable_max_depth"=true},
* denormalizationContext={"groups"={"Company:Write"}},
* collectionOperations={
* "get",
* "get_overview"={
* "path"="/companies/get-overview",
* "method"="GET",
* "normalization_context"={"groups"={"Company:Overview"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "get_all"={
* "path"="/companies/get-all",
* "method"="GET",
* "pagination_enabled"=false,
* "normalization_context"={"groups"={"Company:Read"}, "skip_null_values"=false},
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "get_for_public_page"={
* "route_name"="api_pub_companies_get_for_public_page_collection",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"Company:PRead"}, "skip_null_values"=false}
* },
* "post"
* },
* itemOperations={
* "get"={
* "security"="is_granted('IS_AUTHENTICATED_FULLY')",
* "normalization_context"={"groups"={"Company:Read", "Company:Detail"}, "skip_null_values"=false}
* },
* "get_for_public_item_page"={
* "route_name"="api_pub_companies_get_for_public_page_item",
* "method"="GET",
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"Company:PRead", "Company:PIRead"}, "skip_null_values"=false}
* },
* "put"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE', object)"},
* "patch"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE', object)"},
* "delete"
* }
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "client.id": "exact", "containers.id": "exact", "externalId": "exact", "name": "partial", "website": "partial", "followers.id": "exact", "owners.id": "exact", "companyCategory.id": "exact", "companyTags.id": "exact"})
* @ApiFilter(CompanyFilter::class, properties={"search": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC", "companyCategory.translations.name"})
* @ORM\Entity(repositoryClass=CompanyRepository::class)
*/
class Company implements ClientMappedInterface, UploadMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"Company:Read", "Company:Overview", "Company:PRead", "Conference:Read", "Newsfeed:Read", "Session:GetItemDetail", "User:Me", "Conference:PRead", "User:PRead", "ElCourse:Read", "ElCourse:PRead"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"Company:Read", "Company:Write", "Company:Overview", "Company:PRead", "Conference:Read", "Newsfeed:Read", "Session:GetItemDetail", "User:Me", "Conference:PRead", "User:PRead", "ElCourse:Read", "ElCourse:PRead"})
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:Overview", "Company:PRead", "Conference:Read", "Newsfeed:Read", "Session:GetItemDetail", "Conference:PRead", "User:PRead", "ElCourse:Read", "ElCourse:PRead"})
*/
private $website;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PIRead"})
*/
private $description;
/**
* @ORM\Column(type="string", length=128, nullable=true)
* @Groups({"Company:Read", "Company:Write"})
*/
private $externalId;
/**
* @ORM\Column(type="json", nullable=true)
* @Groups({"Company:Read", "Company:Write"})
*/
private $details = [];
/**
* @ORM\ManyToOne(targetEntity=Client::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"Company:Read", "Company:Write"})
*/
private $client;
/**
* @ORM\ManyToMany(targetEntity=Container::class)
* @Groups({"Company:Detail", "Company:Write"})
*/
private $containers;
/**
* @ApiProperty(attributes={"fetch_eager": false})
* @ORM\ManyToMany(targetEntity=CompanyTag::class, mappedBy="companies", cascade={"persist"})
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $companyTags;
/**
* @ApiProperty(attributes={"fetch_eager": false})
* @ORM\ManyToOne(targetEntity=CommonCategory::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
* @Groups({"Company:Read", "Company:Write", "Company:Overview", "Company:PRead"})
*/
private $companyCategory;
/**
* @ApiProperty(attributes={"fetch_eager": false})
* @ORM\ManyToMany(targetEntity=User::class)
* @ORM\JoinTable(name="company_owner")
* @Groups({"Company:Read", "Company:Write"})
*/
private $owners;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="organization")
*/
private $users;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:Overview", "Company:PRead", "Conference:Read", "Newsfeed:Read", "Session:GetItemDetail", "Conference:PRead", "User:PRead", "ElCourse:Read", "ElCourse:PRead"})
* @EsUploadable()
*/
private $logoImageName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:Overview", "Company:PRead", "Conference:Read", "Newsfeed:Read", "Session:GetItemDetail", "Conference:PRead", "User:PRead", "ElCourse:Read", "ElCourse:PRead"})
* @EsUploadable()
*/
private $coverImageName;
/**
* @ORM\OneToMany(targetEntity=CompanyProduct::class, mappedBy="company", orphanRemoval=true)
*/
private $companyProducts;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:Overview", "Company:PRead", "Newsfeed:Read"})
*/
private $tagline;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $contactEmail;
/**
* @ORM\Column(type="string", length=32, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PIRead"})
*/
private $streamUrl;
/**
* @ORM\Column(type="string", length=32, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PIRead"})
*/
private $streamType;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="followingCompanies")
*/
private $followers;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"Company:Read", "Company:Overview", "Company:PRead"})
*/
private $totalFollowers;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="offCompanyNotifications")
*/
private $offNotificationUsers;
/**
* @ORM\OneToMany(targetEntity=Newsfeed::class, mappedBy="company")
*/
private $newsfeeds;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $industry;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $size;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $address1;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $address2;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $postalCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $state;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $country;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $socialLinkedin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $socialX;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $socialFacebook;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $socialInstagram;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Company:Read", "Company:Write", "Company:PRead"})
*/
private $socialYoutube;
/**
* @ORM\ManyToMany(targetEntity=Container::class)
* @ORM\JoinTable(name="rel_owner_container_company")
* @Groups({"Company:Detail", "Company:Write"})
*/
private $ownerContainers;
public function __construct()
{
$this->containers = new ArrayCollection();
$this->companyTags = new ArrayCollection();
$this->owners = new ArrayCollection();
$this->users = new ArrayCollection();
$this->companyProducts = new ArrayCollection();
$this->followers = new ArrayCollection();
$this->offNotificationUsers = new ArrayCollection();
$this->newsfeeds = new ArrayCollection();
$this->ownerContainers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): self
{
$this->website = $website;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getExternalId(): ?string
{
return $this->externalId;
}
public function setExternalId(?string $externalId): self
{
$this->externalId = $externalId;
return $this;
}
public function getDetails(): ?array
{
return $this->details;
}
public function setDetails(?array $details): self
{
$this->details = $details;
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): self
{
$this->client = $client;
return $this;
}
/**
* @return Collection<int, Container>
*/
public function getContainers(): Collection
{
return $this->containers;
}
public function addContainer(Container $container): self
{
if (!$this->containers->contains($container)) {
$this->containers[] = $container;
}
return $this;
}
public function removeContainer(Container $container): self
{
$this->containers->removeElement($container);
return $this;
}
/**
* @return Collection<int, CompanyTag>
*/
public function getCompanyTags(): Collection
{
return $this->companyTags;
}
public function addCompanyTag(CompanyTag $companyTag): self
{
if (!$this->companyTags->contains($companyTag)) {
$this->companyTags[] = $companyTag;
$companyTag->addCompany($this);
}
return $this;
}
public function removeCompanyTag(CompanyTag $companyTag): self
{
if ($this->companyTags->removeElement($companyTag)) {
$companyTag->removeCompany($this);
}
return $this;
}
public function getCompanyCategory(): ?CommonCategory
{
return $this->companyCategory;
}
public function setCompanyCategory(?CommonCategory $companyCategory): self
{
$this->companyCategory = $companyCategory;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getOwners(): Collection
{
return $this->owners;
}
public function addOwner(User $owner): self
{
if (!$this->owners->contains($owner)) {
$this->owners[] = $owner;
}
return $this;
}
public function removeOwner(User $owner): self
{
$this->owners->removeElement($owner);
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setOrganization($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getOrganization() === $this) {
$user->setOrganization(null);
}
}
return $this;
}
public function getLogoImageName(): ?string
{
return $this->logoImageName;
}
public function setLogoImageName(?string $logoImageName): self
{
$this->logoImageName = $logoImageName;
return $this;
}
public function getCoverImageName(): ?string
{
return $this->coverImageName;
}
public function setCoverImageName(?string $coverImageName): self
{
$this->coverImageName = $coverImageName;
return $this;
}
/**
* @return Collection|CompanyProduct[]
*/
public function getCompanyProducts(): Collection
{
return $this->companyProducts;
}
public function addCompanyProduct(CompanyProduct $companyProduct): self
{
if (!$this->companyProducts->contains($companyProduct)) {
$this->companyProducts[] = $companyProduct;
$companyProduct->setCompany($this);
}
return $this;
}
public function removeCompanyProduct(CompanyProduct $companyProduct): self
{
if ($this->companyProducts->removeElement($companyProduct)) {
// set the owning side to null (unless already changed)
if ($companyProduct->getCompany() === $this) {
$companyProduct->setCompany(null);
}
}
return $this;
}
public function getTagline(): ?string
{
return $this->tagline;
}
public function setTagline(?string $tagline): self
{
$this->tagline = $tagline;
return $this;
}
public function getContactEmail(): ?string
{
return $this->contactEmail;
}
public function setContactEmail(?string $contactEmail): self
{
$this->contactEmail = $contactEmail;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getStreamUrl(): ?string
{
return $this->streamUrl;
}
public function setStreamUrl(?string $streamUrl): self
{
$this->streamUrl = $streamUrl;
return $this;
}
public function getStreamType(): ?string
{
return $this->streamType;
}
public function setStreamType(?string $streamType): self
{
$this->streamType = $streamType;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getFollowers(): Collection
{
return $this->followers;
}
public function getFollowersId(): array
{
$ids = [];
foreach ($this->followers as $u) {
$ids[] = $u->getId();
}
return $ids;
}
public function addFollower(User $follower): self
{
if (!$this->followers->contains($follower)) {
$this->followers[] = $follower;
$follower->addFollowingCompany($this);
}
return $this;
}
public function removeFollower(User $follower): self
{
if ($this->followers->removeElement($follower)) {
$follower->removeFollowingCompany($this);
}
return $this;
}
/**
* @return Collection<int, User>
*/
public function getOffNotificationUsers(): Collection
{
return $this->offNotificationUsers;
}
public function getOffNotificationUsersId(): array
{
$ids = [];
foreach ($this->offNotificationUsers as $u) {
$ids[] = $u->getId();
}
return $ids;
}
public function addOffNotificationUser(User $offNotificationUser): self
{
if (!$this->offNotificationUsers->contains($offNotificationUser)) {
$this->offNotificationUsers[] = $offNotificationUser;
$offNotificationUser->addOffCompanyNotification($this);
}
return $this;
}
public function removeOffNotificationUser(User $offNotificationUser): self
{
if ($this->offNotificationUsers->removeElement($offNotificationUser)) {
$offNotificationUser->removeOffCompanyNotification($this);
}
return $this;
}
/**
* @return Collection<int, Newsfeed>
*/
public function getNewsfeeds(): Collection
{
return $this->newsfeeds;
}
public function addNewsfeed(Newsfeed $newsfeed): self
{
if (!$this->newsfeeds->contains($newsfeed)) {
$this->newsfeeds[] = $newsfeed;
$newsfeed->setCompany($this);
}
return $this;
}
public function removeNewsfeed(Newsfeed $newsfeed): self
{
if ($this->newsfeeds->removeElement($newsfeed)) {
// set the owning side to null (unless already changed)
if ($newsfeed->getCompany() === $this) {
$newsfeed->setCompany(null);
}
}
return $this;
}
public function getTotalFollowers(): ?int
{
return $this->totalFollowers;
}
public function setTotalFollowers(?int $totalFollowers): self
{
$this->totalFollowers = $totalFollowers;
return $this;
}
public function getMetadata()
{
return [
'company' => [
'id' => $this->getId(),
'name' => $this->getName(),
'tagline' => $this->getTagline(),
'website' => $this->getWebsite(),
'companyCategory' => $this->getCompanyCategory() ? $this->getCompanyCategory()->getMeta() : null,
'logoImageName' => $this->getLogoImageName(),
'coverImageName' => $this->getCoverImageName()
]
];
}
public function getIndustry(): ?string
{
return $this->industry;
}
public function setIndustry(?string $industry): self
{
$this->industry = $industry;
return $this;
}
public function getSize(): ?string
{
return $this->size;
}
public function setSize(?string $size): self
{
$this->size = $size;
return $this;
}
public function getAddress1(): ?string
{
return $this->address1;
}
public function setAddress1(?string $address1): self
{
$this->address1 = $address1;
return $this;
}
public function getAddress2(): ?string
{
return $this->address2;
}
public function setAddress2(?string $address2): self
{
$this->address2 = $address2;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getSocialLinkedin(): ?string
{
return $this->socialLinkedin;
}
public function setSocialLinkedin(?string $socialLinkedin): self
{
$this->socialLinkedin = $socialLinkedin;
return $this;
}
public function getSocialX(): ?string
{
return $this->socialX;
}
public function setSocialX(?string $socialX): self
{
$this->socialX = $socialX;
return $this;
}
public function getSocialFacebook(): ?string
{
return $this->socialFacebook;
}
public function setSocialFacebook(?string $socialFacebook): self
{
$this->socialFacebook = $socialFacebook;
return $this;
}
public function getSocialInstagram(): ?string
{
return $this->socialInstagram;
}
public function setSocialInstagram(?string $socialInstagram): self
{
$this->socialInstagram = $socialInstagram;
return $this;
}
public function getSocialYoutube(): ?string
{
return $this->socialYoutube;
}
public function setSocialYoutube(?string $socialYoutube): self
{
$this->socialYoutube = $socialYoutube;
return $this;
}
/**
* @return Collection<int, Container>
*/
public function getOwnerContainers(): Collection
{
return $this->ownerContainers;
}
public function addOwnerContainer(Container $ownerContainer): self
{
if (!$this->ownerContainers->contains($ownerContainer)) {
$this->ownerContainers[] = $ownerContainer;
}
return $this;
}
public function removeOwnerContainer(Container $ownerContainer): self
{
$this->ownerContainers->removeElement($ownerContainer);
return $this;
}
}