src/Entity/Band.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Constant\BandMemberRoleConstant;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use App\Constant\ActionStatusConstant;
  8. use App\Constant\InvitationStatusConstant;
  9. use App\Constant\PeopleActionConstant;
  10. use App\Constant\BandTypeConstant;
  11. use App\Constant\FileStatusConstant;
  12. use App\Constant\FileTypeConstant;
  13. use DateTime;
  14. /**
  15.  * Band
  16.  *
  17.  * @ORM\Table(name="band")
  18.  * @ORM\Entity(repositoryClass="App\Repository\BandRepository")
  19.  */
  20. class Band implements CommonInformationInterface
  21. {
  22.     /**
  23.      * @var int
  24.      *
  25.      * @ORM\Column(name="id", type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     protected int $id;
  30.     /**
  31.      * @var string
  32.      *
  33.      * @ORM\Column(name="name", type="string", length=255, nullable=true)
  34.      */
  35.     protected string $name;
  36.     /**
  37.      * @var string
  38.      *
  39.      * @ORM\Column(name="type", type="string", length=255)
  40.      */
  41.     private string $type BandTypeConstant::USER_COLLABORATION;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity="User", inversedBy="createdBands")
  44.      * @ORM\JoinColumn(nullable=false)
  45.      */
  46.     private User $creator;
  47.     /**
  48.      * @var string
  49.      *
  50.      * @ORM\Column(name="city", type="string", length=255)
  51.      */
  52.     private string $city '';
  53.     /**
  54.      * @ORM\OneToMany(targetEntity="BandMember", mappedBy="band", cascade={"all"})
  55.      */
  56.     private Collection $members;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity="NewMemberSearch", mappedBy="band", cascade={"all"})
  59.      */
  60.     private Collection $newMemberSearches;
  61.     /**
  62.      * @ORM\OneToMany(targetEntity="PeopleAction", mappedBy="bandPeople", cascade={"remove"})
  63.      */
  64.     private Collection $peopleActions;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity="Folder", mappedBy="owner", cascade={"remove"}))
  67.      */
  68.     private Collection $folders;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity="EventAction", mappedBy="band", cascade={"remove"})
  71.      */
  72.     private Collection $eventActions;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity="Invitation", mappedBy="band", cascade={"all"})
  75.      */
  76.     private Collection $invitations;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity="Thread", mappedBy="band", cascade={"all"})
  79.      */
  80.     private Collection $threads;
  81.     /**
  82.      * @ORM\OneToOne(targetEntity="CommonInformation", cascade={"all"})c
  83.      * @ORM\JoinColumn(nullable=false)
  84.      */
  85.     private ?CommonInformation $commonInformation null;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity="Order", mappedBy="band", cascade={"persist"})
  88.      */
  89.     private Collection $orders;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity="Project", mappedBy="band")
  92.      */
  93.     private Collection $projects;
  94.     /**
  95.      * Constructor
  96.      */
  97.     public function __construct()
  98.     {
  99.         $this->members = new ArrayCollection();
  100.         $this->peopleActions = new ArrayCollection();
  101.         $this->folders = new ArrayCollection();
  102.         $this->eventActions = new ArrayCollection();
  103.         $this->projects = new ArrayCollection();
  104.         $this->newMemberSearches = new ArrayCollection();
  105.         $this->invitations = new ArrayCollection();
  106.         $this->threads = new ArrayCollection();
  107.         $this->orders = new ArrayCollection();
  108.     }
  109.     /**
  110.      * Get id
  111.      *
  112.      * @return integer
  113.      */
  114.     public function getId(): int
  115.     {
  116.         return $this->id;
  117.     }
  118.     /**
  119.      * Set name
  120.      *
  121.      * @param string $name
  122.      *
  123.      * @return Band
  124.      */
  125.     public function setName(string $name): Band
  126.     {
  127.         $this->name $name;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Get name
  132.      *
  133.      * @return string|null
  134.      */
  135.     public function getName(): ?string
  136.     {
  137.         return $this->name;
  138.     }
  139.     /**
  140.      * Set city
  141.      *
  142.      * @param string $city
  143.      *
  144.      * @return Band
  145.      */
  146.     public function setCity(string $city): Band
  147.     {
  148.         $this->city $city;
  149.         return $this;
  150.     }
  151.     /**
  152.      * Get city
  153.      *
  154.      * @return string|null
  155.      */
  156.     public function getCity(): ?string
  157.     {
  158.         return $this->city;
  159.     }
  160.     /**
  161.      * Set creator
  162.      *
  163.      * @param User $creator
  164.      *
  165.      * @return Band
  166.      */
  167.     public function setCreator(User $creator): Band
  168.     {
  169.         $this->creator $creator;
  170.         return $this;
  171.     }
  172.     /**
  173.      * Get creator
  174.      *
  175.      * @return User
  176.      */
  177.     public function getCreator(): User
  178.     {
  179.         return $this->creator;
  180.     }
  181.     /**
  182.      * Add member
  183.      *
  184.      * @param BandMember $member
  185.      *
  186.      * @return Band
  187.      */
  188.     public function addMember(BandMember $member): Band
  189.     {
  190.         $member->setBand($this);
  191.         $this->members[] = $member;
  192.         return $this;
  193.     }
  194.     /**
  195.      * Remove member
  196.      *
  197.      * @param BandMember $member
  198.      */
  199.     public function removeMember(BandMember $member)
  200.     {
  201.         $this->members->removeElement($member);
  202.     }
  203.     /**
  204.      * Get members
  205.      *
  206.      * @return Collection
  207.      */
  208.     public function getMembers($withGuest true)
  209.     {
  210.         return $withGuest $this->members $this->members->filter(function(BandMember $bandMember) {
  211.             return $bandMember->getRole() !== BandMemberRoleConstant::GUEST;
  212.         });
  213.     }
  214.     /**
  215.      * Add folder
  216.      *
  217.      * @param Folder $folder
  218.      *
  219.      * @return Band
  220.      */
  221.     public function addFolder(Folder $folder): Band
  222.     {
  223.         $this->folders[] = $folder;
  224.         return $this;
  225.     }
  226.     /**
  227.      * Remove folder
  228.      *
  229.      * @param Folder $folder
  230.      */
  231.     public function removeFolder(Folder $folder)
  232.     {
  233.         $this->folders->removeElement($folder);
  234.     }
  235.     /**
  236.      * Get folders
  237.      *
  238.      * @return Collection
  239.      */
  240.     public function getFolders()
  241.     {
  242.         return $this->folders;
  243.     }
  244.     public function getAllFiles(): array
  245.     {
  246.         $allFiles = array();
  247.         foreach ($this->folders as $folder) {
  248.             foreach ($folder->getFiles() as $file) {
  249.                 $allFiles[] = $file;
  250.             }
  251.         }
  252.         return $allFiles;
  253.     }
  254.     public function getAllPublicFiles($type): array
  255.     {
  256.         $publicFiles = array();
  257.         foreach ($this->getAllFiles() as $file) {
  258.             if ($file->getStatus() == FileStatusConstant::STATUS_PUBLIC && $file->getType() == $type) {
  259.                 $publicFiles[] = $file;
  260.             }
  261.         }
  262.         return $publicFiles;
  263.     }
  264.     public function getWaitingInvitations(): array
  265.     {
  266.         $acceptInvite = array();
  267.         foreach ($this->getInvitations() as $invitation) {
  268.             if ($invitation->getStatus() == InvitationStatusConstant::WAITING) {
  269.                 $acceptInvite[] = $invitation;
  270.             }
  271.         }
  272.         return $acceptInvite;
  273.     }
  274.     public function getBaseFolders(): array
  275.     {
  276.         $baseFolders = array();
  277.         foreach ($this->folders as $folder) {
  278.             if (!$folder->getParent()) {
  279.                 $baseFolders[] = $folder;
  280.             }
  281.         }
  282.         return $baseFolders;
  283.     }
  284.     public function getBaseFolder($fileType FileTypeConstant::MUSIC)
  285.     {
  286.         $baseFolder null;
  287.         foreach ($this->folders as $folder) {
  288.             if (!$folder->getParent() && $folder->getFilesType() == $fileType && (!$baseFolder || ($folder->getId() < $baseFolder->getId()))) {
  289.                 $baseFolder $folder;
  290.             }
  291.         }
  292.         return $baseFolder;
  293.     }
  294.     /**
  295.      * @return mixed|null
  296.      */
  297.     public function getCurrentOrder()
  298.     {
  299.         $currentOrders $this->orders->filter(
  300.             function ($order) {
  301.                 /** @var Order $order */
  302.                 return $order->getEndDate() > new DateTime();
  303.             }
  304.         );
  305.         if (count($currentOrders)) {
  306.             return $currentOrders->first();
  307.         } else {
  308.             return null;
  309.         }
  310.     }
  311.     /**
  312.      * Set type
  313.      *
  314.      * @param string $type
  315.      *
  316.      * @return Band
  317.      */
  318.     public function setType(string $type): Band
  319.     {
  320.         $this->type $type;
  321.         return $this;
  322.     }
  323.     /**
  324.      * Get type
  325.      *
  326.      * @return string
  327.      */
  328.     public function getType(): string
  329.     {
  330.         return $this->type;
  331.     }
  332.     /**
  333.      * Add PeopleAction
  334.      *
  335.      * @param PeopleAction $PeopleAction
  336.      *
  337.      * @return Band
  338.      */
  339.     public function addPeopleAction(PeopleAction $PeopleAction): Band
  340.     {
  341.         $this->peopleActions[] = $PeopleAction;
  342.         return $this;
  343.     }
  344.     /**
  345.      * Remove PeopleAction
  346.      *
  347.      * @param PeopleAction $PeopleAction
  348.      */
  349.     public function removePeopleAction(PeopleAction $PeopleAction)
  350.     {
  351.         $this->peopleActions->removeElement($PeopleAction);
  352.     }
  353.     /**
  354.      * Get PeopleActions
  355.      *
  356.      * @return Collection
  357.      */
  358.     public function getPeopleActions()
  359.     {
  360.         return $this->peopleActions;
  361.     }
  362.     public function getSubscribers(): Collection
  363.     {
  364.         return $this->peopleActions->filter(
  365.             function ($action) {
  366.                 return $action->getAction() == PeopleActionConstant::FOLLOW;
  367.             }
  368.         );
  369.     }
  370.     /**
  371.      * Add eventAction
  372.      *
  373.      * @param EventAction $eventAction
  374.      *
  375.      * @return Band
  376.      */
  377.     public function addEventAction(EventAction $eventAction): Band
  378.     {
  379.         $this->eventActions[] = $eventAction;
  380.         return $this;
  381.     }
  382.     /**
  383.      * Remove eventAction
  384.      *
  385.      * @param EventAction $eventAction
  386.      */
  387.     public function removeEventAction(EventAction $eventAction)
  388.     {
  389.         $this->eventActions->removeElement($eventAction);
  390.     }
  391.     /**
  392.      * Get eventActions
  393.      *
  394.      * @return Collection
  395.      */
  396.     public function getEventActions()
  397.     {
  398.         return $this->eventActions;
  399.     }
  400.     public function getPublicEvents(): Collection
  401.     {
  402.         return $this->eventActions->filter(
  403.             function ($action) {
  404.                 return $action->getStatus() == ActionStatusConstant::STATUS_PUBLIC;
  405.             }
  406.         );
  407.     }
  408.     /**
  409.      * Add invitation
  410.      *
  411.      * @param Invitation $invitation
  412.      *
  413.      * @return Band
  414.      */
  415.     public function addInvitation(Invitation $invitation): Band
  416.     {
  417.         $this->invitations[] = $invitation;
  418.         return $this;
  419.     }
  420.     /**
  421.      * Remove invitation
  422.      *
  423.      * @param Invitation $invitation
  424.      */
  425.     public function removeInvitation(Invitation $invitation)
  426.     {
  427.         $this->invitations->removeElement($invitation);
  428.     }
  429.     /**
  430.      * Get invitations
  431.      *
  432.      * @return Collection
  433.      */
  434.     public function getInvitations()
  435.     {
  436.         return $this->invitations;
  437.     }
  438.     /**
  439.      * Add thread
  440.      *
  441.      * @param Thread $thread
  442.      *
  443.      * @return Band
  444.      */
  445.     public function addThread(Thread $thread): Band
  446.     {
  447.         $this->threads[] = $thread;
  448.         return $this;
  449.     }
  450.     /**
  451.      * Remove thread
  452.      *
  453.      * @param Thread $thread
  454.      */
  455.     public function removeThread(Thread $thread)
  456.     {
  457.         $this->threads->removeElement($thread);
  458.     }
  459.     /**
  460.      * Get threads
  461.      *
  462.      * @return Collection
  463.      */
  464.     public function getThreads()
  465.     {
  466.         return $this->threads;
  467.     }
  468.     /**
  469.      * Get no deleted files
  470.      *
  471.      * @return Collection
  472.      */
  473.     public function getFiles()
  474.     {
  475.         $files = new ArrayCollection();
  476.         foreach ($this->folders as $folder) {
  477.             foreach ($folder->getFiles() as $file) {
  478.                 if (!$file->getDeleted()) {
  479.                     $files->add($file);
  480.                 }
  481.             }
  482.         }
  483.         return $files;
  484.     }
  485.     /**
  486.      * Get no deleted files
  487.      *
  488.      * @return int
  489.      */
  490.     public function getTotalPlaybackNumber(): int
  491.     {
  492.         $files $this->getFiles();
  493.         $totalPlaybackCount 0;
  494.         foreach ($files as $file) {
  495.             if ($file->getPlayable()) {
  496.                 $totalPlaybackCount += count($file->getPlayable()->getPlaybacks());
  497.             }
  498.         }
  499.         return $totalPlaybackCount;
  500.     }
  501.     /**
  502.      * Add order
  503.      *
  504.      * @param Order $order
  505.      *
  506.      * @return Band
  507.      */
  508.     public function addOrder(Order $order): Band
  509.     {
  510.         $this->orders[] = $order;
  511.         return $this;
  512.     }
  513.     /**
  514.      * Remove order
  515.      *
  516.      * @param Order $order
  517.      */
  518.     public function removeOrder(Order $order)
  519.     {
  520.         $this->orders->removeElement($order);
  521.     }
  522.     /**
  523.      * Get orders
  524.      *
  525.      * @return Collection
  526.      */
  527.     public function getOrders(): Collection
  528.     {
  529.         return $this->orders;
  530.     }
  531.     /**
  532.      * Set common information entity
  533.      *
  534.      * @param CommonInformation $commonInformation
  535.      *
  536.      * @return Band
  537.      */
  538.     public function setCommonInformation(CommonInformation $commonInformation): Band
  539.     {
  540.         if ($this->commonInformation == null) {
  541.             $this->commonInformation $commonInformation;
  542.         }
  543.         return $this;
  544.     }
  545.     /**
  546.      * Get common information entity
  547.      *
  548.      * @return CommonInformation|null
  549.      */
  550.     public function getCommonInformation(): ?CommonInformation
  551.     {
  552.         return $this->commonInformation;
  553.     }
  554.     /**
  555.      * @param NewMemberSearch $newMemberSearch
  556.      *
  557.      * @return Band
  558.      */
  559.     public function addNewMemberSearch(NewMemberSearch $newMemberSearch): Band
  560.     {
  561.         $this->newMemberSearches[] = $newMemberSearch;
  562.         return $this;
  563.     }
  564.     /**
  565.      * @param NewMemberSearch $newMemberSearch
  566.      */
  567.     public function removeNewMemberSearch(NewMemberSearch $newMemberSearch)
  568.     {
  569.         $this->newMemberSearches->removeElement($newMemberSearch);
  570.     }
  571.     /**
  572.      * @return Collection
  573.      */
  574.     public function getNewMemberSearches(): Collection
  575.     {
  576.         return $this->newMemberSearches;
  577.     }
  578.     /**
  579.      * @return Collection
  580.      */
  581.     public function getActiveNewMemberSearches(): Collection
  582.     {
  583.         return $this->newMemberSearches->filter(function($newMemberSearch) {
  584.             return !$newMemberSearch->getDeleted();
  585.         });
  586.     }
  587.     /**
  588.      * Add project
  589.      *
  590.      * @param Project $project
  591.      *
  592.      * @return Band
  593.      */
  594.     public function addProject(Project $project): self
  595.     {
  596.         $this->projects[] = $project;
  597.         return $this;
  598.     }
  599.     /**
  600.      * Remove project
  601.      *
  602.      * @param Project $project
  603.      */
  604.     public function removeProject(Project $project)
  605.     {
  606.         $this->projects->removeElement($project);
  607.     }
  608.     /**
  609.      * Get projects
  610.      *
  611.      * @return Collection
  612.      */
  613.     public function getProjects(): Collection
  614.     {
  615.         return $this->projects;
  616.     }
  617. }