From 321a332612f5b37be4aba999677ee6ed6e10b545 Mon Sep 17 00:00:00 2001 From: lopar Date: Mon, 6 Jul 2020 23:34:34 +0300 Subject: [PATCH] tests --- classes/DressedItems.php | 23 ++++++++++++++--------- classes/User.php | 15 +++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/classes/DressedItems.php b/classes/DressedItems.php index ff247bc..59dc43a 100644 --- a/classes/DressedItems.php +++ b/classes/DressedItems.php @@ -10,18 +10,23 @@ class DressedItems protected $DB; private $dressedItem; - public function __construct(int $user_id) - { - try { - $this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $user_id); - } catch (Exception $e) { - echo '
' . $e . '
'; - } + public function __construct() { + // Пустой потому что нужны разные запросы. } - public function getDressedItems() + private function getDressedItems($user_id) { - while ($row = $this->DB->fetch_assoc()) { + try { + return db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $user_id); + } catch (Exception $e) { + echo '
getDressedItems: ' . $e . '
'; + } + return null; + } + + public function getSlots($user_id) + { + while ($row = $this->getDressedItems($user_id)->fetch_assoc()) { $dressed_item[$row['dressed_slot']] = $row; $this->dressedItem[$row['dressed_slot']] = $row; } diff --git a/classes/User.php b/classes/User.php index b5d8f75..c62966e 100644 --- a/classes/User.php +++ b/classes/User.php @@ -46,11 +46,6 @@ class User } } - private function getDressedItems() - { - - } - /** * Отображает куклу персонажа (образ и слоты). * @param int $isBattle - установить 1, если куклу нужно отобразить в поединке (показывает параметры при наведении на образ). @@ -65,8 +60,8 @@ class User while ($row = $dressed_items->fetch_assoc()) { $dressed_item[$row['dressed_slot']] = $row; } - $di = new DressedItems($this->id); - $di->getDressedItems(); + $di = new DressedItems(); + $di->getSlots($this->id); // for ($i = 1; $i <= 12; $i++) { // echo sprintf('
', $i); // if (isset($dressed_item[$i])) { @@ -84,13 +79,13 @@ class User // } for ($i = 1; $i <= 12; $i++) { echo sprintf('
', $i); - if (isset($di->getDressedItems()[$i])) { + if (isset($di->getSlots()[$i])) { if (!$isBattle && $isMain) { $itemString = '%s'; - echo sprintf($itemString, $i, $di->getDressedItems()[$i]['image'], $di->getDressedItems()[$i]['name'], $di->getDressedItems()[$i]['name']); + echo sprintf($itemString, $i, $di->getSlots()[$i]['image'], $di->getSlots()[$i]['name'], $di->getSlots()[$i]['name']); } else { $itemString = '%s%s'; - echo sprintf($itemString, $di->getDressedItems()[$i]['image'], $di->getDressedItems()[$i]['name'], $di->getDressedItems()[$i]['name']); + echo sprintf($itemString, $di->getSlots()[$i]['image'], $di->getSlots()[$i]['name'], $di->getSlots()[$i]['name']); } } else { echo sprintf('Пустой слот [%s]', $i, $i);