Отображение предметов через stdClass вместо массивов.

This commit is contained in:
lopar
2021-03-10 23:20:56 +02:00
parent 9046670081
commit 279422ee9e
4 changed files with 27 additions and 20 deletions
+7 -7
View File
@@ -27,16 +27,16 @@ class DressedItems
public static function getDressedItemBySlot($itemSlot, $ownerId)
{
return self::$db->fetch('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
return self::$db->fetch('SELECT *, COUNT(1) AS count FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
}
public function getItemsInSlots()
public function getItemsInSlots(): \stdClass
{
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
$i = 0;
while ($i < count($items)) {
$this->dressedItem[$items[$i]->dressed_slot] = $items;
$i++;
$this->dressedItem = new \stdClass();
foreach ($items as $item) {
$i = $item->dressed_slot;
$this->dressedItem->$i = $item;
}
return $this->dressedItem;
}
@@ -123,7 +123,7 @@ SQL;
{
self::getItemsInSlots();
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem[$slot_id]) {
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem->$slot_id) {
self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$slot_id, $this->USERID]);
}
}