-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardsort_cat.php
288 lines (230 loc) · 7.55 KB
/
cardsort_cat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
define('VALID_INC', TRUE); include_once 'func.php';
/*
==============================================
Card Sort via category
by Muffy
==============================================
Sorts cards for you.
Place cards into the "sortme" category, then refresh the page for all of these cards to be sorted for you :3
One day this will allow the log input that the idolise cardsort does.
(the coding of that confused me, so i coded my own)
-------------
HOW TO USE:
-------------
1. Place this file in the same folder as your TCG.
2. Create a category in eTCG called "sortme" (or whatever you prefer, you can change this in config below)
- with a cardworth of 0
- no autoupload
3. While you're proccessing your logs, put cards you want to sort into this category.
4. Refresh this page, and the cards will be sorted into categories for you.
5. Once your sorting is complete, pull all your cards out of the sortme category.
6. Rinse and Repeat!
This is easier to me, that way i process my cards while logging them all
Unfortunately this doesn't allow for external input, or checks for EXACT cards, just what decks are where.
-------------
Func Calls
-------------
NOTE: This is it's own standalone page, reading database info from your func.php.
Make sure none of the function calls interact with any of your mods.
grabCats()
callCollect()
catCards()
deckArray()
cardArray()
replaceNumber()
==============================================
CONFIG
============================================== */
// name of the TCG you're working with
$workTCG = "tcgnamehere";
// name of the Sorting category, default "sortme"
$mySortCat = "sortme";
/* ==============================================
Do not touch anything below
lest you know what youre doing.
============================================== */
$workArray = array();
$inputArrays = array();
function grabCats( $tcg ) {
// grabs categories from the database
$holdCats = array(); //categories
$database = new Database;
$sanitize = new Sanitize;
$tcg = $sanitize->for_db($tcg);
$result = $database->get_assoc("SELECT `id` FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
$tcgid = $result['id'];
$counter = 1;
// grabs each category name from the database
while ($counter > 0) {
$result = $database->get_assoc("SELECT * FROM `cards` WHERE `tcg`='$tcgid' AND `id`='$counter' ");
$pushMe = $result['category'];
// if the name is empty, dont push
if($pushMe == "") {
// check next value
$checkIt = $counter + 1;
$wonder = $database->get_assoc("SELECT * FROM `cards` WHERE `tcg`='$tcgid' AND `id`='$checkIt' ");
$wonder = $wonder['category'];
// if THAT's empty, break
if($wonder == "") {
unset( $wonder, $pushMe, $result );
break;
}
} else {
// push otherwise
array_push($holdCats, $pushMe);
}
$counter++;
}
// get cats :3
return $holdCats;
}
// grab cards from collecting
function callCollect( $tcg ) {
$database = new Database;
$sanitize = new Sanitize;
$tcg = $sanitize->for_db($tcg);
$result = $database->get_assoc("SELECT `id` FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
$tcgid = $result['id'];
$result = $database->query("SELECT * FROM `collecting` WHERE `tcg` = '$tcgid' AND `mastered` = '0' ORDER BY `sort`, `deck`");
$cards = '';
while ($row = mysqli_fetch_assoc($result)) {
$current = explode(', ', $row[cards]);
if($row['count'] == count($current)){
}
else {
$cards .= $row['cards'] . ', ';
$total[$row['deck']] = $row['count'];
}
}
return $cards;
}
// grab cards from categories
function catCards( $tcg, $category, $worth = '') {
$database = new Database;
$sanitize = new Sanitize;
$tcg = $sanitize->for_db($tcg);
$category = $sanitize->for_db($category);
$result = $database->get_assoc("SELECT `id` FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
$tcgid = $result['id'];
$result = $database->get_assoc("SELECT `cards` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$category' LIMIT 1");
return $result['cards'];
}
// make a deck array
function deckArray ( string $inputCards ) {
$exportArray = array();
// explode each card
$inputArray = explode(', ', $inputCards );
// remove duplicates
$inputArray = array_values(array_unique($inputArray));
//push to return array
foreach ( $inputArray as &$value ) {
array_push($exportArray, $value);
}
// unset foreach
unset( $value );
// return!
return $exportArray;
}
// make a card array
function cardArray ( string $inputCards ) {
$exportArrayTwo = array();
// explode each card
$exportArrayTwo = explode(', ', $inputCards );
// return!
return $exportArrayTwo;
}
function replaceNumber( string $fixMe ) {
// replaces numbers in a string uwu
$result = "";
$result = preg_replace('/[0-9]+/', '', $fixMe);
return $result;
}
echo "<h2>Card Sort from the sortme Category</h2>";
// grab your input
$inputCards = catCards( $workTCG, $mySortCat );
echo "<p>Your input: " . $inputCards ."</p>";
$sayArray = cardArray($inputCards);
// grab your decks
$inputCardsTwo = replaceNumber($inputCards);
$sayArrayCheck = deckArray($inputCardsTwo);
// grab collecting
$colCards = callCollect( $workTCG );
$colCards = replaceNumber($colCards);
$colArray = deckArray($colCards);
// start your excludes
$excludeCol = array();
$excludeMe = array();
// check if your decks are found in collectiong
$foundArray = array_intersect( $colArray, $sayArrayCheck);
if(count($foundArray) > 0) {
echo "<p><h3>Collecting</h3>";
foreach ( $foundArray as $decksToFind) {
// dig thru the found array
foreach( $sayArray as $cardsToFind) {
// dig thru the input array
if( strpos($cardsToFind, $decksToFind ) !== false && $decksToFind !== "") {
// if found, print!
echo $cardsToFind . ", ";
// push cards we've found to remove from leftovers
array_push ($excludeCol, $cardsToFind);
// push cards we've found to remove for extras
array_push ($excludeMe, $cardsToFind);
}
}
}
echo "</p>";
}
// unset foreach
unset($cardsToFind, $decksToFind);
// lets grab our leftovers
$leftoverArray = array_diff( $sayArray, $excludeCol );
// create a new deckcheck array
$leftoverArrayCheckCards = implode(", ", $leftoverArray);
$leftoverArrayCheckCards = replaceNumber($leftoverArrayCheckCards);
$leftoverArrayCheck = deckArray($leftoverArrayCheckCards);
// find my categories
$myCategories = grabCats( $workTCG ); // grab your categories
$countMeIn = sizeof($myCategories);
// dig through categories
foreach( $myCategories as &$meow ) {
if ($meow !== $mySortCat) {
// grab cards
$workingCards = catCards( $workTCG, $meow );
if($workingCards !== "") {
// remove numbers
$workingCards = replaceNumber($workingCards);
// create working array
$workArray = deckArray($workingCards);
// find DECK matches
$foundArray = array_intersect($workArray, $leftoverArrayCheck);
// match check
if(count($foundArray) > 0) {
echo "<p><h3>" . $meow . "</h3>";
foreach ( $foundArray as $decksToFind) {
// dig through the found array
foreach( $leftoverArray as $cardsToFind) {
// dig thru the input array
if( strpos($cardsToFind, $decksToFind ) !== false && $decksToFind !== "") {
// matches found, print!
echo $cardsToFind . ", ";
// push more cards weve found
array_push ($excludeMe, $cardsToFind);
}
}
}
echo "</p>";
}
}
}
}
unset($meow, $cardsToFind, $decksToFind);
$sayArraySize = sizeof($sayArray);
$excludeMeSize = sizeof($excludeMe);
if( $sayArraySize !== $excludeMeSize ) {
echo "<h3>Unsorted Cards</h3>";
$extraCards = array_diff($sayArray, $excludeMe);
$extraCardsPrint = implode(", ", $extraCards);
echo $extraCardsPrint;
}
?>