Cody Cook
70c8a87e15
All checks were successful
SonarQube Scan / SonarQube Trigger (push) Successful in 30s
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace DJMixHosting;
|
|
|
|
class Genres
|
|
{
|
|
|
|
private $db;
|
|
private $genres = [];
|
|
|
|
public function __construct($db)
|
|
{
|
|
|
|
$this->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;
|
|
}
|
|
}
|