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 count cards traded. Completely optional. Not necessary. You still need to separate out logs to submit stampcards.

caveats: 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 yoru 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

  1. BACK. UP. YOUR. LOGS. You may be messing with your logs to ensure formatting, or re-count later after realizing you counted wrong. BACK UP YOUR LOGS REGULARLY.
  2. Ensure your dates do NOT have commas. Repeating this for the people in the back.
  3. Add this to your mods.php file:
function count_logs( $tcg, $type ) { // function to count the cards traded

                  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] ); // counts amount of trades as denoted by the Traded portion of the log
                    $commas = preg_match_all( "/,/", $log[$type] ) / 2; // counts commas and divides by two to account for multi-card trades
                    return $tradeamount + $commas; // adds, which I can't do because I can't read
                  }
                  else {
                    return false;
                  }

                }
  1. Put this where you want to display cards traded:
cards traded: <?php echo count_logs('TCGNAMEHERE','tradelog'); ?>