dj_mix_hosting_software/classes/Genre.php
2024-04-29 23:27:28 -07:00

102 lines
No EOL
2.2 KiB
PHP

<?php
class Genre
{
private $id = "" ;
private $enabled = "";
private $count = "";
private $name = "";
private $slug = "";
private $db = "";
public function __construct($value, $db)
{
$this->db = $db;
if (intval($value)) {
$this->id = $value;
if ($this->load_by_id()) {
return true;
} else {
return false;
}
} else {
$this->slug = $value;
if ($this->load_by_slug()) {
return true;
} else {
return false;
}
}
}
private function load_by_id(): bool
{
$genre = $this->get_genre_by_id();
if ($genre && $genre['name'] != "") {
$this->enabled = $genre['enabled'];
$this->count = $genre['count'];
$this->name = $genre['name'];
$this->slug = $genre['slug'];
return true;
} else {
return false;
}
}
private function get_genre_by_id()
{
$stmt = $this->db->prepare("SELECT * FROM genres WHERE id = ?");
$stmt->bind_param("i", $this->id);
$stmt->execute();
$result = $stmt->get_result();
$dj = $result->fetch_assoc();
$stmt->close();
return $dj;
}
private function load_by_slug(): bool
{
$genre = $this->get_genre_by_slug();
if ($genre && $genre['name'] != "") {
$this->id = $genre['id'];
$this->enabled = $genre['enabled'];
$this->count = $genre['count'];
$this->name = $genre['name'];
return true;
}
return false;
}
private function get_genre_by_slug()
{
$stmt = $this->db->prepare("SELECT * FROM genres WHERE slug = ?");
$stmt->bind_param("s", $this->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;
}
}