mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-30 20:22:23 +00:00
152 lines
2.8 KiB
PHP
152 lines
2.8 KiB
PHP
<?php
|
|
|
|
class Payment
|
|
{
|
|
private $id;
|
|
private $user_id;
|
|
private $tournament_id;
|
|
private $amount;
|
|
private $method;
|
|
private $transaction_infos;
|
|
private $validation_status;
|
|
|
|
private function __construct() {}
|
|
|
|
public static function fromId($id)
|
|
{
|
|
global $DB;
|
|
$req = $DB->prepare("SELECT * FROM `payments` WHERE `id` = ?;");
|
|
$req->execute([htmlspecialchars($id)]);
|
|
$data = $req->fetch();
|
|
|
|
if ($data === false)
|
|
return null;
|
|
|
|
$payment = new Payment();
|
|
$payment->fill($data);
|
|
return $payment;
|
|
}
|
|
|
|
private function fill($data)
|
|
{
|
|
$this->id = $data["id"];
|
|
$this->user_id = $data["user"];
|
|
$this->tournament_id = $data["tournament"];
|
|
$this->amount = $data["amount"];
|
|
$this->method = PaymentMethod::fromName($data["method"]);
|
|
$this->transaction_infos = $data["transaction_infos"];
|
|
$this->validation_status = ValidationStatus::fromName($data["validation_status"]);
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getAmount()
|
|
{
|
|
return $this->amount;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $amount
|
|
*/
|
|
public function setAmount($amount)
|
|
{
|
|
global $DB;
|
|
$this->amount = $amount;
|
|
$DB->prepare("UPDATE `payments` SET `amount` = ? WHERE `id` = ?;")->execute([$amount, $this->id]);
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getMethod()
|
|
{
|
|
return $this->method;
|
|
}
|
|
|
|
/**
|
|
* @param int $method
|
|
*/
|
|
public function setMethod($method)
|
|
{
|
|
global $DB;
|
|
$this->method = $method;
|
|
$DB->prepare("UPDATE `payments` SET `method` = ? WHERE `id` = ?;")->execute([PaymentMethod::getName($method), $this->id]);
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getTournamentId()
|
|
{
|
|
return $this->tournament_id;
|
|
}
|
|
|
|
/**
|
|
* @return Tournament|null
|
|
*/
|
|
public function getTournament()
|
|
{
|
|
return Tournament::fromId($this->getTournamentId());
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getUserId()
|
|
{
|
|
return $this->user_id;
|
|
}
|
|
|
|
/**
|
|
* @return User|null
|
|
*/
|
|
public function getUser()
|
|
{
|
|
return User::fromId($this->getUserId());
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getTransactionInfos()
|
|
{
|
|
return $this->transaction_infos;
|
|
}
|
|
|
|
/**
|
|
* @param string $transaction_infos
|
|
*/
|
|
public function setTransactionInfos($transaction_infos)
|
|
{
|
|
global $DB;
|
|
$this->transaction_infos = $transaction_infos;
|
|
$DB->prepare("UPDATE `payments` SET `transaction_infos` = ? WHERE `id` = ?;")->execute([$transaction_infos, $this->id]);
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getValidationStatus()
|
|
{
|
|
return $this->validation_status;
|
|
}
|
|
|
|
/**
|
|
* @param int $validation_status
|
|
*/
|
|
public function setValidationStatus($validation_status)
|
|
{
|
|
global $DB;
|
|
$this->validation_status = $validation_status;
|
|
$DB->prepare("UPDATE `payments` SET `validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::getName($validation_status), $this->id]);
|
|
}
|
|
} |