| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Models;
- class OrderbookModel
- {
- private \PDO $pdo;
- public function __construct()
- {
- if (isset($GLOBALS['pdo']) && $GLOBALS['pdo'] instanceof \PDO) {
- $this->pdo = $GLOBALS['pdo'];
- return;
- }
- throw new \RuntimeException('Global PDO connection not initialized');
- }
- /**
- * @param array{
- * orderbook_flag:string,
- * orderbook_ts:int,
- * orderbook_is_token:bool,
- * orderbook_amount:string,
- * status_id:int,
- * user_id:int,
- * wallet_id:int,
- * token_id:int,
- * currency_id:?int,
- * chain_id:int
- * } $data
- */
- public function create(array $data): array
- {
- $stmt = $this->pdo->prepare(
- 'INSERT INTO "orderbook" (
- orderbook_flag,
- orderbook_ts,
- orderbook_is_token,
- orderbook_amount,
- status_id,
- user_id,
- wallet_id,
- token_id,
- currency_id,
- chain_id
- ) VALUES (
- :orderbook_flag,
- :orderbook_ts,
- :orderbook_is_token,
- :orderbook_amount,
- :status_id,
- :user_id,
- :wallet_id,
- :token_id,
- :currency_id,
- :chain_id
- ) RETURNING orderbook_id'
- );
- $stmt->execute([
- 'orderbook_flag' => $data['orderbook_flag'],
- 'orderbook_ts' => $data['orderbook_ts'],
- 'orderbook_is_token' => $data['orderbook_is_token'],
- 'orderbook_amount' => $data['orderbook_amount'],
- 'status_id' => $data['status_id'],
- 'user_id' => $data['user_id'],
- 'wallet_id' => $data['wallet_id'],
- 'token_id' => $data['token_id'],
- 'currency_id' => $data['currency_id'],
- 'chain_id' => $data['chain_id'],
- ]);
- $orderbookId = (int)$stmt->fetchColumn();
- return [
- 'orderbook_id' => $orderbookId,
- 'orderbook_ts' => $data['orderbook_ts'],
- ];
- }
- }
|