diff --git a/classes/DJ.php b/classes/DJ.php index 0fe5a41..56514fe 100644 --- a/classes/DJ.php +++ b/classes/DJ.php @@ -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 = ?"); diff --git a/classes/Genre.php b/classes/Genre.php index 8a74623..f724797 100644 --- a/classes/Genre.php +++ b/classes/Genre.php @@ -3,9 +3,9 @@ class Genre { - private $id = "" ; + private $id = -1 ; private $enabled = ""; - private $count = ""; + private $count = 0; private $name = ""; private $slug = ""; private $db = ""; @@ -13,25 +13,15 @@ class Genre public function __construct($value, $db) { $this->db = $db; - if (intval($value)) { - $this->id = $value; - if ($this->load_by_id()) { - return true; - } else { - return false; - } + + if (ctype_digit((string)$value)) { + $this->id = (int)$value; + return $this->load_by_id(); } else { $this->slug = $value; - if ($this->load_by_slug()) { - return true; - } else { - return false; - } + return $this->load_by_slug(); } - - } - private function load_by_id(): bool { $genre = $this->get_genre_by_id(); @@ -98,5 +88,14 @@ class Genre return $this->name; } + public function get_img(): string + { + return "img/no-image1.png"; + } + + public function get_count(): int + { + return $this->count; + } } \ No newline at end of file diff --git a/classes/Genres.php b/classes/Genres.php new file mode 100644 index 0000000..b881859 --- /dev/null +++ b/classes/Genres.php @@ -0,0 +1,53 @@ +db = $db; + if (!$this->load_all_genres()) { + return false; + } else { + return true; + } + + } + + private function load_all_genres(): bool + { + $genres = $this->get_all_genres(); + if ($genres) { + $this->genres = $genres; + return true; + } else { + return false; + } + + + } + + public function get_all_genres($order = "ASC") + { + $stmt = $this->db->prepare("SELECT * FROM genres ORDER BY name $order"); + $stmt->execute(); + $result = $stmt->get_result(); + $genres = $result->fetch_all(MYSQLI_ASSOC); + $stmt->close(); + return $genres; + } + + public function get_nonzero_genres() + { + $stmt = $this->db->prepare("SELECT * FROM genres WHERE count > 0 ORDER BY name ASC"); + $stmt->execute(); + $result = $stmt->get_result(); + $genres = $result->fetch_all(MYSQLI_ASSOC); + $stmt->close(); + return $genres; + } +} \ No newline at end of file diff --git a/classes/Mix.php b/classes/Mix.php new file mode 100644 index 0000000..079718d --- /dev/null +++ b/classes/Mix.php @@ -0,0 +1,195 @@ +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(): bool + { + $mix = $this->get_mix_by_id(); + if ($mix && $mix['name'] != "") { + return $this->build_mix($mix); + } else { + return false; + } + } + + private function get_mix_by_id() + { + $stmt = $this->db->prepare("SELECT * FROM mix WHERE id = ?"); + $stmt->bind_param("i", $this->id); + $stmt->execute(); + $result = $stmt->get_result(); + $mix = $result->fetch_assoc(); + $stmt->close(); + 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()]; + } + + } + + } + + } + 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 + */ + private function build_mix($mix): bool + { + $this->id = $mix['id']; + $this->name = $mix['title']; + $this->slug = $mix['slug']; + $this->description = $mix['description']; + if (isset($mix['cover'])) { + + // is this legacy code? + // the code is legacy if it starts with /dj/, + // if it does, prefix with https://www.utahsdjs.com + if (substr($mix['cover'], 0, 5) == "/djs/") { + $mix['cover'] = substr($mix['cover'], 4); + $this->cover = "https://cdn.utahsdjs.com" . $mix['cover']; + } else { + $this->cover = $mix['cover']; + } + } + $this->url = $mix['url']; + $this->seconds = $mix['seconds']; + $this->mediaplayer = $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); + + // delete any nulls from the array + $this->djs = array_filter($this->djs); + + $this->genre = $this->get_mix_genres(); + $this->playcount = $this->get_playcount(); + + + return true; + } + +} + diff --git a/dj.php b/dj.php index ae9438a..e8a319a 100644 --- a/dj.php +++ b/dj.php @@ -30,7 +30,7 @@ if (isset($_GET['dj']) && $_GET['dj'] != "") { <?php echo $config['app']['name']; ?> - + @@ -42,11 +42,11 @@ if (isset($_GET['dj']) && $_GET['dj'] != "") {
- +
- avatar -
get_name(); +
get_name(); ?>
- get_claimed()) { - echo '

'; - echo "Claimed"; - echo "

"; - } - - ?>

-

$location1

-
-
-
-
    - - -

    $value -

    - "; - } - $socials = $dj->get_socials(); - - foreach ($socials as $key => $value) { - echo social_line($key, $value); - } - - ?> - -
-
-
-

Full Name

+

-

Johnatan Smith

+

get_count(); ?> +


@@ -184,33 +100,6 @@ if (isset($_GET['genre']) && $_GET['genre'] != "") {

example@example.com

-
-
-
-

Phone

-
-
-

(097) 234-5678

-
-
-
-
-
-

Mobile

-
-
-

(098) 765-4321

-
-
-
-
-
-

Address

-
-
-

Bay Area, San Francisco, CA

-
-
diff --git a/genres.php b/genres.php new file mode 100644 index 0000000..a407117 --- /dev/null +++ b/genres.php @@ -0,0 +1,111 @@ + + + + + + + <?php echo $config['app']['name']; ?> + + + + + + + + +
+
+
+
+ +
+
+ + get_all_genres + // create a card for each genre, 4 max per row + + $genres = $genres->get_nonzero_genres(); + $count = 0; + foreach ($genres as $genre) { + if ($count % 4 == 0) { + echo '
'; + } + echo '
'; + echo '
'; + echo '
'; + echo '
' . $genre['name'] . '
'; + echo '

' . $genre['count'] . ' ' ; + if ($genre['count'] == 1) { + echo $locale['mix']; + } else { + echo $locale['mixes']; + } + echo '

'; + echo '' . $locale['view'] . ''; + echo '
'; + echo '
'; + echo '
'; + if ($count % 4 == 3) { + echo '
'; + } + $count++; + } + ?> + +
+
+ + + \ No newline at end of file diff --git a/index.php b/index.php index a864314..848107f 100644 --- a/index.php +++ b/index.php @@ -12,18 +12,32 @@ $lang = $_SESSION['lang'] ?? $config['app']['locale']; $locale = loadLocale($lang); ?> - + <?php echo $config['app']['name']; ?> + + - + - - +
+
+
+
+ +
+
+
+
+ \ No newline at end of file diff --git a/locale/en_US/messages.php b/locale/en_US/messages.php index cdc51d4..3bb19a8 100644 --- a/locale/en_US/messages.php +++ b/locale/en_US/messages.php @@ -19,4 +19,15 @@ return [ "genre" => "Genre", "genres" => "Genres", "genreNotFound" => "Could not load genre; either the genre wasn't found, was empty, or this genre is private.", + "mix-count" => "Mix Count", + "mixes" => "Mixes", + "mix" => "Mix", + "mixNotFound" => "Could not load mix; either the mix wasn't found, was empty, or this mix is private.", + "mixName" => "Mix Name", + "mixDescription" => "Mix Description", + "mixLength" => "Mix Length", + "mixGenre" => "Mix Genre", + "view" => "View", + "mixname" => "Mix Name", + ]; \ No newline at end of file diff --git a/mix.php b/mix.php new file mode 100644 index 0000000..9c54b69 --- /dev/null +++ b/mix.php @@ -0,0 +1,242 @@ +get_name() != "") { + $mixFound = true; + } +} + + +?> + + + + + + <?php echo $config['app']['name']; ?> + + + + + + + +
+
+
+
+ +
+
+ + +
+
+
+
+ avatar +
get_name(); + ?>
+

