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