49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
require_once __DIR__ . '/../../db/config.php';
|
|
|
|
class ApkService {
|
|
protected $db;
|
|
|
|
public function __construct() {
|
|
$this->db = db();
|
|
}
|
|
|
|
public function getLatest($limit = 10) {
|
|
$stmt = $this->db->prepare("SELECT * FROM apks WHERE status = 'published' ORDER BY created_at DESC LIMIT :limit");
|
|
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
public function getBySlug($slug) {
|
|
$stmt = $this->db->prepare("SELECT * FROM apks WHERE slug = :slug AND status = 'published' LIMIT 1");
|
|
$stmt->execute(['slug' => $slug]);
|
|
return $stmt->fetch();
|
|
}
|
|
|
|
public function getAllApks() {
|
|
$stmt = $this->db->prepare("SELECT * FROM apks ORDER BY created_at DESC");
|
|
$stmt->execute();
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
public function getApkById($id) {
|
|
$stmt = $this->db->prepare("SELECT * FROM apks WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
return $stmt->fetch();
|
|
}
|
|
|
|
public function incrementDownload($apkId) {
|
|
$stmt = $this->db->prepare("UPDATE apks SET total_downloads = total_downloads + 1 WHERE id = :id");
|
|
$stmt->execute(['id' => $apkId]);
|
|
|
|
$stmt = $this->db->prepare("INSERT INTO downloads (apk_id, ip_address) VALUES (:apk_id, :ip)");
|
|
$stmt->execute([
|
|
'apk_id' => $apkId,
|
|
'ip' => $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0'
|
|
]);
|
|
}
|
|
} |