the problem & context

the problem: Sometimes you want to see how many trades you need until the next stampcard. Why would you count manually?

the solution: You can see how many trades you've made out of 20 toward your next stampcard. 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.

Same caveats as above as well - 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. Cannot be using archived logs (you can edit this to work around that).

the mod

Add this to your mods.php file

function next_stampcard( $tcg, $type ) {

                  if ( $type == 'activitylog' || $type == 'activitylogarch' || $type == 'tradelog' || $type == 'tradelogarch' ) {
                    $database = new Database;
                    $sanitize = new Sanitize;
                    $tcg = $sanitize->for_db($tcg);

                    $log = $database->get_assoc("SELECT `$type` FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
                    $tradeamount = preg_match_all( "/Traded/", $log[$type] );
                    $commas = preg_match_all( "/,/", $log[$type] ) / 2;
                    $tradetotal = $tradeamount + $commas;
                    $needed = ($tradetotal % 20)."\\n"; // gives remainder of dividing total trades by 20
                    return $needed;
                  }
                  else {
                    return false;
                  }

                }

Add this to where you want to display tradecard count:

trades filled for next stampcard: <?php echo next_stampcard('idolise','tradelog'); ?>/20