Enter Puzzle ID to testsolve: <input type="text" name="pid" /> <input type="submit" name="getTestId" value="Go" /> </form> <br/><h3><a href="stats.php">Testsolver stats</a></h3> <br /> <?php if (ALLOW_TESTSOLVE_PICK) { ?> <h2>Available for you to test (In order of priority):</h2> <strong class="impt">IMPORTANT:</strong> <b>Clicking a puzzle below will mark you as a testsolver. Please click judiciously and file a testsolving report!</b> <br> <?php $availPuzzles = getAvailablePuzzlesToTestForUser($uid); if ($availPuzzles != NULL) { // Sort descending, by MINUS priority, then reverse. // Trust me on this. // // (We want to sort by priority descending, then by puzzle ID // ascending. This is the easiest way to (sort of mostly) // accomplish that. "Mostly" because PHP's asort is not // stable, so this method of using a secondary sort key doesn't // quite work.) foreach ($availPuzzles as $pid) { $sort[$pid] = -getPuzzleTestPriority($pid); } asort($sort); $availPuzzles = array_keys($sort); $availPuzzles = array_reverse($availPuzzles);
function getPuzzleToTest($uid) { $puzzles = getAvailablePuzzlesToTestForUser($uid); if (!$puzzles) { return FALSE; } $sort = array(); foreach ($puzzles as $pid) { $num = getPuzzleTestPriority($pid); // Lower numbers are HIGHER priorities $sort[$pid] = $num; } asort($sort); return key($sort); }