128 lines
No EOL
2.7 KiB
PHP
128 lines
No EOL
2.7 KiB
PHP
<?php
|
|
|
|
class DJ
|
|
{
|
|
|
|
private int $id = -1;
|
|
private string $name = "";
|
|
private string $bio = "";
|
|
private string $slug = "";
|
|
private string $img = "";
|
|
private bool $active = false;
|
|
private string $email = "";
|
|
private array $socials = [];
|
|
|
|
private string $created = "";
|
|
private string $updated = "";
|
|
private $db = null;
|
|
|
|
|
|
public function __construct($slug, $db)
|
|
{
|
|
$this->slug = $slug;
|
|
$this->db = $db;
|
|
if (!$this->load_from_slug()) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private function load_from_slug(): bool
|
|
{
|
|
$dj = $this->get_dj_by_slug($this->slug);
|
|
if ($dj) {
|
|
if (isset($dj['id'])) {
|
|
$this->id = $dj['id'];
|
|
}
|
|
if (isset($dj['name'])) {
|
|
$this->name = $dj['name'];
|
|
}
|
|
if (isset($dj['bio'])) {
|
|
$this->bio = $dj['bio'];
|
|
}
|
|
if (isset($dj['img'])) {
|
|
$this->img = $dj['img'];
|
|
}
|
|
if (isset($dj['email'])) {
|
|
$this->email = $dj['email'];
|
|
}
|
|
if (isset($dj['socials'])) {
|
|
$this->socials = json_decode($dj['socials'], true) ?? [];
|
|
}
|
|
if (isset($dj['created'])) {
|
|
$this->created = $dj['created'];
|
|
}
|
|
if (isset($dj['updated'])) {
|
|
$this->updated = $dj['updated'];
|
|
}
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private function get_dj_by_slug($slug)
|
|
{
|
|
$stmt = $this->db->prepare("SELECT * FROM djs WHERE slug = ?");
|
|
$stmt->bind_param("s", $slug);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$dj = $result->fetch_assoc();
|
|
$stmt->close();
|
|
return $dj;
|
|
}
|
|
|
|
public function get_slug(): string
|
|
{
|
|
return $this->slug;
|
|
}
|
|
|
|
public function get_id(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function get_name(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function get_bio(): string
|
|
{
|
|
return $this->bio;
|
|
}
|
|
|
|
public function get_img(): string
|
|
{
|
|
return $this->img;
|
|
}
|
|
|
|
public function get_active(): bool
|
|
{
|
|
return $this->active;
|
|
}
|
|
|
|
public function get_email(): string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function get_socials(): array
|
|
{
|
|
return $this->socials;
|
|
}
|
|
|
|
public function get_created(): string
|
|
{
|
|
return $this->created;
|
|
}
|
|
|
|
public function get_updated(): string
|
|
{
|
|
return $this->updated;
|
|
}
|
|
|
|
|
|
} |