2016-09-02 00:34:08 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Entity;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2019-08-14 23:50:53 +00:00
|
|
|
use App\Annotations\AuditLog;
|
2020-02-18 04:32:14 +00:00
|
|
|
use App\Normalizer\Annotation\DeepNormalize;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
2018-12-22 00:01:04 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-04-07 08:40:55 +00:00
|
|
|
use OpenApi\Annotations as OA;
|
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
|
|
|
|
2016-09-02 00:34:08 +00:00
|
|
|
/**
|
|
|
|
* Station streamers (DJ accounts) allowed to broadcast to a station.
|
|
|
|
*
|
2020-01-29 02:23:55 +00:00
|
|
|
* @ORM\Table(name="station_streamers", uniqueConstraints={
|
|
|
|
* @ORM\UniqueConstraint(name="username_unique_idx", columns={"station_id", "streamer_username"})
|
|
|
|
* })
|
2019-09-29 07:50:24 +00:00
|
|
|
* @ORM\Entity()
|
2018-12-22 00:01:04 +00:00
|
|
|
* @ORM\HasLifecycleCallbacks
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\Auditable
|
|
|
|
*
|
2019-04-07 08:40:55 +00:00
|
|
|
* @OA\Schema(type="object")
|
2016-09-02 00:34:08 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
class StationStreamer
|
2016-09-02 00:34:08 +00:00
|
|
|
{
|
2018-04-06 21:29:27 +00:00
|
|
|
use Traits\TruncateStrings;
|
|
|
|
|
2016-09-02 00:34:08 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="id", type="integer")
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY")
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=1)
|
2020-12-05 07:39:05 +00:00
|
|
|
* @var int|null
|
2016-09-02 00:34:08 +00:00
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="station_id", type="integer")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
2016-09-02 00:34:08 +00:00
|
|
|
protected $station_id;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\ManyToOne(targetEntity="Station", inversedBy="streamers")
|
2018-12-22 00:01:04 +00:00
|
|
|
* @ORM\JoinColumns({
|
|
|
|
* @ORM\JoinColumn(name="station_id", referencedColumnName="id", onDelete="CASCADE")
|
2017-08-17 18:28:48 +00:00
|
|
|
* })
|
|
|
|
* @var Station
|
|
|
|
*/
|
|
|
|
protected $station;
|
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="streamer_username", type="string", length=50, nullable=false)
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example="dj_test")
|
2019-04-10 04:46:51 +00:00
|
|
|
* @Assert\NotBlank()
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2016-09-02 00:34:08 +00:00
|
|
|
protected $streamer_username;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2020-01-29 02:23:55 +00:00
|
|
|
* @ORM\Column(name="streamer_password", type="string", length=255, nullable=false)
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
2020-03-15 05:00:29 +00:00
|
|
|
* @AuditLog\AuditIgnore()
|
|
|
|
*
|
2020-01-29 02:23:55 +00:00
|
|
|
* @Assert\NotBlank()
|
2019-04-07 08:40:55 +00:00
|
|
|
* @OA\Property(example="")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2016-09-02 00:34:08 +00:00
|
|
|
protected $streamer_password;
|
|
|
|
|
2018-02-03 21:54:12 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="display_name", type="string", length=255, nullable=true)
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example="Test DJ")
|
2018-02-03 21:54:12 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $display_name;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="comments", type="text", nullable=true)
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example="This is a test DJ account.")
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
2016-09-02 00:34:08 +00:00
|
|
|
protected $comments;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="is_active", type="boolean", nullable=false)
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
|
|
|
* @OA\Property(example=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
2020-02-18 04:32:14 +00:00
|
|
|
protected $is_active = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Column(name="enforce_schedule", type="boolean", nullable=false)
|
|
|
|
*
|
|
|
|
* @OA\Property(example=false)
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $enforce_schedule = false;
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2019-09-04 18:00:51 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="reactivate_at", type="integer", nullable=true)
|
2019-04-07 08:40:55 +00:00
|
|
|
*
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\AuditIgnore()
|
|
|
|
*
|
2019-04-07 08:40:55 +00:00
|
|
|
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
2018-10-27 00:14:32 +00:00
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
protected $reactivate_at;
|
|
|
|
|
2020-02-18 04:32:14 +00:00
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="StationSchedule", mappedBy="streamer")
|
|
|
|
* @var Collection
|
|
|
|
*
|
|
|
|
* @DeepNormalize(true)
|
|
|
|
* @Serializer\MaxDepth(1)
|
|
|
|
* @OA\Property(
|
|
|
|
* @OA\Items()
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
protected $schedule_items;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-12-05 07:39:05 +00:00
|
|
|
public function getId(): ?int
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStation(): Station
|
|
|
|
{
|
|
|
|
return $this->station;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
$streamer_password = trim($streamer_password);
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\AuditIdentifier()
|
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
|
|
|
|
{
|
2020-03-29 07:16:41 +00:00
|
|
|
$this->display_name = $this->truncateString($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;
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:32:14 +00:00
|
|
|
public function isActive(): 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
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection|StationSchedule[]
|
|
|
|
*/
|
|
|
|
public function getScheduleItems(): Collection
|
|
|
|
{
|
|
|
|
return $this->schedule_items;
|
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|