dj_mix_hosting_software/classes/Mixshow.php

134 lines
No EOL
3 KiB
PHP

<?php
class Mixshow
{
private $id = -1;
private $enabled = false;
private $name = "";
private $slug = "";
private $db = null;
private $description = "";
private $cover = "";
private $count;
private $mixes = [];
public function __construct($value, $db)
{
$this->db = $db;
if (ctype_digit((string)$value)) {
$this->id = (int)$value;
return $this->load_by_id();
} else {
$this->slug = $value;
return $this->load_by_slug();
}
}
private function load_by_id()
{
$mixshow = $this->get_mixshow_by_id();
if ($mixshow && $mixshow['title'] != "") {
return $this->build_mixshow($mixshow);
} else {
return false;
}
}
private function get_mixshow_by_id()
{
$stmt = $this->db->prepare("SELECT * FROM shows WHERE id = ?");
$stmt->bind_param("i", $this->id);
$stmt->execute();
$result = $stmt->get_result();
return $result->fetch_assoc();
}
private function build_mixshow($mixshow)
{
$this->id = $mixshow['id'];
$this->name = $mixshow['name'];
$this->slug = $mixshow['slug'];
$this->description = $mixshow['description'];
$this->cover = $mixshow['cover'];
$this->enabled = $mixshow['enabled'];
$this->count = $mixshow['count'];
$this->load_mixes();
return true;
}
private function load_mixes()
{
$stmt = $this->db->prepare("SELECT value FROM mix_meta WHERE value = ?");
$stmt->bind_param("i", $this->id);
$stmt->execute();
$result = $stmt->get_result();
$this->mixes = [];
while ($mix = $result->fetch_assoc()) {
$this->mixes[] = $mix;
}
}
private function load_by_slug()
{
$mixshow = $this->get_mixshow_by_slug();
if ($mixshow && $mixshow['title'] != "") {
return $this->build_mixshow($mixshow);
} else {
return false;
}
}
private function get_mixshow_by_slug()
{
$stmt = $this->db->prepare("SELECT * FROM shows WHERE slug = ?");
$stmt->bind_param("s", $this->slug);
$stmt->execute();
$result = $stmt->get_result();
return $result->fetch_assoc();
}
public function get_id()
{
return $this->id;
}
public function get_name()
{
return $this->name;
}
public function get_slug()
{
return $this->slug;
}
public function get_description()
{
return $this->description;
}
public function get_cover()
{
return $this->cover;
}
public function get_enabled()
{
return $this->enabled;
}
public function get_count()
{
return $this->count;
}
public function get_mixes()
{
return $this->mixes;
}
}