Priority File Manager

📁 public_html
Base Directory:
/home/ecedu/public_html/new/Models
NameTypeSizeActions
📁 .. Folder -
📄 BasicManager.php File 2087
Edit Download
📄 DB.php File 935
Edit Download
📄 DetailsManager.php File 4312
Edit Download
📄 DeviceAuth.php File 698
Edit Download
📄 Functions.php File 6774
Edit Download
📄 ImageManager.php File 2862
Edit Download
📄 News.php File 13517
Edit Download
📄 NewsModel.php File 9523
Edit Download

View File: ImageManager.php

<?php
require_once   __DIR__ . "/DB.php"; 

class ImageManager
{
    protected $db;

    public function __construct()
    {
        $this->db = DB::instance()->getConnection();
    }
   
    public function getImageByType(int $typeId): ?array
    {
        $sql = "SELECT * FROM dbs_image WHERE type_id = :t";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
        $stmt->execute();
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        return $row ?: null;
    }

    public function updateImageRecord(int $imgId, string $ext, int $userId): bool
    {
        $sql = "UPDATE dbs_image SET img_ext = :ext, user_id = :u WHERE img_id = :id";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(':ext', $ext);
        $stmt->bindValue(':u',   $userId, PDO::PARAM_INT);
        $stmt->bindValue(':id',  $imgId,  PDO::PARAM_INT);
        return $stmt->execute();
    }

    public function insertImageRecord(int $typeId, string $ext, int $userId): int
    {
        $sql = "INSERT INTO dbs_image (type_id, img_ext, user_id) VALUES (:t, :e, :u)";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
        $stmt->bindValue(':e', $ext);
        $stmt->bindValue(':u', $userId, PDO::PARAM_INT);

        if (!$stmt->execute()) {
            return 0;
        }
        return (int)$this->db->lastInsertId();
    }
    public function getAdsByType(int $typeId): ?array
    {
        $sql = "SELECT * FROM dbs_ads WHERE type_id = :t";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
        $stmt->execute();
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        return $row ?: null;
    }

    public function updateAdsRecord(int $imgId, string $url, string $ext, int $userId): bool
    {
        $sql = "UPDATE dbs_ads SET img_url = :url, img_ext = :ext, user_id = :u WHERE img_id = :id";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(':url', $url);
        $stmt->bindValue(':ext', $ext);
        $stmt->bindValue(':u',   $userId, PDO::PARAM_INT);
        $stmt->bindValue(':id',  $imgId,  PDO::PARAM_INT);
        return $stmt->execute();
    }

    public function insertAdsRecord(int $typeId, string $url, string $ext, int $userId): int
    {
        $sql = "INSERT INTO dbs_ads (type_id, img_url, img_ext, user_id) VALUES (:t, :u, :e, :u)";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
        $stmt->bindValue(':u', $url);
        $stmt->bindValue(':e', $ext);
        $stmt->bindValue(':u', $userId, PDO::PARAM_INT);

        if (!$stmt->execute()) {
            return 0;
        }
        return (int)$this->db->lastInsertId();
    }
}