Add mix lookup, genre support, DJ enhancements.

This commit is contained in:
Cody Cook 2024-04-30 01:07:22 -07:00
commit db1d26e122
11 changed files with 741 additions and 181 deletions

View file

@ -19,21 +19,43 @@ class DJ
private $db = null;
public function __construct($slug, $db)
public function __construct($value, $db)
{
$this->slug = $slug;
$this->db = $db;
if (!$this->load_from_slug()) {
return false;
if (ctype_digit((string)$value)) {
$this->id = (int)$value;
return $this->load_from_id();
} else {
return true;
$this->slug = $value;
return $this->load_from_slug();
}
}
private function load_from_slug(): bool
private function load_from_id(): bool
{
$socials = [];
$dj = $this->get_dj_by_slug($this->slug);
$dj = $this->get_dj_by_id($this->id);
return $this->build_dj($dj);
}
private function get_dj_by_id()
{
$stmt = $this->db->prepare("SELECT * FROM djs WHERE id = ?");
$stmt->bind_param("i", $this->id);
$stmt->execute();
$result = $stmt->get_result();
$dj = $result->fetch_assoc();
$stmt->close();
return $dj;
}
/**
* @param $dj
* @return bool
*/
private function build_dj($dj): bool
{
if ($dj) {
if (isset($dj['id'])) {
$this->id = $dj['id'];
@ -44,6 +66,10 @@ class DJ
if (isset($dj['bio'])) {
$this->bio = $dj['bio'];
}
if (isset($dj['slug'])) {
$this->slug = $dj['slug'];
}
if (isset($dj['img'])) {
// is this legacy code?
@ -109,6 +135,13 @@ class DJ
}
}
private function load_from_slug(): bool
{
$socials = [];
$dj = $this->get_dj_by_slug($this->slug);
return $this->build_dj($dj);
}
private function get_dj_by_slug($slug)
{
$stmt = $this->db->prepare("SELECT * FROM djs WHERE slug = ?");