diff --git a/classes/DressedItems.php b/classes/DressedItems.php index c3fe557..55f793d 100644 --- a/classes/DressedItems.php +++ b/classes/DressedItems.php @@ -8,6 +8,7 @@ class DressedItems { protected $DB; + protected $DBSUM; private $dressedItem; /** @@ -15,36 +16,37 @@ class DressedItems */ public function __construct() {} - private function getDressedItems() - { - try { - $this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->userid); - while ($row = $this->DB->fetch_assoc()) { - $dressed_item[$row['dressed_slot']] = $row; - $this->dressedItem[$row['dressed_slot']] = $row; - } - } catch (Exception $e) { - echo '
getDressedItems: ' . $e . '
'; - } - } - - public function getSlots() - { - return $this->dressedItem; - } - - private function runQuery($user_id) + private function getDressedItems($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 '
getDressedItems: ' . $e . '
'; + echo '
Не прогрузилась таблица inventory (*) для класса DressedItems.
'; } } - public function eeee($user_id) + + private function getBonusesFromDressedItems($user_id) + { + try { + $query = << 0' +SQL; + $this->DBSUM = db::c()->query($query, $user_id)->fetch_assoc(); + } catch (Exception $e) { + echo '
Не прогрузилась таблица inventory (SUM) для класса DressedItems.
'; + } + } + + public function getItemsInSlots($user_id) { if (!$this->DB) { - $this->runQuery($user_id); + $this->getDressedItems($user_id); } while ($row = $this->DB->fetch_assoc()) { $dressed_item[$row['dressed_slot']] = $row; @@ -52,4 +54,12 @@ class DressedItems } } + public function getBonusesAmount($user_id) + { + if (!$this->DBSUM) { + $this->getBonusesFromDressedItems($user_id); + } + return $this->DBSUM; + } + } \ No newline at end of file diff --git a/classes/User.php b/classes/User.php index 7907eb2..432302a 100644 --- a/classes/User.php +++ b/classes/User.php @@ -56,37 +56,18 @@ class User private function UserInfoDoll($isBattle = 0, $isMain = 0) { //https://jsfiddle.net/ngx0yvhc -// $dressed_items = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->id); -// while ($row = $dressed_items->fetch_assoc()) { -// $dressed_item[$row['dressed_slot']] = $row; -// } $di = new DressedItems(); - $di->eeee($this->id); + $dressedItems = $di->getItemsInSlots($this->id); -// for ($i = 1; $i <= 12; $i++) { -// echo sprintf('
', $i); -// if (isset($dressed_item[$i])) { -// if (!$isBattle && $isMain) { -// $itemString = '%s'; -// echo sprintf($itemString, $i, $dressed_item[$i]['image'], $dressed_item[$i]['name'], $dressed_item[$i]['name']); -// } else { -// $itemString = '%s%s'; -// echo sprintf($itemString, $dressed_item[$i]['image'], $dressed_item[$i]['name'], $dressed_item[$i]['name']); -// } -// } else { -// echo sprintf('Пустой слот [%s]', $i, $i); -// } -// echo sprintf('
', $i); -// } for ($i = 1; $i <= 12; $i++) { echo sprintf('
', $i); if (isset($di->eeee($this->id)[$i])) { if (!$isBattle && $isMain) { $itemString = '%s'; - echo sprintf($itemString, $i, $di->eeee($this->id)[$i]['image'], $di->eeee($this->id)[$i]['name'], $di->eeee($this->id)[$i]['name']); + echo sprintf($itemString, $i, $dressedItems[$i]['image'], $dressedItems[$i]['name'], $dressedItems[$i]['name']); } else { $itemString = '%s%s'; - echo sprintf($itemString, $di->eeee($this->id)[$i]['image'], $di->eeee($this->id)[$i]['name'], $di->eeee($this->id)[$i]['name']); + echo sprintf($itemString, $dressedItems[$i]['image'], $dressedItems[$i]['name'], $dressedItems[$i]['name']); } } else { echo sprintf('Пустой слот [%s]', $i, $i);