$senderId, 'receiverId' => $receiverId, 'amount' => $amount, 'type' => $type, 'text' => $text, ]), self::BANK, ); } /** * Добавление записи в лог пользовательских операций (личное дело). * @param int $userId кому добавляется запись. * @param string $text текст записи. * @param string $type тип записи. * @param int $authorId кто добавляет запись. Использовать -1 для системной записи по умолчанию. */ public static function addUserLog(int $userId, string $text, string $type = '', int $authorId = 0) { if (empty($authorId)) { $authorId = -1; } if (empty($type)) { $type = "system"; } self::addLog( json_encode([ 'userId' => $userId, 'authotId' => $authorId, 'type' => $type, 'text' => $text, ]), self::USER_ACTIONS, ); } private static function addLog($jsonString, $logType) { Db::getInstance()->execute('insert into logs (json_data, type) VALUES (?,?)', [ $jsonString, $logType ]); } private static function getLogByType(int $type): array { $result = []; $logs = Db::getInstance()->fetchAll('select json_data from logs where type = ?', $type); foreach ($logs as $log) { $result[] = json_decode($log, true); } return $result; } public static function getUserLogs(?int $userId): array { $logs = self::getLogByType(self::USER_ACTIONS); if (is_null($userId)) { return $logs; } $result = []; foreach ($logs as $log) { if ($userId !== $log['userId']) { continue; } $result[] = $log; } return $result; } public static function addBattleLog(int $battleId, string $text) { self::addLog( json_encode([ 'battleId' => $battleId, 'text' => $text, ]), self::BATTLE, ); } }