Рефакторинг, очистка, работа над ошибками, связанными с базой, отказ от глобальной переменной $user во многих файлах.

Singleton в некоторых местах вместо решения #42.
Новые шаги для решения #16 и #52.
Closes #42.
Closes #32.
Closes #31.
This commit is contained in:
Igor Barkov (iwork)
2022-01-27 01:15:33 +02:00
parent b1ba212c8c
commit 3502904656
82 changed files with 1575 additions and 2015 deletions
+13 -8
View File
@@ -2,29 +2,34 @@
# Date: 29.08.2021 (21:34)
namespace Battles;
use Battles\Database\DBPDO;
use Battles\Database\Db;
class Shop
{
public const GENERAL_SHOP = 1;
public const BARTER_SHOP = 2;
public const CATEGORY_SALE_ITEMS = -1;
public static Shop $current;
public int $categoryType = 0;
private int $shopId;
public function __construct($shop_id) {
private function __construct($shop_id)
{
$this->shopId = $shop_id;
}
public static function id($shopid): self
{
return new self($shopid);
}
private function showGoods(): string
{
if ($this->categoryType) {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0 and item_type = ?', [$this->shopId, $this->categoryType]);
$stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null and item_type = ?', $this->categoryType);
$stmt = Db::getInstance()->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0 and item_type = ?', [$this->shopId, $this->categoryType]);
$stmt2 = Db::getInstance()->ofetchAll('select * from inventory where on_sale != 0 and present is null and item_type = ?', $this->categoryType);
} else {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0', $this->shopId);
$stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null');
$stmt = Db::getInstance()->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0', $this->shopId);
$stmt2 = Db::getInstance()->ofetchAll('select * from inventory where on_sale != 0 and present is null');
}
$iteminfo = [];
@@ -39,7 +44,7 @@ class Shop
private function showUserSellItems(): string
{
$stmt = DBPDO::$db->ofetchall('select * from inventory where on_sale = 0 and dressed_slot = 0 and durability > 0 and owner_id = ?', User::$current->getId());
$stmt = Db::getInstance()->ofetchall('select * from inventory where on_sale = 0 and dressed_slot = 0 and durability > 0 and owner_id = ?', User::getInstance()->getId());
$iteminfo = [];
$operationType = 'sellshop';