dev #41

Merged
lopar merged 29 commits from dev into master 2021-05-25 15:28:14 +00:00
4 changed files with 27 additions and 20 deletions
Showing only changes of commit 279422ee9e - Show all commits

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]);
}
}

View File

@ -49,9 +49,17 @@ abstract class Item
*/
public function __construct($row)
{
foreach ($this as $key => $value) {
if (isset($row[$key])) {
$this->$key = $row[$key];
if (is_array($row)) {
foreach ($this as $key => $value) {
if (isset($row[$key])) {
$this->$key = $row[$key];
}
}
} elseif (is_object($row)) {
foreach ($this as $name => $value) {
if (isset($row->$name)) {
$this->$name = $row->$name;
}
}
}

View File

@ -25,13 +25,13 @@ class UserInfo extends User
$dressedItems = $di->getItemsInSlots();
for ($i = 1; $i <= 12; $i++) {
echo sprintf('<div class="slot-%s">', $i);
if (!empty($dressedItems[$i])) {
if (!empty($dressedItems->$i)) {
if (!$isBattle && $isMain) {
$itemString = '<a href="?edit=%s&drop=%s"><img src="/i/sh/%s" class="item-wrap-normal" alt="%s" title="%s"></a>';
echo sprintf($itemString, mt_rand(), $i, $dressedItems[$i]['image'], $dressedItems[$i]['name'], $dressedItems[$i]['name']);
echo sprintf('<a href="?edit=%s&drop=%s"><img src="/i/sh/%s" class="item-wrap-normal" alt="%s" title="%s"></a>',
mt_rand(), $i, $dressedItems->$i->image, $dressedItems->$i->name, $dressedItems->$i->name);
} else {
$itemString = '<img src="/i/sh/%s" class="item-wrap-normal tip" alt="%s"><span class="tiptext"><strong>%s</strong></span>';
echo sprintf($itemString, $dressedItems[$i]['image'], $dressedItems[$i]['name'], $dressedItems[$i]['name']);
echo sprintf('<img src="/i/sh/%s" class="item-wrap-normal tip" alt="%s"><span class="tiptext"><strong>%s</strong></span>',
$dressedItems->$i->image, $dressedItems->$i->name, $dressedItems->$i->name);
}
} else {
echo sprintf('<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [%s]" alt="Пустой слот [%s]">', $i, $i);

View File

@ -36,10 +36,9 @@ $edit = $_GET['edit'] ?? null;
// Подготавливаем отображение инфы и предметов.
$userInfo = new UserInfo($user->getId());
$getItemsBonuses = new DressedItems($_SESSION['uid']);
$data_query = 'SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot = 0 AND on_sale = 0';
$data = db::c()->query($data_query, $_SESSION['uid']);
$data = \Battles\Database\DBPDO::INIT()->ofetchAll('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = 0 AND on_sale = 0', $user->getId());
$iteminfo = [];
while ($row = $data->fetch_assoc()) {
foreach ($data as $row) {
$iteminfo[] = new InventoryItem($row);
}
@ -456,8 +455,8 @@ Template::header('Игра');
echo "<td valign='top' bgcolor='#d3d3d3'>";
$ii->printInfo();
}
if ($data->getNumRows() == 0) {
echo "<tr><th colspan='3' align=center bgcolor=#C7C7C7>Пусто";
if (!$data) {
echo "<tr><th colspan='3' style='text-align: center; background-color: #c7c7c7'>Пусто";
}
?>
</table>