the problem & context

the problem: Humans are not superior to robots like Taeyong. We must invent these robots to do things more efficiently and counter our human error. Counting trades and stampcards is one of those areas where we're likely to exhibit this human side of ourselves.

the solution: Automatically calculate stampcards earned based on cards traded in your logs. A build on the previous function (but the previous function is not needed)

caveats: Main caveat - this assumes a 20 card stampcard. Since I only play idolise, it works for me. You can edit to make the count different for other tcgs, but I'm not spinning my wheels on it.

This script works by counting "Traded" and commas in your trade log. You cannot have commas in the date format (you can swap out by going to your TCG settings and changing format, and by finding and replacing your existing log). Assumes your trade log is called 'tradelog' in etcg and archive log is called whatever the default is (ttradelogarch i think).

the mod

Add this to your mods.php file

function count_stampcards( $tcg ) {

                        $database = new Database;
                        $sanitize = new Sanitize;
                        $tcg = $sanitize->for_db($tcg);

                        $curlog = $database->get_assoc("SELECT `tradelog` FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
                        $curtradeamount = preg_match_all( "/Traded/", $curlog[tradelog] );
                        $curcommas = preg_match_all( "/,/", $curlog[tradelog] ) / 2;
                        $archlog = $database->get_assoc("SELECT `tradelogarch` FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
                        $archtradeamount = preg_match_all( "/Traded/", $archlog[tradelogarch] );
                        $archcommas = preg_match_all( "/,/", $archlog[tradelogarch] ) / 2;
                        $stampcards = ($curtradeamount + $curcommas + $archtradeamount + $archcommas) / 20;
                        return floor($stampcards);
                }

Add this to where you want to display tradecard count:

stampcard count: <?php echo count_stampcards('idolise'); ?>