function fetchTransactions($apikey, $vcode, $refID, $idcharacter, $con) { $pheal4 = new Pheal($apikey, $vcode, "char", $refID); $wallet_response = $pheal4->WalletTransactions(array("characterID" => $idcharacter)); if ($refID != 0) { $wallet_response = $pheal4->WalletTransactions(array("fromID" => $refID)); } $i = -1; //get the Eve transaction ID for the latest transaction (this might need some tweaking when they decide to recycle ids) $getLatestTransaction = utils::mysqli_result(mysqli_query($con, "SELECT MAX(transkey) AS val FROM transaction WHERE character_eve_idcharacter = '{$idcharacter}'"), 0, 0); //var_dump($getLatestTransaction); if (!isset($getLatestTransaction)) { $latestTransaction = 0; } else { $latestTransaction = $getLatestTransaction; } // var_dump($latestTransaction); $arrayfinal = array(); $array_refs = array(); $null = (string) "NULL"; foreach ($wallet_response->transactions as $row2) { $transkey = $row2->transactionID; $typeid = $row2->typeID; $dateTime = $row2->transactionDateTime; $quantity = $row2->quantity; $price_unit = $row2->price; $transactionType = $row2->transactionType; $station = $row2->stationName; $price_total = $price_unit * $quantity; $station_id = $row2->stationID; $clientName = $row2->clientName; array_push($array_refs, $transkey); if ($transkey > $latestTransaction) { $i++; $item[$i] = array("{$null}", "'" . $dateTime . "'", "'" . $quantity . "'", "'" . $price_unit . "'", "'" . $price_total . "'", "'" . $transactionType . "'", "'" . $idcharacter . "'", "'" . $station_id . "'", "'" . $typeid . "'", "'" . $transkey . "'", "'" . str_replace("'", ".", $clientName) . "'"); } } for ($j = 0; $j <= $i; $j++) { $arrayfinal[$j] = $item[$j]; } $values_transactions = array(); foreach ($arrayfinal as $rowValues) { foreach ($rowValues as $key => $rowValue) { $rowValues[$key] = $rowValues[$key]; } //this array contains all transactions in this format: (x,y,z),(a,b,c),... $values_transactions[] = "(" . implode(', ', $rowValues) . ")"; } if (!empty($values_transactions)) { //var_dump($values); $query_insert = "INSERT IGNORE INTO `trader`.`transaction` (`idbuy`, `time`, `quantity`, `price_unit`, `price_total`, `transaction_type`, `character_eve_idcharacter`, `station_eve_idstation`, `item_eve_iditem`, `transkey`, `client`) " . "VALUES " . implode(', ', $values_transactions); $insert_transactions = mysqli_query($con, $query_insert) or die(mysqli_error($con)); return $newTransactions = mysqli_affected_rows($con); if (count($array_refs) == 2560) { $refID = end($array_refs); fetchTransactions($apikey, $vcode, $refID, $idcharacter, $con); } } else { return $newTransactions = 0; $insert_transactions = False; } }
} if (!empty($corpStandingsArray)) { $update_standings_corp = mysqli_query($con, "INSERT IGNORE INTO `trader`.`standings_corporation` \n (`idstandings_corporation`, \n `characters_eve_idcharacters`, \n `corporation_eve_idcorporation`, \n `value`) \n VALUES" . implode(', ', $corpStandingsArray)) or die(mysqli_error($con)); } $factionStandingsArray = array(); foreach ($result3->characterNPCStandings->factions as $factionStandings) { //$standing = $factionStandings->standing; //$factionStandingsArray[$standing] = $factionStandings->fromID; $factionStandingsArray[] = "(NULL," . $idcharacter . "," . $factionStandings->fromID . "," . $factionStandings->standing . ")"; } if (!empty($factionStandingsArray)) { $update_standings_faction = mysqli_query($con, "INSERT IGNORE INTO `trader`.`standings_faction` \n (`idstandings_faction`, \n `characters_eve_idcharacters`, \n `faction_eve_idfaction`, \n `value`) \n VALUES" . implode(', ', $factionStandingsArray)) or die(mysqli_error($con)); } //Update ALL transactions for each character $pheal4 = new Pheal($apikey, $vcode, "char"); $wallet_response = $pheal4->WalletTransactions(array("characterID" => $idcharacter)); $i = -1; $null = (string) "NULL"; foreach ($wallet_response->transactions as $row2) { $i++; $typeid = $row2->typeID; $dateTime = $row2->transactionDateTime; $quantity = $row2->quantity; $price_unit = $row2->price; $transactionType = $row2->transactionType; $station = $row2->stationName; $price_total = $price_unit * $quantity; $station_id = $row2->stationID; $transkey = $row2->transactionID; $clientName = $row2->clientName; $item[$i] = array("{$null}", "'" . $dateTime . "'", "'" . $quantity . "'", "'" . $price_unit . "'", "'" . $price_total . "'", "'" . $transactionType . "'", "'" . $idcharacter . "'", "'" . $station_id . "'", "'" . $typeid . "'", "'" . $transkey . "'", "'" . str_replace("'", ".", $clientName) . "'");