<?php
namespace App\Entity\Profile;
use App\Entity\EntityInterface;
use App\Entity\Logs\ProfileHierarchyHistoryLog;
use App\Entity\Profile\Splits\DeliverySplits;
use App\Entity\Profile\Helper\Helper;
use App\Entity\Profile\PaymentMethod\PaymentGateway;
use App\Entity\Profile\Splits\RoyaltySplits;
use App\Entity\Profile\Splits\RoyaltySplitsTemplate;
use App\Entity\Song\Song;
use App\Entity\Composition\SongWriter;
use App\Entity\User\User;
use App\Entity\Package\PackageSongWriter;
use App\Enums\Constants;
use App\Enums\Platforms;
use App\Repository\Profile\ProfileRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use FOS\ElasticaBundle\Configuration\ConfigManager;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Profile\ProfileNote;
/**
* @ORM\Entity(repositoryClass=ProfileRepository::class)
*/
class Profile implements EntityInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"profile:index", "profile:edit", "invitation:index", "user:index", "package:index", "package:show", "package-songwriter:show", "package-transaction:show", "order:index", "order:show", "contract:index", "event:log", "composition:show", "signature:show", "elastica:profile", "r-splits-templates:get", "royalty-importer-file:index", "composition:unsubmission-log", "message:show", "royalty-due:create"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Groups({"profile:index", "invitation:index", "event:log", "public_info", "user:index", "package:index", "package:show", "package-songwriter:show", "package-transaction:show", "order:index", "order:show", "contract:index", "signature:show", "elastica:profile", "r-splits-templates:get", "royalty-importer-file:index", "composition:unsubmission-log"})
*/
private $urlName;
/**
* @var ProfileType
*
* @ORM\ManyToOne(targetEntity="ProfileType")
* @ORM\JoinColumn(name="profile_type_id", referencedColumnName="id")
* @Groups({"profile:index", "profile:new", "user:index", "event:log", "public_info", "elastica:profile"})
*/
private $profileType;
/**
* @var Profile
*
* @ORM\ManyToOne(targetEntity=Profile::class, inversedBy="subProfiles")
* @ORM\JoinColumn(nullable=true)
*/
private $parent;
/**
* @var Profile
*/
private $publisherAdministrator;
/**
* @var integer
*
* @ORM\Column(type="integer", nullable=true)
*/
private $relatedMmdzProfileId;
/**
* @ORM\OneToMany(targetEntity=Profile::class, mappedBy="parent")
*/
private $subProfiles;
/**
* @ORM\Column(type="boolean")
* @Groups({"profile:index", "event:log"})
*/
private $enabled;
/**
* @var string
*
* @ORM\Column(type="string", nullable=false, options={"default":"Active"})
* @Groups({"profile:index", "invitation:index", "profile:edit", "package:index", "package:show", "package-songwriter:show", "package-transaction:show", "order:index", "order:show", "event:log", "composition:show", "elastica:profile"})
*/
private $status;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
* @Groups({"composition:show", "profile:index", "profile:new", "profile:edit", "event:log", "public_info", "elastica:profile"})
*/
private $caeNumber;
/**
* @var bool
*
* @ORM\Column(name="has_cae_number", type="boolean", nullable=false, options={"default":0})
* @Groups({"composition:show", "profile:index", "profile:new", "profile:edit", "event:log", "public_info", "elastica:profile"})
*/
private $hasCaeNumber;
/**
* This field will be autogenerated based on a profile name.
* It is only generated if the profile type is Publisher or Publisher Administrator.
* It is used in CWR workflow (i.e. for a Submitter Work Number in a NWR/REV records).
*
* @var string
*
* @ORM\Column(name="works_prefix", type="string", length=6, nullable=true, unique=true)
*/
private $worksPrefix;
/**
* @var string
*
* @ORM\Column(name="interested_party_number", type="string", length=9, nullable=true, unique=true)
*/
private $interestedPartyNumber;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default": true})
* @Groups({"profile:index", "profile:new", "profile:edit", "event:log", "public_info"})
*/
private $signupPrivate = true;
/**
* @var ProfileInformation
*
* @ORM\OneToOne(targetEntity="App\Entity\Profile\ProfileInformation", mappedBy="profile", cascade={"persist"})
* @Groups({"elastica:song", "profile:index", "invitation:index", "public_info", "profile:new", "profile:edit", "user:index", "composition:show", "contract:index", "event:log", "signature:show", "splits:preview", "composition:unsubmission-log", "message:show"})
* @Assert\Valid()
*/
private $profileInformation;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
* @Groups({"profile:index", "event:log"})
*/
private $createdAt;
/**
* @var string
*
* @ORM\Column(name="confirmation_token", type="text", nullable=true)
*/
private $confirmationToken;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=ProfileRBAC::class, mappedBy="profile")
* @Groups({"profile:show", "event:log"})
*/
private $profileRbac;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=PackageSongWriter::class, mappedBy="profile")
* @Groups({"profile:show", "event:log"})
*/
private $packageSongWriters;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=Helper::class, mappedBy="profile")
* @ORM\OrderBy({"orderNumber"="ASC"})
* @Groups({"profile:show", "event:log"})
*/
private $helpers;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=PaymentGateway::class, mappedBy="profile")
* @Groups({"profile:show", "event:log"})
*/
private $paymentGateways;
/**
* @var ProfileSocialMedia
*
* @ORM\OneToOne(targetEntity="App\Entity\Profile\ProfileSocialMedia", mappedBy="profile", cascade={"persist"})
* @Groups({"profile:show", "event:log"})
*/
private $profileSocialMedia;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\Profile\ProfileCommunicationSettings", mappedBy="profile", cascade={"persist"})
* @Groups({"profile:show", "event:log"})
*/
private $profileCommunicationSettings;
/**
* @ORM\OneToMany(targetEntity=ProfileHierarchyHistoryLog::class, mappedBy="profile")
*/
private $profileHierarchyHistoryLogs;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\Composition\SongWriter", mappedBy="profile")
*/
private $songWriters;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\Profile\PlatformIpiNumber", mappedBy="profile")
* @Groups({"profile:show"})
*/
private $platformIpiNumbers;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\Profile\Splits\RoyaltyImporterFile", mappedBy="profile")
* @Groups({"profile:show"})
*/
private $royaltyImporterFiles;
/**
* @ORM\OneToOne(targetEntity=DeliverySplits::class, mappedBy="profile", cascade={"remove"})
* @Groups({"splits:get"})
*/
private $deliverySplits;
/**
* @var RoyaltySplits
*
* @ORM\OneToOne(targetEntity=RoyaltySplits::class, mappedBy="profile", cascade={"remove"})
* @Groups({"r-splits:get"})
*/
private $royaltySplits;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=RoyaltySplitsTemplate::class, mappedBy="profile")
*/
private $royaltySplitsTemplates;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=ProfileNote::class, mappedBy="profile")
*/
private $profileNotes;
public function __construct()
{
$this->enabled = false;
$this->hasCaeNumber = false;
$this->createdAt = new \DateTime();
$this->subProfiles = new ArrayCollection();
$this->profileHierarchyHistoryLogs = new ArrayCollection();
$this->songWriters = new ArrayCollection();
$this->platformIpiNumbers = new ArrayCollection();
$this->royaltySplitsTemplates = new ArrayCollection();
$this->royaltyImporterFiles = new ArrayCollection();
$this->profileNotes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUrlName(): ?string
{
return $this->urlName;
}
public function setUrlName(string $urlName): self
{
$this->urlName = $urlName;
return $this;
}
/**
* @return ProfileType
*/
public function getProfileType(): ProfileType
{
return $this->profileType;
}
/**
* @param ProfileType $profileType
* @return Profile
*/
public function setProfileType(ProfileType $profileType): Profile
{
$this->profileType = $profileType;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Profile
*/
public function getPublisherAdministrator(): ?Profile
{
return $this->publisherAdministrator;
}
/**
* @param ?Profile $publisherAdministrator
* @return Profile
*/
public function setPublisherAdministrator(?Profile $publisherAdministrator): Profile
{
$this->publisherAdministrator = $publisherAdministrator;
return $this;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
* @return Profile
*/
public function setEnabled($enabled): Profile
{
$this->enabled = $enabled;
return $this;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @param string $status
* @return Profile
*/
public function setStatus(string $status): Profile
{
$this->status = $status;
return $this;
}
/**
* @return bool
*/
public function isSignupPrivate(): bool
{
return $this->signupPrivate;
}
/**
* @param bool $signupPrivate
* @return Profile
*/
public function setSignupPrivate(bool $signupPrivate): Profile
{
$this->signupPrivate = $signupPrivate;
return $this;
}
/**
* @return ProfileInformation
*/
public function getProfileInformation(): ?ProfileInformation
{
return $this->profileInformation;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return Collection
*/
public function getSubProfiles(): Collection
{
return $this->subProfiles;
}
/**
* Get number of subProfiles where this profile is direct parent
*
* @SerializedName("sub_profiles_count")
* @Groups({"profile:index"})
*
* @return int
*/
public function getSubProfilesCount(): int
{
return $this->subProfiles->count();
}
/**
* Check if profile has any notes
*
* @SerializedName("has_notes")
* @Groups({"profile:index", "profile:show"})
*
* @return bool
*/
public function getHasNotes(): bool
{
return !$this->profileNotes->isEmpty();
}
/**
* @return Collection|ProfileNote[]
*/
public function getProfileNotes(): Collection
{
return $this->profileNotes;
}
/**
* @SerializedName("parent")
* @Groups({"profile:show", "profile:index"})
*/
public function getParentProfileData()
{
if (! $this->parent) {
return null;
}
return [
'id' => $this->parent->getId(),
'cae_number' => $this->parent->getCaeNumber(),
'url_name' => $this->parent->getUrlName(),
'profile_information' => [
'name' => $this->parent->getProfileInformation()->getName()
]
];
}
//publisherAdministrator
/**
* @SerializedName("publisherAdministrator")
* @Groups({"profile:show", "profile:index"})
*/
public function getPublisherAdministratorData()
{
if (! $this->parent) {
return null;
}
$parent = ($this->parent->getProfileType()->getName() === Constants::PROFILE_TYPE_PUBLISHER_ADMINISTRATOR
|| $this->parent->getProfileType()->getName() === Constants::PROFILE_TYPE_SERVICE) ? $this->parent : $this->parent->getParent();
return [
'id' => $parent->getId(),
'cae_number' => $parent->getCaeNumber(),
'url_name' => $parent->getUrlName(),
'profile_information' => [
'name' => $parent->getProfileInformation()->getName()
]
];
}
/**
* @return Collection
*/
public function getProfileRBAC(): Collection
{
return $this->profileRbac;
}
/**
* @return Collection
*/
public function getPackageSongWriters(): Collection
{
return $this->packageSongWriters;
}
/**
* @return Collection
*/
public function getHelpers(): Collection
{
return $this->helpers;
}
/**
* @return Collection
*/
public function getPaymentGateways(): Collection
{
return $this->paymentGateways;
}
/**
* @return ProfileSocialMedia
*/
public function getProfileSocialMedia(): ?ProfileSocialMedia
{
return $this->profileSocialMedia;
}
/**
* @return Collection
*/
public function getProfileCommunicationSettings(): ?Collection
{
return $this->profileCommunicationSettings;
}
/**
* @return int
*/
public function getRelatedMmdzProfileId(): ?int
{
return $this->relatedMmdzProfileId;
}
/**
* @param int $relatedMmdzProfileId
* @return Profile
*/
public function setRelatedMmdzProfileId(?int $relatedMmdzProfileId): Profile
{
$this->relatedMmdzProfileId = $relatedMmdzProfileId;
return $this;
}
/**
* @return Collection|ProfileHierarchyHistoryLog[]
*/
public function getProfileHierarchyHistoryLogs(): Collection
{
return $this->profileHierarchyHistoryLogs;
}
/**
* @return array
*/
public function getSongs(): array
{
$songs = [];
/** @var SongWriter $songWriter */
foreach ($this->songWriters as $songWriter) {
/** @var Song $song */
foreach ($songWriter->getComposition()->getSongs() as $song) {
$songs[] = $song;
}
}
return $songs;
}
/**
* @return string
*/
public function getConfirmationToken(): ?string
{
return $this->confirmationToken;
}
/**
* @param string $confirmationToken
* @return Profile
*/
public function setConfirmationToken(?string $confirmationToken): Profile
{
$this->confirmationToken = $confirmationToken;
return $this;
}
/**
* @return string
*/
public function getCaeNumber(): ?string
{
return $this->caeNumber;
}
/**
* @param string $caeNumber
* @return Profile
*/
public function setCaeNumber(?string $caeNumber): Profile
{
$this->caeNumber = $caeNumber;
return $this;
}
/**
* @return bool
*/
public function getHasCaeNumber(): bool
{
return $this->hasCaeNumber;
}
/**
* @param bool $hasCaeNumber
* @return Profile
*/
public function setHasCaeNumber(bool $hasCaeNumber)
{
$this->hasCaeNumber = $hasCaeNumber;
return $this;
}
/**
* @return Collection
*/
public function getPlatformIpiNumbers(): Collection
{
return $this->platformIpiNumbers;
}
/**
* Get IPI number for PRS
*
* @return string|null
*/
public function getPrsIpiNumber(): ?string
{
/** @var PlatformIpiNumber $platformIpiNumber */
foreach ($this->platformIpiNumbers as $platformIpiNumber) {
if ($platformIpiNumber->getPlatform()->getName() === Platforms::PRS) {
return $platformIpiNumber->getIpiNumber();
}
}
return null;
}
/**
* @param string $worksPrefix
* @return Profile
*/
public function setWorksPrefix(string $worksPrefix): Profile
{
$this->worksPrefix = $worksPrefix;
return $this;
}
/**
* @return string
*/
public function getWorksPrefix(): ?string
{
return $this->worksPrefix;
}
/**
* @return string
*/
public function getInterestedPartyNumber(): ?string
{
return $this->interestedPartyNumber;
}
/**
* @param string $interestedPartyNumber
* @return Profile
*/
public function setInterestedPartyNumber(?string $interestedPartyNumber): Profile
{
$this->interestedPartyNumber = $interestedPartyNumber;
return $this;
}
public function getDeliverySplits(): ?DeliverySplits
{
return $this->deliverySplits;
}
/**
* @return ?RoyaltySplits
*/
public function getRoyaltySplits(): ?RoyaltySplits
{
return $this->royaltySplits;
}
/**
* @return ArrayCollection|Collection
*/
public function getRoyaltySplitsTemplates()
{
return $this->royaltySplitsTemplates;
}
/**
* @param ArrayCollection|Collection $royaltySplitsTemplates
* @return Profile
*/
public function setRoyaltySplitsTemplates($royaltySplitsTemplates)
{
$this->royaltySplitsTemplates = $royaltySplitsTemplates;
}
/**
* @return ArrayCollection|Collection
*/
public function getRoyaltyImporterFiles()
{
return $this->royaltyImporterFiles;
}
/**
* @param ArrayCollection|Collection $royaltyImporterFiles
* @return Profile
*/
public function setRoyaltyImporterFiles($royaltyImporterFiles)
{
$this->royaltyImporterFiles = $royaltyImporterFiles;
return $this;
}
/**
* @SerializedName("owner")
* @Groups({"profile:index"})
*
* @return User|null
*/
public function getOwner(): ?User
{
/** @var ProfileRBAC $profileRBAC */
foreach ($this->profileRbac as $profileRBAC) {
if ($profileRBAC->getRole()->getName() === Constants::PROFILE_ROLE_NAME_OWNER) {
return $profileRBAC->getUser();
}
if ($profileRBAC->getRole()->getName() === Constants::PROFILE_ROLE_NAME_ADMIN) {
return $profileRBAC->getUser();
}
}
return null;
}
}