Add locale, en_US, DJ and Database functions.

This commit is contained in:
Cody Cook 2024-04-29 21:16:49 -07:00
commit 5fe1a21b8e
7 changed files with 440 additions and 8 deletions

128
classes/DJ.php Normal file
View file

@ -0,0 +1,128 @@
<?php
class DJ
{
private int $id = -1;
private string $name = "";
private string $bio = "";
private string $slug = "";
private string $img = "";
private bool $active = false;
private string $email = "";
private array $socials = [];
private string $created = "";
private string $updated = "";
private $db = null;
public function __construct($slug, $db)
{
$this->slug = $slug;
$this->db = $db;
if (!$this->load_from_slug()) {
return false;
} else {
return true;
}
}
private function load_from_slug(): bool
{
$dj = $this->get_dj_by_slug($this->slug);
if ($dj) {
if (isset($dj['id'])) {
$this->id = $dj['id'];
}
if (isset($dj['name'])) {
$this->name = $dj['name'];
}
if (isset($dj['bio'])) {
$this->bio = $dj['bio'];
}
if (isset($dj['img'])) {
$this->img = $dj['img'];
}
if (isset($dj['email'])) {
$this->email = $dj['email'];
}
if (isset($dj['socials'])) {
$this->socials = json_decode($dj['socials'], true) ?? [];
}
if (isset($dj['created'])) {
$this->created = $dj['created'];
}
if (isset($dj['updated'])) {
$this->updated = $dj['updated'];
}
return true;
} else {
return false;
}
}
private function get_dj_by_slug($slug)
{
$stmt = $this->db->prepare("SELECT * FROM djs WHERE slug = ?");
$stmt->bind_param("s", $slug);
$stmt->execute();
$result = $stmt->get_result();
$dj = $result->fetch_assoc();
$stmt->close();
return $dj;
}
public function get_slug(): string
{
return $this->slug;
}
public function get_id(): int
{
return $this->id;
}
public function get_name(): string
{
return $this->name;
}
public function get_bio(): string
{
return $this->bio;
}
public function get_img(): string
{
return $this->img;
}
public function get_active(): bool
{
return $this->active;
}
public function get_email(): string
{
return $this->email;
}
public function get_socials(): array
{
return $this->socials;
}
public function get_created(): string
{
return $this->created;
}
public function get_updated(): string
{
return $this->updated;
}
}

View file

@ -7,6 +7,6 @@ class Database extends mysqli
public function __construct($config)
{
// call the parent constructor with the config file
parent::__construct($config['database']['host'], $config['database']['username'], $config['database']['password'], $config['database']['database'], $config['database']['port'] ?? 3306);
parent::__construct($config['database']['host'], $config['database']['user'], $config['database']['pass'], $config['database']['db'], $config['database']['port'] ?? 3306);
}
}