db = $db; if (intval($value)) { $this->id = $value; if ($this->load_by_id()) { return true; } else { return false; } } else { $this->slug = $value; if ($this->load_by_slug()) { return true; } else { return false; } } } private function load_by_id(): bool { $genre = $this->get_genre_by_id(); if ($genre && $genre['name'] != "") { $this->enabled = $genre['enabled']; $this->count = $genre['count']; $this->name = $genre['name']; $this->slug = $genre['slug']; return true; } else { return false; } } private function get_genre_by_id() { $stmt = $this->db->prepare("SELECT * FROM genres WHERE id = ?"); $stmt->bind_param("i", $this->id); $stmt->execute(); $result = $stmt->get_result(); $dj = $result->fetch_assoc(); $stmt->close(); return $dj; } private function load_by_slug(): bool { $genre = $this->get_genre_by_slug(); if ($genre && $genre['name'] != "") { $this->id = $genre['id']; $this->enabled = $genre['enabled']; $this->count = $genre['count']; $this->name = $genre['name']; return true; } return false; } private function get_genre_by_slug() { $stmt = $this->db->prepare("SELECT * FROM genres WHERE slug = ?"); $stmt->bind_param("s", $this->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; } }