src/Entity/Profile/Profile.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Profile;
  3. use App\Entity\EntityInterface;
  4. use App\Entity\Logs\ProfileHierarchyHistoryLog;
  5. use App\Entity\Profile\Splits\DeliverySplits;
  6. use App\Entity\Profile\Helper\Helper;
  7. use App\Entity\Profile\PaymentMethod\PaymentGateway;
  8. use App\Entity\Profile\Splits\RoyaltySplits;
  9. use App\Entity\Profile\Splits\RoyaltySplitsTemplate;
  10. use App\Entity\Song\Song;
  11. use App\Entity\Composition\SongWriter;
  12. use App\Entity\User\User;
  13. use App\Entity\Package\PackageSongWriter;
  14. use App\Enums\Constants;
  15. use App\Enums\Platforms;
  16. use App\Repository\Profile\ProfileRepository;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\ORM\Mapping as ORM;
  20. use FOS\ElasticaBundle\Configuration\ConfigManager;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. use Symfony\Component\Serializer\Annotation\SerializedName;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. use App\Entity\Profile\ProfileNote;
  25. /**
  26.  * @ORM\Entity(repositoryClass=ProfileRepository::class)
  27.  */
  28. class Profile implements EntityInterface
  29. {
  30.     /**
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue
  33.      * @ORM\Column(type="integer")
  34.      * @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"})
  35.      */
  36.     private $id;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, unique=true)
  39.      * @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"})
  40.      */
  41.     private $urlName;
  42.     /**
  43.      * @var ProfileType
  44.      *
  45.      * @ORM\ManyToOne(targetEntity="ProfileType")
  46.      * @ORM\JoinColumn(name="profile_type_id", referencedColumnName="id")
  47.      * @Groups({"profile:index", "profile:new", "user:index", "event:log", "public_info", "elastica:profile"})
  48.      */
  49.     private $profileType;
  50.     /**
  51.      * @var Profile
  52.      *
  53.      * @ORM\ManyToOne(targetEntity=Profile::class, inversedBy="subProfiles")
  54.      * @ORM\JoinColumn(nullable=true)
  55.      */
  56.     private $parent;
  57.     /**
  58.      * @var  Profile
  59.      */
  60.     private $publisherAdministrator;
  61.     /**
  62.      * @var integer
  63.      *
  64.      * @ORM\Column(type="integer", nullable=true)
  65.      */
  66.     private $relatedMmdzProfileId;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity=Profile::class, mappedBy="parent")
  69.      */
  70.     private $subProfiles;
  71.     /**
  72.      * @ORM\Column(type="boolean")
  73.      * @Groups({"profile:index", "event:log"})
  74.      */
  75.     private $enabled;
  76.     /**
  77.      * @var string
  78.      *
  79.      * @ORM\Column(type="string", nullable=false, options={"default":"Active"})
  80.      * @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"})
  81.      */
  82.     private $status;
  83.     /**
  84.      * @var string
  85.      *
  86.      * @ORM\Column(type="string", nullable=true)
  87.      * @Groups({"composition:show", "profile:index", "profile:new", "profile:edit", "event:log", "public_info", "elastica:profile"})
  88.      */
  89.     private $caeNumber;
  90.     /**
  91.      * @var bool
  92.      *
  93.      * @ORM\Column(name="has_cae_number", type="boolean", nullable=false, options={"default":0})
  94.      * @Groups({"composition:show", "profile:index", "profile:new", "profile:edit", "event:log", "public_info", "elastica:profile"})
  95.      */
  96.     private $hasCaeNumber;
  97.     /**
  98.      * This field will be autogenerated based on a profile name.
  99.      * It is only generated if the profile type is Publisher or Publisher Administrator.
  100.      * It is used in CWR workflow (i.e. for a Submitter Work Number in a NWR/REV records).
  101.      *
  102.      * @var string
  103.      *
  104.      * @ORM\Column(name="works_prefix", type="string", length=6, nullable=true, unique=true)
  105.      */
  106.     private $worksPrefix;
  107.     /**
  108.      * @var string
  109.      *
  110.      * @ORM\Column(name="interested_party_number", type="string", length=9, nullable=true, unique=true)
  111.      */
  112.     private $interestedPartyNumber;
  113.     /**
  114.      * @var bool
  115.      *
  116.      * @ORM\Column(type="boolean", options={"default": true})
  117.      * @Groups({"profile:index", "profile:new", "profile:edit", "event:log", "public_info"})
  118.      */
  119.     private $signupPrivate true;
  120.     /**
  121.      * @var ProfileInformation
  122.      *
  123.      * @ORM\OneToOne(targetEntity="App\Entity\Profile\ProfileInformation", mappedBy="profile", cascade={"persist"})
  124.      * @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"})
  125.      * @Assert\Valid()
  126.      */
  127.     private $profileInformation;
  128.     /**
  129.      * @var \DateTime
  130.      *
  131.      * @ORM\Column(name="created_at", type="datetime", nullable=false)
  132.      * @Groups({"profile:index", "event:log"})
  133.      */
  134.     private $createdAt;
  135.     /**
  136.      * @var string
  137.      *
  138.      * @ORM\Column(name="confirmation_token", type="text", nullable=true)
  139.      */
  140.     private $confirmationToken;
  141.     /**
  142.      * @var Collection
  143.      *
  144.      * @ORM\OneToMany(targetEntity=ProfileRBAC::class, mappedBy="profile")
  145.      * @Groups({"profile:show", "event:log"})
  146.      */
  147.     private $profileRbac;
  148.     /**
  149.      * @var Collection
  150.      *
  151.      * @ORM\OneToMany(targetEntity=PackageSongWriter::class, mappedBy="profile")
  152.      * @Groups({"profile:show", "event:log"})
  153.      */
  154.     private $packageSongWriters;
  155.     /**
  156.      * @var Collection
  157.      *
  158.      * @ORM\OneToMany(targetEntity=Helper::class, mappedBy="profile")
  159.      * @ORM\OrderBy({"orderNumber"="ASC"})
  160.      * @Groups({"profile:show", "event:log"})
  161.      */
  162.     private $helpers;
  163.     /**
  164.      * @var Collection
  165.      *
  166.      * @ORM\OneToMany(targetEntity=PaymentGateway::class, mappedBy="profile")
  167.      * @Groups({"profile:show", "event:log"})
  168.      */
  169.     private $paymentGateways;
  170.     /**
  171.      * @var ProfileSocialMedia
  172.      *
  173.      * @ORM\OneToOne(targetEntity="App\Entity\Profile\ProfileSocialMedia", mappedBy="profile", cascade={"persist"})
  174.      * @Groups({"profile:show", "event:log"})
  175.      */
  176.     private $profileSocialMedia;
  177.     /**
  178.      * @var Collection
  179.      *
  180.      * @ORM\OneToMany(targetEntity="App\Entity\Profile\ProfileCommunicationSettings", mappedBy="profile", cascade={"persist"})
  181.      * @Groups({"profile:show", "event:log"})
  182.      */
  183.     private $profileCommunicationSettings;
  184.     /**
  185.      * @ORM\OneToMany(targetEntity=ProfileHierarchyHistoryLog::class, mappedBy="profile")
  186.      */
  187.     private $profileHierarchyHistoryLogs;
  188.     /**
  189.      * @var Collection
  190.      *
  191.      * @ORM\OneToMany(targetEntity="App\Entity\Composition\SongWriter", mappedBy="profile")
  192.      */
  193.     private $songWriters;
  194.     /**
  195.      * @var Collection
  196.      *
  197.      * @ORM\OneToMany(targetEntity="App\Entity\Profile\PlatformIpiNumber", mappedBy="profile")
  198.      * @Groups({"profile:show"})
  199.      */
  200.     private $platformIpiNumbers;
  201.     /**
  202.      * @var Collection
  203.      *
  204.      * @ORM\OneToMany(targetEntity="App\Entity\Profile\Splits\RoyaltyImporterFile", mappedBy="profile")
  205.      * @Groups({"profile:show"})
  206.      */
  207.     private $royaltyImporterFiles;
  208.     /**
  209.      * @ORM\OneToOne(targetEntity=DeliverySplits::class, mappedBy="profile", cascade={"remove"})
  210.      * @Groups({"splits:get"})
  211.      */
  212.     private $deliverySplits;
  213.     /**
  214.      * @var RoyaltySplits
  215.      *
  216.      * @ORM\OneToOne(targetEntity=RoyaltySplits::class, mappedBy="profile", cascade={"remove"})
  217.      * @Groups({"r-splits:get"})
  218.      */
  219.     private $royaltySplits;
  220.     /**
  221.      * @var Collection
  222.      *
  223.      * @ORM\OneToMany(targetEntity=RoyaltySplitsTemplate::class, mappedBy="profile")
  224.      */
  225.     private $royaltySplitsTemplates;
  226.     /**
  227.      * @var Collection
  228.      *
  229.      * @ORM\OneToMany(targetEntity=ProfileNote::class, mappedBy="profile")
  230.      */
  231.     private $profileNotes;
  232.     public function __construct()
  233.     {
  234.         $this->enabled false;
  235.         $this->hasCaeNumber false;
  236.         $this->createdAt = new \DateTime();
  237.         $this->subProfiles = new ArrayCollection();
  238.         $this->profileHierarchyHistoryLogs = new ArrayCollection();
  239.         $this->songWriters = new ArrayCollection();
  240.         $this->platformIpiNumbers = new ArrayCollection();
  241.         $this->royaltySplitsTemplates = new ArrayCollection();
  242.         $this->royaltyImporterFiles = new ArrayCollection();
  243.         $this->profileNotes = new ArrayCollection();
  244.     }
  245.     public function getId(): ?int
  246.     {
  247.         return $this->id;
  248.     }
  249.     public function getUrlName(): ?string
  250.     {
  251.         return $this->urlName;
  252.     }
  253.     public function setUrlName(string $urlName): self
  254.     {
  255.         $this->urlName $urlName;
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return ProfileType
  260.      */
  261.     public function getProfileType(): ProfileType
  262.     {
  263.         return $this->profileType;
  264.     }
  265.     /**
  266.      * @param ProfileType $profileType
  267.      * @return Profile
  268.      */
  269.     public function setProfileType(ProfileType $profileType): Profile
  270.     {
  271.         $this->profileType $profileType;
  272.         return $this;
  273.     }
  274.     public function getParent(): ?self
  275.     {
  276.         return $this->parent;
  277.     }
  278.     public function setParent(?self $parent): self
  279.     {
  280.         $this->parent $parent;
  281.         return $this;
  282.     }
  283.     /**
  284.      * @return Profile
  285.      */
  286.     public function getPublisherAdministrator(): ?Profile
  287.     {
  288.         return $this->publisherAdministrator;
  289.     }
  290.     /**
  291.      * @param ?Profile $publisherAdministrator
  292.      * @return Profile
  293.      */
  294.     public function setPublisherAdministrator(?Profile $publisherAdministrator): Profile
  295.     {
  296.         $this->publisherAdministrator $publisherAdministrator;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return mixed
  301.      */
  302.     public function getEnabled()
  303.     {
  304.         return $this->enabled;
  305.     }
  306.     /**
  307.      * @param mixed $enabled
  308.      * @return Profile
  309.      */
  310.     public function setEnabled($enabled): Profile
  311.     {
  312.         $this->enabled $enabled;
  313.         return $this;
  314.     }
  315.     /**
  316.      * @return string
  317.      */
  318.     public function getStatus(): string
  319.     {
  320.         return $this->status;
  321.     }
  322.     /**
  323.      * @param string $status
  324.      * @return Profile
  325.      */
  326.     public function setStatus(string $status): Profile
  327.     {
  328.         $this->status $status;
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return bool
  333.      */
  334.     public function isSignupPrivate(): bool
  335.     {
  336.         return $this->signupPrivate;
  337.     }
  338.     /**
  339.      * @param bool $signupPrivate
  340.      * @return Profile
  341.      */
  342.     public function setSignupPrivate(bool $signupPrivate): Profile
  343.     {
  344.         $this->signupPrivate $signupPrivate;
  345.         return $this;
  346.     }
  347.     /**
  348.      * @return ProfileInformation
  349.      */
  350.     public function getProfileInformation(): ?ProfileInformation
  351.     {
  352.         return $this->profileInformation;
  353.     }
  354.     /**
  355.      * @return \DateTime
  356.      */
  357.     public function getCreatedAt(): \DateTime
  358.     {
  359.         return $this->createdAt;
  360.     }
  361.     /**
  362.      * @return Collection
  363.      */
  364.     public function getSubProfiles(): Collection
  365.     {
  366.         return $this->subProfiles;
  367.     }
  368.     /**
  369.      * Get number of subProfiles where this profile is direct parent
  370.      *
  371.      * @SerializedName("sub_profiles_count")
  372.      * @Groups({"profile:index"})
  373.      *
  374.      * @return int
  375.      */
  376.     public function getSubProfilesCount(): int
  377.     {
  378.         return $this->subProfiles->count();
  379.     }
  380.     /**
  381.      * Check if profile has any notes
  382.      *
  383.      * @SerializedName("has_notes")
  384.      * @Groups({"profile:index", "profile:show"})
  385.      *
  386.      * @return bool
  387.      */
  388.     public function getHasNotes(): bool
  389.     {
  390.         return !$this->profileNotes->isEmpty();
  391.     }
  392.     /**
  393.      * @return Collection|ProfileNote[]
  394.      */
  395.     public function getProfileNotes(): Collection
  396.     {
  397.         return $this->profileNotes;
  398.     }
  399.     /**
  400.      * @SerializedName("parent")
  401.      * @Groups({"profile:show", "profile:index"})
  402.      */
  403.     public function getParentProfileData()
  404.     {
  405.         if (! $this->parent) {
  406.             return null;
  407.         }
  408.         return [
  409.             'id'                    => $this->parent->getId(),
  410.             'cae_number'            => $this->parent->getCaeNumber(),
  411.             'url_name'              => $this->parent->getUrlName(),
  412.             'profile_information'   => [
  413.                 'name' => $this->parent->getProfileInformation()->getName()
  414.             ]
  415.         ];
  416.     }
  417.     //publisherAdministrator
  418.     /**
  419.      * @SerializedName("publisherAdministrator")
  420.      * @Groups({"profile:show", "profile:index"})
  421.      */
  422.     public function getPublisherAdministratorData()
  423.     {
  424.         if (! $this->parent) {
  425.             return null;
  426.         }
  427.         $parent = ($this->parent->getProfileType()->getName() === Constants::PROFILE_TYPE_PUBLISHER_ADMINISTRATOR
  428.             || $this->parent->getProfileType()->getName() === Constants::PROFILE_TYPE_SERVICE) ? $this->parent $this->parent->getParent();
  429.         return [
  430.             'id'                    => $parent->getId(),
  431.             'cae_number'            => $parent->getCaeNumber(),
  432.             'url_name'              => $parent->getUrlName(),
  433.             'profile_information'   => [
  434.                 'name' => $parent->getProfileInformation()->getName()
  435.             ]
  436.         ];
  437.     }
  438.     /**
  439.      * @return Collection
  440.      */
  441.     public function getProfileRBAC(): Collection
  442.     {
  443.         return $this->profileRbac;
  444.     }
  445.     /**
  446.      * @return Collection
  447.      */
  448.     public function getPackageSongWriters(): Collection
  449.     {
  450.         return $this->packageSongWriters;
  451.     }
  452.     /**
  453.      * @return Collection
  454.      */
  455.     public function getHelpers(): Collection
  456.     {
  457.         return $this->helpers;
  458.     }
  459.     /**
  460.      * @return Collection
  461.      */
  462.     public function getPaymentGateways(): Collection
  463.     {
  464.         return $this->paymentGateways;
  465.     }
  466.     /**
  467.      * @return ProfileSocialMedia
  468.      */
  469.     public function getProfileSocialMedia(): ?ProfileSocialMedia
  470.     {
  471.         return $this->profileSocialMedia;
  472.     }
  473.     /**
  474.      * @return Collection
  475.      */
  476.     public function getProfileCommunicationSettings(): ?Collection
  477.     {
  478.         return $this->profileCommunicationSettings;
  479.     }
  480.     /**
  481.      * @return int
  482.      */
  483.     public function getRelatedMmdzProfileId(): ?int
  484.     {
  485.         return $this->relatedMmdzProfileId;
  486.     }
  487.     /**
  488.      * @param int $relatedMmdzProfileId
  489.      * @return Profile
  490.      */
  491.     public function setRelatedMmdzProfileId(?int $relatedMmdzProfileId): Profile
  492.     {
  493.         $this->relatedMmdzProfileId $relatedMmdzProfileId;
  494.         return $this;
  495.     }
  496.     /**
  497.      * @return Collection|ProfileHierarchyHistoryLog[]
  498.      */
  499.     public function getProfileHierarchyHistoryLogs(): Collection
  500.     {
  501.         return $this->profileHierarchyHistoryLogs;
  502.     }
  503.     /**
  504.      * @return array
  505.      */
  506.     public function getSongs(): array
  507.     {
  508.         $songs = [];
  509.         /** @var SongWriter $songWriter */
  510.         foreach ($this->songWriters as $songWriter) {
  511.             /** @var Song $song */
  512.             foreach ($songWriter->getComposition()->getSongs() as $song) {
  513.                 $songs[] = $song;
  514.             }
  515.         }
  516.         return $songs;
  517.     }
  518.     /**
  519.      * @return string
  520.      */
  521.     public function getConfirmationToken(): ?string
  522.     {
  523.         return $this->confirmationToken;
  524.     }
  525.     /**
  526.      * @param string $confirmationToken
  527.      * @return Profile
  528.      */
  529.     public function setConfirmationToken(?string $confirmationToken): Profile
  530.     {
  531.         $this->confirmationToken $confirmationToken;
  532.         return $this;
  533.     }
  534.     /**
  535.      * @return string
  536.      */
  537.     public function getCaeNumber(): ?string
  538.     {
  539.         return $this->caeNumber;
  540.     }
  541.     /**
  542.      * @param string $caeNumber
  543.      * @return Profile
  544.      */
  545.     public function setCaeNumber(?string $caeNumber): Profile
  546.     {
  547.         $this->caeNumber $caeNumber;
  548.         return $this;
  549.     }
  550.     /**
  551.      * @return bool
  552.      */
  553.     public function getHasCaeNumber(): bool
  554.     {
  555.         return $this->hasCaeNumber;
  556.     }
  557.     /**
  558.      * @param bool $hasCaeNumber
  559.      * @return Profile
  560.      */
  561.     public function setHasCaeNumber(bool $hasCaeNumber)
  562.     {
  563.         $this->hasCaeNumber $hasCaeNumber;
  564.         return $this;
  565.     }
  566.     /**
  567.      * @return Collection
  568.      */
  569.     public function getPlatformIpiNumbers(): Collection
  570.     {
  571.         return $this->platformIpiNumbers;
  572.     }
  573.     /**
  574.      * Get IPI number for PRS
  575.      *
  576.      * @return string|null
  577.      */
  578.     public function getPrsIpiNumber(): ?string
  579.     {
  580.         /** @var PlatformIpiNumber $platformIpiNumber */
  581.         foreach ($this->platformIpiNumbers as $platformIpiNumber) {
  582.             if ($platformIpiNumber->getPlatform()->getName() === Platforms::PRS) {
  583.                 return $platformIpiNumber->getIpiNumber();
  584.             }
  585.         }
  586.         return null;
  587.     }
  588.     /**
  589.      * @param string $worksPrefix
  590.      * @return Profile
  591.      */
  592.     public function setWorksPrefix(string $worksPrefix): Profile
  593.     {
  594.         $this->worksPrefix $worksPrefix;
  595.         return $this;
  596.     }
  597.     /**
  598.      * @return string
  599.      */
  600.     public function getWorksPrefix(): ?string
  601.     {
  602.         return $this->worksPrefix;
  603.     }
  604.     /**
  605.      * @return string
  606.      */
  607.     public function getInterestedPartyNumber(): ?string
  608.     {
  609.         return $this->interestedPartyNumber;
  610.     }
  611.     /**
  612.      * @param string $interestedPartyNumber
  613.      * @return Profile
  614.      */
  615.     public function setInterestedPartyNumber(?string $interestedPartyNumber): Profile
  616.     {
  617.         $this->interestedPartyNumber $interestedPartyNumber;
  618.         return $this;
  619.     }
  620.     public function getDeliverySplits(): ?DeliverySplits
  621.     {
  622.         return $this->deliverySplits;
  623.     }
  624.     /**
  625.      * @return ?RoyaltySplits
  626.      */
  627.     public function getRoyaltySplits(): ?RoyaltySplits
  628.     {
  629.         return $this->royaltySplits;
  630.     }
  631.     /**
  632.      * @return ArrayCollection|Collection
  633.      */
  634.     public function getRoyaltySplitsTemplates()
  635.     {
  636.         return $this->royaltySplitsTemplates;
  637.     }
  638.     /**
  639.      * @param ArrayCollection|Collection $royaltySplitsTemplates
  640.      * @return Profile
  641.      */
  642.     public function setRoyaltySplitsTemplates($royaltySplitsTemplates)
  643.     {
  644.         $this->royaltySplitsTemplates $royaltySplitsTemplates;
  645.     }
  646.     /**
  647.      * @return ArrayCollection|Collection
  648.      */
  649.     public function getRoyaltyImporterFiles()
  650.     {
  651.         return $this->royaltyImporterFiles;
  652.     }
  653.     /**
  654.      * @param ArrayCollection|Collection $royaltyImporterFiles
  655.      * @return Profile
  656.      */
  657.     public function setRoyaltyImporterFiles($royaltyImporterFiles)
  658.     {
  659.         $this->royaltyImporterFiles $royaltyImporterFiles;
  660.         return $this;
  661.     }
  662.     /**
  663.      * @SerializedName("owner")
  664.      * @Groups({"profile:index"})
  665.      *
  666.      * @return User|null
  667.      */
  668.     public function getOwner(): ?User
  669.     {
  670.         /** @var ProfileRBAC $profileRBAC */
  671.         foreach ($this->profileRbac as $profileRBAC) {
  672.             if ($profileRBAC->getRole()->getName() === Constants::PROFILE_ROLE_NAME_OWNER) {
  673.                 return $profileRBAC->getUser();
  674.             }
  675.             if ($profileRBAC->getRole()->getName() === Constants::PROFILE_ROLE_NAME_ADMIN) {
  676.                 return $profileRBAC->getUser();
  677.             }
  678.         }
  679.         return null;
  680.     }
  681. }