Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 5m27s
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace DJMixHosting;
|
|
class DJs
|
|
{
|
|
|
|
private $db;
|
|
private $djs = [];
|
|
|
|
public function __construct($db)
|
|
{
|
|
|
|
$this->db = $db;
|
|
if (!$this->load_all_djs()) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
private function load_all_djs(): bool
|
|
{
|
|
$djs = $this->get_all_djs();
|
|
if ($djs) {
|
|
$this->djs = $djs;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function get_all_djs($order = "ASC")
|
|
{
|
|
$stmt = $this->db->prepare("SELECT * FROM djs ORDER BY name $order");
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$djs = $result->fetch_all(MYSQLI_ASSOC);
|
|
$stmt->close();
|
|
return $djs;
|
|
}
|
|
|
|
public function get_nonzero_djs($order = "ASC")
|
|
{
|
|
$stmt = $this->db->prepare("SELECT * FROM djs WHERE count > 0 ORDER BY name $order");
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$djs = $result->fetch_all(MYSQLI_ASSOC);
|
|
$stmt->close();
|
|
return $djs;
|
|
}
|
|
|
|
public function search(string $query, int $page = 1, int $resultsPerPage = 10): array {
|
|
$offset = ($page - 1) * $resultsPerPage;
|
|
$likeQuery = "%" . $query . "%";
|
|
$stmt = $this->db->prepare("SELECT * FROM djs WHERE name LIKE ? OR bio LIKE ? LIMIT ?, ?");
|
|
$stmt->bind_param("ssii", $likeQuery, $likeQuery, $offset, $resultsPerPage);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$djs = $result->fetch_all(MYSQLI_ASSOC);
|
|
$stmt->close();
|
|
return $djs;
|
|
}
|
|
|
|
|
|
}
|