38751-vm/app/Services/ApkService.php
Flatlogic Bot a887a75aed Aslam
2026-02-24 22:20:46 +00:00

38 lines
1.1 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 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'
]);
}
}