+
+
+
+
+
+
+
+
+

+
+
+

get_name(); ?>

+
+
+
+
+
+

+
+
+

+ get_djs(); + $djCount = count($djs); + $i = 0; + foreach ($djs as $dj) { + echo "" . $dj->get_name() . ""; + if ($i < $djCount - 1) { + echo ", "; + } + $i++; + } + + + ?> + +

+
+
+
+
+
+

Phone

+
+
+

(097) 234-5678

+
+
+
+
+
+

Mobile

+
+
+

(098) 765-4321

+
+
+
+
+
+

Address

+
+
+

Bay Area, San Francisco, CA

+
+
+
+
+
+
+
+
+

assigment Project + Status +

+

Web Design

+
+
+
+

Website Markup

+
+
+
+

One Page

+
+
+
+

Mobile Template

+
+
+
+

Backend API

+
+
+
+
+
+
+
+
+
+

assigment Project + Status +

+

Web Design

+
+
+
+

Website Markup

+
+
+
+

One Page

+
+
+
+

Mobile Template

+
+
+
+

Backend API

+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+ + +
+
+ + + \ No newline at end of file diff --git a/navbar.php b/navbar.php index 8f808f0..94f792a 100644 --- a/navbar.php +++ b/navbar.php @@ -1,28 +1,40 @@ -