2016-09-02 00:34:08 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
2020-12-08 18:40:33 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Entity;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2021-12-29 21:19:34 +00:00
|
|
|
use App\OpenApi;
|
2021-04-21 07:37:47 +00:00
|
|
|
use App\Validator\Constraints\UniqueEntity;
|
2021-11-07 08:20:52 +00:00
|
|
|
use Azura\Normalizer\Attributes\DeepNormalize;
|
2020-02-18 04:32:14 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
2018-12-22 00:01:04 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2021-12-28 18:26:41 +00:00
|
|
|
use OpenApi\Attributes as OA;
|
2021-06-10 03:22:13 +00:00
|
|
|
use Stringable;
|
2020-02-18 04:32:14 +00:00
|
|
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
2019-04-07 08:40:55 +00:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2020-10-05 06:27:12 +00:00
|
|
|
use const PASSWORD_ARGON2ID;
|
2018-12-22 00:01:04 +00:00
|
|
|
|
2021-05-30 18:55:26 +00:00
|
|
|
#[
|
2021-12-19 18:50:37 +00:00
|
|
|
OA\Schema(
|
|
|
|
description: 'Station streamers (DJ accounts) allowed to broadcast to a station.',
|
|
|
|
type: "object"
|
|
|
|
),
|
2021-05-30 18:55:26 +00:00
|
|
|
ORM\Entity,
|
|
|
|
ORM\Table(name: 'station_streamers'),
|
|
|
|
ORM\UniqueConstraint(name: 'username_unique_idx', columns: ['station_id', 'streamer_username']),
|
|
|
|
ORM\HasLifecycleCallbacks,
|
|
|
|
UniqueEntity(fields: ['station', 'streamer_username']),
|
2021-05-31 01:15:34 +00:00
|
|
|
Attributes\Auditable
|
2021-05-30 18:55:26 +00:00
|
|
|
]
|
2021-07-19 05:53:45 +00:00
|
|
|
class StationStreamer implements
|
|
|
|
Stringable,
|
|
|
|
Interfaces\StationCloneAwareInterface,
|
2022-05-31 04:23:03 +00:00
|
|
|
Interfaces\IdentifiableEntityInterface,
|
|
|
|
Interfaces\StationAwareInterface
|
2016-09-02 00:34:08 +00:00
|
|
|
{
|
2021-05-30 18:55:26 +00:00
|
|
|
use Traits\HasAutoIncrementId;
|
2018-04-06 21:29:27 +00:00
|
|
|
use Traits\TruncateStrings;
|
|
|
|
|
2021-06-09 01:38:18 +00:00
|
|
|
#[ORM\Column(nullable: false)]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected int $station_id;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
ORM\ManyToOne(inversedBy: 'streamers'),
|
|
|
|
ORM\JoinColumn(name: 'station_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected Station $station;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(example: "dj_test"),
|
|
|
|
ORM\Column(length: 50),
|
|
|
|
Assert\NotBlank
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected string $streamer_username;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(example: ""),
|
|
|
|
ORM\Column(length: 255),
|
|
|
|
Assert\NotBlank,
|
|
|
|
Attributes\AuditIgnore
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected string $streamer_password;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(example: "Test DJ"),
|
|
|
|
ORM\Column(length: 255, nullable: true)
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected ?string $display_name = null;
|
2018-02-03 21:54:12 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(example: "This is a test DJ account."),
|
|
|
|
ORM\Column(type: 'text', nullable: true)
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected ?string $comments = null;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(example: true),
|
|
|
|
ORM\Column
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected bool $is_active = true;
|
2020-02-18 04:32:14 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(example: false),
|
|
|
|
ORM\Column
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected bool $enforce_schedule = false;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
2021-12-29 21:19:34 +00:00
|
|
|
OA\Property(example: OpenApi::SAMPLE_TIMESTAMP),
|
2021-12-19 18:50:37 +00:00
|
|
|
ORM\Column(nullable: true),
|
|
|
|
Attributes\AuditIgnore
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected ?int $reactivate_at = null;
|
2018-10-27 00:14:32 +00:00
|
|
|
|
2022-05-31 04:23:03 +00:00
|
|
|
#[
|
|
|
|
ORM\Column,
|
|
|
|
Attributes\AuditIgnore
|
|
|
|
]
|
|
|
|
protected int $art_updated_at = 0;
|
|
|
|
|
2022-05-31 11:41:35 +00:00
|
|
|
/** @var Collection<int, StationSchedule> */
|
2021-12-19 18:50:37 +00:00
|
|
|
#[
|
|
|
|
OA\Property(type: "array", items: new OA\Items()),
|
|
|
|
ORM\OneToMany(mappedBy: 'streamer', targetEntity: StationSchedule::class),
|
|
|
|
DeepNormalize(true),
|
|
|
|
Serializer\MaxDepth(1)
|
|
|
|
]
|
2021-05-30 18:55:26 +00:00
|
|
|
protected Collection $schedule_items;
|
2020-02-18 04:32:14 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
public function __construct(Station $station)
|
|
|
|
{
|
|
|
|
$this->station = $station;
|
2020-10-14 22:19:31 +00:00
|
|
|
$this->schedule_items = new ArrayCollection();
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getStation(): Station
|
|
|
|
{
|
|
|
|
return $this->station;
|
|
|
|
}
|
|
|
|
|
2021-06-09 23:28:44 +00:00
|
|
|
public function setStation(Station $station): void
|
|
|
|
{
|
|
|
|
$this->station = $station;
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getStreamerUsername(): string
|
|
|
|
{
|
|
|
|
return $this->streamer_username;
|
|
|
|
}
|
|
|
|
|
2020-01-29 02:23:55 +00:00
|
|
|
public function setStreamerUsername(string $streamer_username): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
2020-03-29 07:16:41 +00:00
|
|
|
$this->streamer_username = $this->truncateString($streamer_username, 50);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getStreamerPassword(): string
|
|
|
|
{
|
2020-01-29 02:23:55 +00:00
|
|
|
return '';
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 02:23:55 +00:00
|
|
|
public function setStreamerPassword(?string $streamer_password): void
|
|
|
|
{
|
2021-07-19 05:53:45 +00:00
|
|
|
$streamer_password = trim($streamer_password ?? '');
|
2020-01-29 02:23:55 +00:00
|
|
|
|
|
|
|
if (!empty($streamer_password)) {
|
2020-10-05 06:27:12 +00:00
|
|
|
$this->streamer_password = password_hash($streamer_password, PASSWORD_ARGON2ID);
|
2020-01-29 02:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function authenticate(string $password): bool
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
2020-01-29 02:23:55 +00:00
|
|
|
return password_verify($password, $this->streamer_password);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
2018-02-03 21:54:12 +00:00
|
|
|
public function getDisplayName(): string
|
|
|
|
{
|
|
|
|
return (!empty($this->display_name))
|
|
|
|
? $this->display_name
|
2019-09-04 18:00:51 +00:00
|
|
|
: $this->streamer_username;
|
2018-02-03 21:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setDisplayName(?string $display_name): void
|
|
|
|
{
|
2021-05-30 18:55:26 +00:00
|
|
|
$this->display_name = $this->truncateNullableString($display_name);
|
2018-02-03 21:54:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getComments(): ?string
|
|
|
|
{
|
|
|
|
return $this->comments;
|
|
|
|
}
|
|
|
|
|
2020-01-29 02:23:55 +00:00
|
|
|
public function setComments(string $comments = null): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->comments = $comments;
|
|
|
|
}
|
|
|
|
|
2021-11-07 05:02:44 +00:00
|
|
|
public function getIsActive(): bool
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
return $this->is_active;
|
|
|
|
}
|
|
|
|
|
2020-01-29 02:23:55 +00:00
|
|
|
public function setIsActive(bool $is_active): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
$this->is_active = $is_active;
|
2018-10-27 00:23:22 +00:00
|
|
|
|
|
|
|
// Automatically set the "reactivate_at" flag to null if the DJ is for any reason reactivated.
|
|
|
|
if (true === $is_active) {
|
|
|
|
$this->reactivate_at = null;
|
|
|
|
}
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
2018-10-27 00:14:32 +00:00
|
|
|
|
2020-02-18 04:32:14 +00:00
|
|
|
public function enforceSchedule(): bool
|
|
|
|
{
|
|
|
|
return $this->enforce_schedule;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEnforceSchedule(bool $enforce_schedule): void
|
|
|
|
{
|
|
|
|
$this->enforce_schedule = $enforce_schedule;
|
|
|
|
}
|
|
|
|
|
2018-10-27 00:14:32 +00:00
|
|
|
public function getReactivateAt(): ?int
|
|
|
|
{
|
|
|
|
return $this->reactivate_at;
|
|
|
|
}
|
|
|
|
|
2020-01-29 02:23:55 +00:00
|
|
|
public function setReactivateAt(?int $reactivate_at): void
|
2018-10-27 00:14:32 +00:00
|
|
|
{
|
|
|
|
$this->reactivate_at = $reactivate_at;
|
|
|
|
}
|
2018-10-27 00:23:22 +00:00
|
|
|
|
2020-01-29 02:23:55 +00:00
|
|
|
public function deactivateFor(int $seconds): void
|
2018-10-27 00:23:22 +00:00
|
|
|
{
|
|
|
|
$this->is_active = false;
|
2019-09-04 18:00:51 +00:00
|
|
|
$this->reactivate_at = time() + $seconds;
|
2018-10-27 00:23:22 +00:00
|
|
|
}
|
2020-02-18 04:32:14 +00:00
|
|
|
|
2022-05-31 04:23:03 +00:00
|
|
|
public function getArtUpdatedAt(): int
|
|
|
|
{
|
|
|
|
return $this->art_updated_at;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setArtUpdatedAt(int $art_updated_at): self
|
|
|
|
{
|
|
|
|
$this->art_updated_at = $art_updated_at;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:32:14 +00:00
|
|
|
/**
|
2022-05-31 11:41:35 +00:00
|
|
|
* @return Collection<int, StationSchedule>
|
2020-02-18 04:32:14 +00:00
|
|
|
*/
|
|
|
|
public function getScheduleItems(): Collection
|
|
|
|
{
|
|
|
|
return $this->schedule_items;
|
|
|
|
}
|
2021-05-30 18:55:26 +00:00
|
|
|
|
|
|
|
public function __toString(): string
|
|
|
|
{
|
2021-06-08 06:40:49 +00:00
|
|
|
return $this->getStation() . ' Streamer: ' . $this->getDisplayName();
|
2021-05-30 18:55:26 +00:00
|
|
|
}
|
2021-06-09 23:28:44 +00:00
|
|
|
|
2021-06-10 00:34:11 +00:00
|
|
|
public function __clone()
|
2021-06-09 23:28:44 +00:00
|
|
|
{
|
|
|
|
$this->reactivate_at = null;
|
|
|
|
}
|
2022-05-31 04:23:03 +00:00
|
|
|
|
|
|
|
public static function getArtworkPath(int|string $streamer_id): string
|
|
|
|
{
|
|
|
|
return 'streamer_' . $streamer_id . '.jpg';
|
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|