List Group Tournaments
The list group tournaments method retrieves all available group tournaments for a specific game. Group tournaments allow multiple players to compete as teams.
Overview
The getGroupTournaments method:
- Returns all group tournaments configured for a specific game
- Provides tournament metadata including team requirements
- Returns an array of
GroupTournamentMetaobjects - Handles empty results gracefully
Method Signature
public function getGroupTournaments(string $gameID): array
Parameters
Required Parameters
gameID(String) - The Game ID for which to retrieve group tournaments- Must be a valid Moitribe Game ID
- Cannot be empty
Return Value
Returns an array of GroupTournamentMeta objects:
- Empty array - No group tournaments found or game doesn't exist
- Array with objects - Successfully retrieved group tournaments
Each GroupTournamentMeta object contains:
- Tournament ID
- Tournament name
- Team size requirements
- Start/end dates
- Entry requirements
- Prize information
Basic Usage
Get All Group Tournaments for a Game
use Veniso\Moitribe\Sdk\modules\classes\MoitribeApi;
$moitribe = new MoitribeApi([
'gameid' => 'your-game-id',
'channelid' => 'your-channel-id',
'playerid' => 'player-123'
]);
try {
$groupTournaments = $moitribe->groupTournRequestsHandler->getGroupTournaments('your-game-id');
echo "Found " . count($groupTournaments) . " group tournaments:\n";
foreach ($groupTournaments as $tournament) {
echo "- " . $tournament->getName() . " (ID: " . $tournament->getId() . ")\n";
echo " Team Size: " . $tournament->getMinTeamSize() . " - " . $tournament->getMaxTeamSize() . "\n";
echo " Status: " . $tournament->getStatus() . "\n";
echo " Start: " . $tournament->getStartDate() . "\n";
echo " End: " . $tournament->getEndDate() . "\n";
if ($tournament->getEntryFee()) {
echo " Entry Fee: " . $tournament->getEntryFee() . "\n";
}
if ($tournament->getPrizePool()) {
echo " Prize Pool: " . $tournament->getPrizePool() . "\n";
}
echo "---\n";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
Filter Group Tournaments by Status
function getGroupTournamentsByStatus($gameId, $status = null) {
global $moitribe;
try {
$allGroupTournaments = $moitribe->groupTournRequestsHandler->getGroupTournaments($gameId);
if ($status === null) {
return $allGroupTournaments;
}
$filteredTournaments = array_filter($allGroupTournaments, function($tournament) use ($status) {
return $tournament->getStatus() === $status;
});
return array_values($filteredTournaments);
} catch (Exception $e) {
error_log("Error getting group tournaments: " . $e->getMessage());
return [];
}
}
// Usage examples
$activeTournaments = getGroupTournamentsByStatus('your-game-id', 'active');
$upcomingTournaments = getGroupTournamentsByStatus('your-game-id', 'upcoming');
$completedTournaments = getGroupTournamentsByStatus('your-game-id', 'completed');
echo "Active group tournaments: " . count($activeTournaments) . "\n";
echo "Upcoming group tournaments: " . count($upcomingTournaments) . "\n";
echo "Completed group tournaments: " . count($completedTournaments) . "\n";
Integration Examples
Group Tournament Selection Interface
function displayGroupTournamentSelection($gameId) {
global $moitribe;
try {
$groupTournaments = $moitribe->groupTournRequestsHandler->getGroupTournaments($gameId);
if (empty($groupTournaments)) {
echo "<p>No group tournaments available for this game.</p>";
return;
}
// Group tournaments by status
$groupedTournaments = [];
foreach ($groupTournaments as $tournament) {
$status = $tournament->getStatus();
if (!isset($groupedTournaments[$status])) {
$groupedTournaments[$status] = [];
}
$groupedTournaments[$status][] = $tournament;
}
echo "<div class='group-tournament-selection'>";
echo "<h2>Choose a Group Tournament</h2>";
foreach ($groupedTournaments as $status => $tournaments) {
$statusLabel = ucfirst($status);
$statusClass = $status === 'active' ? 'active' : 'inactive';
echo "<div class='tournament-group $statusClass'>";
echo "<h3>$statusLabel Group Tournaments</h3>";
foreach ($tournaments as $tournament) {
$teamSize = $tournament->getMinTeamSize() . '-' . $tournament->getMaxTeamSize();
$entryFee = $tournament->getEntryFee() ?: 'Free';
$prizePool = $tournament->getPrizePool() ?: 'N/A';
echo "<div class='tournament-item' data-id='{$tournament->getId()}'>";
echo "<h4>" . htmlspecialchars($tournament->getName()) . "</h4>";
echo "<div class='tournament-details'>";
echo "<span class='team-size'>Team: $teamSize</span>";
echo "<span class='entry-fee'>Entry: $entryFee</span>";
echo "<span class='prize-pool'>Prizes: $prizePool</span>";
echo "<span class='dates'>" . date('M j', strtotime($tournament->getStartDate())) . " - " . date('M j', strtotime($tournament->getEndDate())) . "</span>";
echo "</div>";
if ($status === 'active') {
echo "<button class='join-btn' onclick='joinGroupTournament(\"{$tournament->getId()}\")'>Join Tournament</button>";
} else {
echo "<button class='join-btn disabled'>" . getJoinButtonText($status) . "</button>";
}
echo "</div>";
}
echo "</div>";
}
echo "</div>";
} catch (Exception $e) {
echo "<div class='error'>Failed to load group tournaments. Please try again later.</div>";
error_log("Group tournament selection error: " . $e->getMessage());
}
}
function getJoinButtonText($status) {
switch ($status) {
case 'active':
return 'Join Tournament';
case 'upcoming':
return 'Starting Soon';
case 'completed':
return 'Tournament Ended';
case 'full':
return 'Tournament Full';
default:
return 'Not Available';
}
}
// Display on your page
displayGroupTournamentSelection('your-game-id');
Group Tournament Management System
class GroupTournamentManager {
private $moitribe;
private $gameId;
private $cache = [];
private $cacheExpiry = 300; // 5 minutes
public function __construct($moitribe, $gameId) {
$this->moitribe = $moitribe;
$this->gameId = $gameId;
}
public function getAvailableTournaments($useCache = true) {
$cacheKey = "group_tournaments_{$this->gameId}";
// Check cache first
if ($useCache && isset($this->cache[$cacheKey])) {
$cached = $this->cache[$cacheKey];
if (time() - $cached['timestamp'] < $this->cacheExpiry) {
return $cached['data'];
}
}
try {
$tournaments = $this->moitribe->groupTournRequestsHandler->getGroupTournaments($this->gameId);
// Cache the result
$this->cache[$cacheKey] = [
'data' => $tournaments,
'timestamp' => time()
];
return $tournaments;
} catch (Exception $e) {
error_log("Error getting group tournaments: " . $e->getMessage());
return [];
}
}
public function getTournamentsByTeamSize($minSize, $maxSize = null) {
$tournaments = $this->getAvailableTournaments();
$filteredTournaments = array_filter($tournaments, function($tournament) use ($minSize, $maxSize) {
$tournamentMinSize = $tournament->getMinTeamSize();
$tournamentMaxSize = $tournament->getMaxTeamSize();
$sizeMatch = $tournamentMinSize >= $minSize;
if ($maxSize !== null) {
$sizeMatch = $sizeMatch && $tournamentMaxSize <= $maxSize;
}
return $sizeMatch;
});
return array_values($filteredTournaments);
}
public function getTournamentsByEntryFee($isFree = null) {
$tournaments = $this->getAvailableTournaments();
$filteredTournaments = array_filter($tournaments, function($tournament) use ($isFree) {
$entryFee = $tournament->getEntryFee();
if ($isFree === null) {
return true; // Include all if not specified
}
return $isFree ? ($entryFee === null || $entryFee == 0) : ($entryFee > 0);
});
return array_values($filteredTournaments);
}
public function getTournamentById($tournamentId) {
$tournaments = $this->getAvailableTournaments();
foreach ($tournaments as $tournament) {
if ($tournament->getId() === $tournamentId) {
return $tournament;
}
}
return null;
}
public function refreshCache() {
$cacheKey = "group_tournaments_{$this->gameId}";
unset($this->cache[$cacheKey]);
return $this->getAvailableTournaments(false);
}
}
// Usage
$tournamentManager = new GroupTournamentManager($moitribe, 'your-game-id');
// Get all tournaments (with caching)
$allTournaments = $tournamentManager->getAvailableTournaments();
echo "Total group tournaments: " . count($allTournaments) . "\n";
// Get tournaments for specific team size
$teamTournaments = $tournamentManager->getTournamentsByTeamSize(2, 4);
echo "2-4 player tournaments: " . count($teamTournaments) . "\n";
// Get free tournaments
$freeTournaments = $tournamentManager->getTournamentsByEntryFee(true);
echo "Free tournaments: " . count($freeTournaments) . "\n";
// Get specific tournament
$tournament = $tournamentManager->getTournamentById('tournament-456');
if ($tournament) {
echo "Found: " . $tournament->getName() . "\n";
} else {
echo "Tournament not found\n";
}