Something im wokring on as this seems to be a busy feature to our surprise. Faithful seeders.

So it feels necessary to develop a class just for this. This is under development and is only displayed here for ongoing-reference toward the final code.


<?
interface Store
{
   public function checkbonus($user_id);
   public function rowtype(int $user_id, array $data);
   public function retrieveitems($res);
   public function updateuser($user_id);
}
class DB
{
   public $pdo;
   public function __construct()
   {
       $dsn = "mysql:host=$host;dbname=$db;port=$port;charset=utf8mb4";
       try {
           $this->pdo = new PDO($dsn, $username, $password, $options);
       }
       catch (PDOException $e) {
           $this->log_exception($e->getMessage(), $e->getLine());
       }
   }
   private function log_exception($msg, $line)
   {
       $query = "INSERT INTO sql_logging(exception, added) VALUES(?, NOW())";
       $stt   = $this->pdo->prepare($query);
       $stt->bindValue(1, $msg . $line);
       $stt->execute();
   }
   public function preprocess($query, $get_id)
   {
       return $query;
   }
   public function write_log($text)
   {
       $this->query_params('INSERT INTO log (added, txt) VALUES(NOW(), :log)', array(
           'log' => $text
       ));
   }
   public function interval($s)
   {
       return sprintf("INTERVAL '%s'", $s);
   }
   public function query_params($query, $params = null, $get_id = null)
   {
       if (is_null($params)) {
           $params = array();
       }
       try {
           $query = $this->preprocess($query, $get_id);
           $stmt  = $this->pdo->prepare($query);
           foreach ($params as $key => $param) {
               if ($key == "data") {
                   $stmt->bindValue(':' . $key, $param, PDO::PARAM_LOB);
               } else if ($key == "limit") {
                   $stmt->bindValue(':' . $key, (int) trim($param), PDO::PARAM_INT);
               } else {
                   $stmt->bindValue(':' . $key, $param);
               }
           }
           $stmt->execute();
           $stmt->setFetchMode(PDO::FETCH_ASSOC);
           if (is_null($get_id)) {
               return $stmt;
           } else {
               return $this->get_last_id($stmt, $get_id);
           }
       }
       catch (PDOException $e) {
           $this->log_exception($e->getMessage(), $e->getLine());
       }
   }
}
class Seedbonus extends DB implements Store
{
   public function __construct($db = 'database', $username = 'username', $password = 'password', $host = 'localhost', $port = 3306, $options = [])
   {
       $this->invite        = true;
       $this->traffic       = true;
       $this->hnr           = true;
       $this->slots         = true;
       $this->vip           = true;
       $this->last_exchange = true;
       $this->value         = true;
       $this->feature       = true;
   }
   public function checkbonus($user_id)
   {
       $points = $this->query_params('SELECT users.seedbonus, users.username, users.class, users.user_id, bonus.cost, bonus.descr, bonus.type, bonus.value FROM users, bonus WHERE users.user_id = :user_id', array(
           'user_id' => $user_id
       )) or die('db error');
       while ($check = $points->fetch()) {
           $pointsuser    = $check['user_id'];
           $currentpoints = $check['seedbonus'];
           if ($currentpoints) {
               return true;
           }
       }
       return false;
   }
   public function retrieveitems($res)
   {
       $res = $this->query_params('SELECT * FROM bonus ORDER BY type');
   }
   public function rowtype(int $user_id, array $data)
   {
       $this->query_params('SELECT users.seedbonus, users.perk_avatar, users.username, users.slots, users.last_exchange, users.class, users.user_id, bonus.cost, bonus.descr, bonus.type, bonus.value, bonus.id FROM users, bonus WHERE users.user_id = :user_id AND bonus.id = :post_id', array(
           'user_id' => $user_id,
           'post_id' => $data['id']
       ));
       return $row = $res->fetch();
       if ($row['type'] == $this->invite && $data['id'] == $row['id']) {
           $this->query_params('UPDATE users SET invites = invites + :value WHERE user_id = :user_id', array(
               'value' => $row['value'],
               'user_id' => $user_id
           ));
           return sprintf('Your account has been <b>credited</b> for <b>%s</b> Extra Invites!', $row['value']);
       }
   }
   public function updateuser($user_id)
   {
       $res = $this->query_params('SELECT users.seedbonus, users.perk_avatar, users.username, users.slots, users.last_exchange, users.class, users.user_id, bonus.cost, bonus.descr, bonus.type, bonus.value, bonus.id FROM users, bonus WHERE users.user_id = :user_id AND bonus.id = :post_id', array(
           'user_id' => $user_id,
           'post_id' => $data['id']
       ));
       $row = $res->fetch();
       $this->query_params('UPDATE users SET seedbonus = seedbonus - :cost WHERE user_id = :user_id', array(
           'cost' => $row['cost'],
           'user_id' => $user_id
       ));
   }
}


@m-jay - Disable smilies/bbcode for code frame.
Last edited by STorrents2020 on 2021-03-06 06:32:38