dj_mix_hosting_software/classes/Mixshow.php
Cody Cook 70c8a87e15
All checks were successful
SonarQube Scan / SonarQube Trigger (push) Successful in 30s
Changes.
2024-05-19 20:01:13 -07:00

149 lines
3.6 KiB
PHP

<?php
namespace DJMixHosting;
class Mixshow
{
private $id = -1;
private $enabled = false;
private $name = "";
private $slug = "";
private $db = null;
private $description = "";
private $cover = "/img/no-image1.png";
private $count;
private $mixes = [];
private $updated;
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['name'] != "") {
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'];
// is this legacy code?
// the code is legacy if it starts with /dj/,
// if it does, prefix with https://www.utahsdjs.com
if (substr($mixshow['cover'], 0, 5) == "/djs/") {
// remove /djs/ from the string
$mixshow['cover'] = substr($mixshow['cover'], 4);
$this->cover = "https://cdn.utahsdjs.com" . $mixshow['cover'];
}
$this->updated = $mixshow['lastupdated'];
$this->count = $mixshow['count'];
$this->load_mixes();
return true;
}
private function load_mixes()
{
$stmt = $this->db->prepare("SELECT mix_id FROM mix_meta WHERE value = ? AND attribute = 'mixshow'");
$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['name'] != "") {
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;
}
public function get_updated(){
return $this->updated;
}
}