[eTCG] combinemypile

Here's a mod you can use to combine different categories into one pile.

First step : Install

This goes into your func.php, custom function page, or any pages that you will use the function on.
// Combine up to 5 categories into one pile.
// $tcg = the name of the TCG as defined in the database.
// $cata, $catb, $catc, $catd, $cate = the categories you want to combine. a and b are obligatory. 
// $doubles = 1 divide pile into uniques/doubles; 2 shows only unique cards; 3 shows only doubles.

function combinemypile($tcg, $doubles = 0, $cata, $catb, $catc = '', $catd = '', $cate = '') {
$database = new Database;
$sanitize = new Sanitize;
$tcg = $sanitize->for_db($tcg);

$tcginfo = $database->get_assoc("SELECT * FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
$tcgid = $tcginfo['id'];
$cardsurl = $tcginfo['cardsurl'];
$format = $tcginfo['format'];

$cata = $sanitize->for_db($cata); $catb = $sanitize->for_db($catb); $catc = $sanitize->for_db($catc); $catd = $sanitize->for_db($catd); $cate = $sanitize->for_db($cate);
$cardsa = $database->get_assoc("SELECT `cards`, `format` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$cata' LIMIT 1");
$cardsb = $database->get_assoc("SELECT `cards`, `format` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$catb' LIMIT 1");
if($catc === '') { $cardsc = ''; } else { $cardsc = $database->get_assoc("SELECT `cards`, `format` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$catc' LIMIT 1"); $cardsc = $cardsc['cards']; }
if($catd === '') { $cardsd = ''; } else { $cardsd = $database->get_assoc("SELECT `cards`, `format` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$catd' LIMIT 1"); $cardsd = $cardsd['cards']; }
if($cate === '') { $cardse = ''; } else { $cardse = $database->get_assoc("SELECT `cards`, `format` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$cate' LIMIT 1"); $cardse = $cardse['cards']; }
$cards = $cardsa['cards'] . ', ' . $cardsb['cards'] . ', ' . $cardsc . ', ' . $cardsd . ', ' . $cardse;

if ( $cards === ', , , ,' ) { echo '<p class="cards"><em>There are currently no cards under this category.</em></p>'; } else {
$cardsall = explode(', ',$cards);
sort($cardsall);
$cardsall = array_map(trim, $cardsall);			
$cardsuni = array_unique($cardsall);
$cardsdou = array_diff_assoc($cardsall, array_unique($cardsall));
if($doubles == 0) {			
echo '<p class="cards">'; foreach ( $cardsall as $card ) { $card = trim($card); if($card != '') { echo '<img src="'.$cardsurl.''.$card.'.'.$format.'" alt="" title="'.$card.'" /> '; } } echo '</p>';
} else {
if($doubles == 1 || $doubles == 2 ) { echo '<p class="cards">'; foreach ( $cardsuni as $card ) { $card = trim($card); if($card != '') { echo '<img src="'.$cardsurl.''.$card.'.'.$format.'" alt="" title="'.$card.'" /> '; } } echo '</p>'; }
if($doubles == 1 || $doubles == 3 ) { echo '<p class="cards">'; foreach ( $cardsdou as $cardd ) { $cardd = trim($cardd); if($cardd != '') { echo '<img src="'.$cardsurl.''.$cardd.'.'.$format.'" alt="" title="'.$cardd.'" /> '; } } echo '</p>'; }
} } }

Second step : Use it

Place this wherever you want the list to go.
combinemypile($tcg, $doubles, $cata, $catb, $catc, $catd, $cate);
  • Replace $tcg with the TCG you're using it on.
  • Replace $doubles with 1 if you want divide your pile into uniques and doubles, 2 for only unique cards or 3 for only doubles (optional).
  • Replace $cata, $catb, $catc, $catd, $cate with the categories you want to combine. C to E are optional.

Examples

"I've two categories: #-M and N-Z. I want to combine them".
combinemypile('TCG name', '', '#-M', 'N-Z');
"I want them to be divided into uniques and doubles".
combinemypile('TCG name', '1', '#-M', 'N-Z');
"I changed my mind and now I want to show the uniques in one page and the doubles in another one".
combinemypile('TCG name', '2', '#-M', 'N-Z');
echo '<hr />'; /// just to separate the piles
combinemypile('TCG name', '3', '#-M', 'N-Z');
"Oh. I just created a new category for my newest cards (New) and I also want to combine it".
combinemypile('TCG name', '', '#-M', 'N-Z', 'New');
That's all. If you need help or find some mistake, please let me know :D