Check-in; adding features like mixshow and google analytics.
This commit is contained in:
parent
36e6e23a68
commit
8288ebc67a
50 changed files with 1492 additions and 483 deletions
345
classes/Mix.php
345
classes/Mix.php
|
@ -7,26 +7,32 @@ class Mix
|
|||
private $enabled = false;
|
||||
private $name = "";
|
||||
private $slug = "";
|
||||
private $genre = [];
|
||||
private $db = null;
|
||||
private $description = "";
|
||||
private $cover = "";
|
||||
private $url = "";
|
||||
private $seconds = 0;
|
||||
private $mediaplayer = false;
|
||||
private $download_only = true;
|
||||
private $djs = [];
|
||||
private $genres = [];
|
||||
private $recorded;
|
||||
private $downloads = 0;
|
||||
private $created;
|
||||
private $updated;
|
||||
private $playcount = 0;
|
||||
private $tracklist = [];
|
||||
private $loadDJs = true;
|
||||
private $related_mixes = [];
|
||||
private $duration = [];
|
||||
private $mixshow = [];
|
||||
|
||||
|
||||
public function __construct($value, $db)
|
||||
public function __construct($value, $db, $loadDJs = true)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
// echo the type of value
|
||||
|
||||
if (ctype_digit((string)$value)) {
|
||||
$this->id = (int)$value;
|
||||
return $this->load_by_id();
|
||||
|
@ -40,7 +46,7 @@ class Mix
|
|||
private function load_by_id(): bool
|
||||
{
|
||||
$mix = $this->get_mix_by_id();
|
||||
if ($mix && $mix['name'] != "") {
|
||||
if ($mix && $mix['title'] != "") {
|
||||
return $this->build_mix($mix);
|
||||
} else {
|
||||
return false;
|
||||
|
@ -58,122 +64,6 @@ class Mix
|
|||
return $mix;
|
||||
}
|
||||
|
||||
private function get_mix_genres()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix_meta WHERE attribute = 'genre' AND mix_id = ?");
|
||||
$stmt->bind_param("i", $this->id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$genres = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $genres;
|
||||
}
|
||||
|
||||
private function get_playcount()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT value FROM mix_meta WHERE attribute = 'playcount' AND mix_id = ?");
|
||||
$stmt->bind_param("i", $this->id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$genres = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $genres;
|
||||
}
|
||||
|
||||
private function load_by_slug(): bool
|
||||
{
|
||||
$mix = $this->get_mix_by_slug();
|
||||
|
||||
if ($mix['title'] != "") {
|
||||
return $this->build_mix($mix);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function get_mix_by_slug()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE slug = ?");
|
||||
$stmt->bind_param("s", $this->slug);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mix = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
return $mix;
|
||||
}
|
||||
|
||||
private function load_mix_genres()
|
||||
{
|
||||
$genres = $this->get_mix_genres();
|
||||
if (count($genres) == 0) {
|
||||
$this->genres = [];
|
||||
} else {
|
||||
// iterate through the genres; add each of the rest to the array
|
||||
$this->genres = [];
|
||||
require_once 'Genre.php';
|
||||
foreach ($genres as $genre) {
|
||||
$genre = new Genre($genre['value'], $this->db);
|
||||
if ($genre->get_id() != -1) {
|
||||
$this->genres[] = ['id' => $genre->get_id(), 'name' => $genre->get_name(), 'slug' => $genre->get_slug()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function evaluate_tracklist(): array
|
||||
{
|
||||
if (empty($this->tracklist)){
|
||||
return [];
|
||||
} else {
|
||||
// if the first item in the array is also an array, then return it
|
||||
if (is_array($this->tracklist[0]['value'])){
|
||||
|
||||
return $this->tracklist[0]['value'];
|
||||
} else {
|
||||
return explode("\n", $this->tracklist[0]['value']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function load_mix_tracklist()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT value FROM mix_meta WHERE attribute = 'tracklist' AND mix_id = ?");
|
||||
$stmt->bind_param("i", $this->id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$tracklist = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return $tracklist;
|
||||
}
|
||||
|
||||
public function get_img(): string
|
||||
{
|
||||
return $this->cover;
|
||||
}
|
||||
|
||||
public function get_id(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_slug(): string
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function get_djs(){
|
||||
return $this->djs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mix
|
||||
* @return true
|
||||
|
@ -198,29 +88,157 @@ class Mix
|
|||
}
|
||||
$this->url = $mix['url'];
|
||||
$this->seconds = $mix['seconds'];
|
||||
$this->mediaplayer = $mix['mediaplayer'];
|
||||
$this->duration = $this->configure_duration();
|
||||
$this->download_only = $mix['mediaplayer'];
|
||||
$this->recorded = $mix['recorded'];
|
||||
$this->created = $mix['created'];
|
||||
$this->updated = $mix['lastupdated'];
|
||||
$this->enabled = $mix['pending'];
|
||||
require 'DJ.php';
|
||||
$this->djs[] = new DJ($mix['dj1'], $this->db);
|
||||
if ($mix['dj2'] != null)
|
||||
$this->djs[] = new DJ($mix['dj2'], $this->db);
|
||||
if ($mix['dj3'] != null)
|
||||
$this->djs[] = new DJ($mix['dj3'], $this->db);
|
||||
if ($this->loadDJs) {
|
||||
require_once 'DJ.php';
|
||||
$this->djs[] = new DJ($mix['dj1'], $this->db);
|
||||
if ($mix['dj2'] != null) $this->djs[] = new DJ($mix['dj2'], $this->db);
|
||||
if ($mix['dj3'] != null) $this->djs[] = new DJ($mix['dj3'], $this->db);
|
||||
|
||||
// delete any nulls from the array
|
||||
$this->djs = array_filter($this->djs);
|
||||
$this->djs = array_filter($this->djs);
|
||||
}
|
||||
|
||||
$this->genre = $this->get_mix_genres();
|
||||
$this->playcount = $this->get_playcount();
|
||||
$this->tracklist = $this->load_mix_tracklist();
|
||||
$this->load_mix_meta();
|
||||
$this->tracklist = $this->evaluate_tracklist();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function configure_duration(): array
|
||||
{
|
||||
$seconds = $this->seconds;
|
||||
$hours = floor($seconds / 3600);
|
||||
$minutes = floor(($seconds / 60) % 60);
|
||||
$seconds = $seconds % 60;
|
||||
|
||||
// for 't', we need to show it as 01:02:03
|
||||
if ($hours < 10) {
|
||||
$hours0 = "0" . $hours;
|
||||
} else {
|
||||
$hours0 = $hours;
|
||||
}
|
||||
if ($minutes < 10) {
|
||||
$minutes0 = "0" . $minutes;
|
||||
} else {
|
||||
$minutes0 = $minutes;
|
||||
}
|
||||
if ($seconds < 10) {
|
||||
$seconds0 = "0" . $seconds;
|
||||
} else {
|
||||
$seconds0 = $seconds;
|
||||
}
|
||||
|
||||
// if hours is 0, we don't need to show it
|
||||
$time = $hours > 0 ? $hours0 . ":" . $minutes0 . ":" . $seconds0 : $minutes0 . ":" . $seconds0;
|
||||
|
||||
return ['h' => $hours, 'm' => $minutes, 's' => $seconds, 't' => $time, 'S' => $this->seconds];
|
||||
}
|
||||
|
||||
private function load_mix_meta(): void
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT attribute,value FROM mix_meta WHERE mix_id = ?");
|
||||
$stmt->bind_param("i", $this->id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$meta = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
|
||||
foreach ($meta as $key => $value) {
|
||||
if ($value['attribute'] == "genre") {
|
||||
$this->genres[] = $value['value'];
|
||||
unset($meta[$key]);
|
||||
}
|
||||
if ($value['attribute'] == "related") {
|
||||
$this->related_mixes[] = $value['value'];
|
||||
unset($meta[$key]);
|
||||
}
|
||||
if ($value['attribute'] == "playcount") {
|
||||
$this->playcount = $value['value'];
|
||||
unset($meta[$key]);
|
||||
}
|
||||
if ($value['attribute'] == "downloads") {
|
||||
$this->downloads = $value['value'];
|
||||
unset($meta[$key]);
|
||||
}
|
||||
if ($value['attribute'] == "tracklist") {
|
||||
$this->tracklist = $value['value'];
|
||||
unset($meta[$key]);
|
||||
}
|
||||
if ($value['attribute'] == "mixshow") {
|
||||
$this->mixshow[] = $value['value'];
|
||||
unset($meta[$key]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function evaluate_tracklist()
|
||||
{
|
||||
if (empty($this->tracklist)) {
|
||||
return [];
|
||||
} else {
|
||||
// if the first item in the array is also an array, then return it
|
||||
if (is_array($this->tracklist)) {
|
||||
return $this->tracklist;
|
||||
} else {
|
||||
return explode("\n", (string)$this->tracklist);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function load_by_slug(): bool
|
||||
{
|
||||
$mix = $this->get_mix_by_slug();
|
||||
|
||||
if ($mix['title'] != "") {
|
||||
return $this->build_mix($mix);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function get_mix_by_slug()
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE slug = ?");
|
||||
$stmt->bind_param("s", $this->slug);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mix = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
return $mix;
|
||||
}
|
||||
|
||||
public function get_recorded()
|
||||
{
|
||||
return $this->recorded;
|
||||
}
|
||||
|
||||
public function get_created()
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function get_updated()
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
public function get_img(): string
|
||||
{
|
||||
return $this->cover;
|
||||
}
|
||||
|
||||
public function get_djs()
|
||||
{
|
||||
return $this->djs;
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
{
|
||||
return $this->description;
|
||||
|
@ -231,5 +249,66 @@ class Mix
|
|||
return $this->tracklist;
|
||||
}
|
||||
|
||||
public function get_genres()
|
||||
{
|
||||
return $this->genres;
|
||||
}
|
||||
|
||||
public function get_seconds(): int
|
||||
{
|
||||
return $this->seconds;
|
||||
}
|
||||
|
||||
public function is_download_only(): bool
|
||||
{
|
||||
return $this->download_only;
|
||||
}
|
||||
|
||||
public function get_url(): string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function get_cover(): string
|
||||
{
|
||||
return $this->cover;
|
||||
}
|
||||
|
||||
public function get_downloads(): int
|
||||
{
|
||||
return $this->downloads;
|
||||
}
|
||||
|
||||
public function get_plays(): int
|
||||
{
|
||||
return $this->playcount;
|
||||
}
|
||||
|
||||
public function get_id(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_slug(): string
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function get_duration(): array
|
||||
{
|
||||
return $this->duration;
|
||||
}
|
||||
|
||||
public function get_mixshow(): array
|
||||
{
|
||||
return $this->mixshow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue