Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d3d1682
- Added BBCode parsing to titles
blackshadowshade Sep 29, 2025
01432cd
Added unit test for display of tournament description including BBCode
blackshadowshade Jan 3, 2026
b7bb417
Added new function Env.removeBbCodeFromHtml to strip BBCode from desc…
blackshadowshade Jan 4, 2026
8f62080
Added QUnit test for new function
blackshadowshade Jan 4, 2026
9978a37
Used new function to strip BBCode on the tournament overview page
blackshadowshade Jan 8, 2026
60d3f54
- Simplified and refactored logic to strip BBCode from overly long to…
blackshadowshade Jan 11, 2026
3439818
Simplified regex further, similar to Env.removeBbCodeFromHtml
blackshadowshade Jan 11, 2026
cd5400b
Fixed PHPMD error
blackshadowshade Jan 11, 2026
b2961af
- Removed truncation and BBCode removal code from backend
blackshadowshade Jan 15, 2026
e0418c0
Started implementing QUnit tests for TournamentOverview
blackshadowshade Jan 17, 2026
183f1b6
Added QUnit test for TournamentOverview.getOverview
blackshadowshade Jan 17, 2026
2eb6199
Added infrastructure for caching all tournaments data to JSON for use…
blackshadowshade Jan 26, 2026
9f8a14b
Fixed incorrect caching of functions during testing
blackshadowshade Jan 26, 2026
015971c
Fixed handling of newline characters in tournament descriptions and o…
blackshadowshade Mar 8, 2026
06d97f8
- Changed replacement of newlines to global
blackshadowshade Jun 21, 2026
6aa94d0
Added logic for editing tournament description
blackshadowshade Apr 12, 2026
52d04d7
Started adding dummy infrastructure for testing change of tournament …
blackshadowshade May 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/database/schema.game.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CREATE TABLE game (
last_winner_id SMALLINT UNSIGNED,
tournament_id SMALLINT UNSIGNED,
tournament_round_number SMALLINT UNSIGNED,
description VARCHAR(255) NOT NULL,
description VARCHAR(305) NOT NULL,
chat TEXT,
previous_game_id MEDIUMINT UNSIGNED,
FOREIGN KEY (previous_game_id) REFERENCES game(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE game MODIFY description VARCHAR(305) NOT NULL;
19 changes: 19 additions & 0 deletions src/api/ApiResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,25 @@ protected function get_interface_response_unfollowTournament($interface, $args)
return $retval;
}

/**
* Interface redirect for changeTournamentDesc
*
* @param type $interface
* @param type $args
* @return type
*/
protected function get_interface_response_changeTournamentDesc($interface, $args) {
$retval = $interface->tournament()->change_tournament_desc(
$this->session_user_id(),
$args['tournamentId'],
$args['description']
);
if (isset($retval)) {
$interface->player()->update_last_action_time($this->session_user_id());
}
return $retval;
}

// End of tournament-related methods
////////////////////////////////////////////////////////////

Expand Down
10 changes: 10 additions & 0 deletions src/api/ApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ class ApiSpec {
),
'permitted' => array(),
),
'changeTournamentDesc' => array(
'mandatory' => array(
'tournamentId' => 'number',
'description' => array(
'arg_type' => 'string',
'maxlength' => self::TOURNAMENT_DESCRIPTION_MAX_LENGTH,
),
),
'permitted' => array(),
),
// countPendingGames returns:
// count: int,
'countPendingGames' => array(
Expand Down
21 changes: 21 additions & 0 deletions src/api/DummyApiResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,27 @@ protected function get_interface_response_loadGameData($args) {
);
}

protected function get_interface_response_loadTournaments($args) {
return $this->load_json_data_from_file(
'loadTournaments',
'noargs.json'
);
}

protected function get_interface_response_changeTournamentDesc($args) {
return $this->load_json_data_from_file(
'changeTournamentDesc',
$args['tournamentId'] . '.json'
);
}

protected function get_interface_response_loadTournamentData($args) {
return $this->load_json_data_from_file(
'loadTournamentData',
$args['tournament'] . '.json'
);
}

protected function get_interface_response_countPendingGames() {
return $this->load_json_data_from_file(
'countPendingGames',
Expand Down
119 changes: 114 additions & 5 deletions src/engine/BMInterfaceTournament.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,57 @@ protected function load_tournament_participants(BMTournament $tournament) {
$tournament->remainCountArray = $remainCountArray;
}

/**
* Set tournament description in database
*
* @param type $tournamentId
* @param type $tournamentDesc
*/
protected function set_tournament_description($tournamentId, $tournamentDesc) {
try {
$query = 'UPDATE tournament ' .
'SET description = :description ' .
'WHERE id = :id';
$parameters = array(
':description' => $tournamentDesc,
':id' => $tournamentId
);

self::$db->update($query, $parameters);

return $tournamentId;
} catch (BMExceptionDatabase $e) {
$this->set_message('Cannot set tournament description because the tournament ID was not valid');
return NULL;
} catch (Exception $e) {
$this->set_message('Tournament description set failed: ' . $e->getMessage());
error_log(
'Caught exception in BMInterface::set_tournament_description: ' .
$e->getMessage()
);
return NULL;
}
}

protected function is_tournament_creator($playerId, $tournamentId) {
if (($playerId <= 0) || ($tournamentId <= 0)) {
return FALSE;
}

$query = 'SELECT t.creator_id ' .
'FROM tournament AS t ' .
'WHERE t.id = :tournament_id;';
$parameters = array(
':tournament_id' => $tournamentId,
);
$columnReturnTypes = array(
'creator_id' => 'int',
);
$rows = self::$db->select_rows($query, $parameters, $columnReturnTypes);
$row = $rows[0];
return ($row['creator_id'] === $playerId);
}

/**
* Check whether a player is in a tournament
*
Expand All @@ -447,7 +498,7 @@ protected function is_player_in_tournament($playerId, $tournamentId) {
'AND t.tournament_id = :tournament_id;';
$parameters = array(
':player_id' => $playerId,
':tournament_id' => $tournamentId
':tournament_id' => $tournamentId,
);
$columnReturnTypes = array(
'player_id' => 'int',
Expand Down Expand Up @@ -503,17 +554,21 @@ protected function generate_new_games(BMTournament $tournament) {
array($gameData['buttonId1'], $gameData['buttonId2'])
);

$description = 'Round ' . $gameData['roundNumber'];
if ('' != $tournament->description) {
$description = $tournament->description . ' ' . $description;
$roundDescription = 'Tournament Round ' . $gameData['roundNumber'];
$tournDescription = $tournament->description;

if ('' == trim($tournDescription)) {
$tournDescription = $roundDescription;
} else {
$tournDescription = $tournDescription . ' • ' . $roundDescription;
}

$interfaceResponse = $this->game()->create_game_from_button_ids(
array($gameData['playerId1'], $gameData['playerId2']),
array($gameData['buttonId1'], $gameData['buttonId2']),
$buttonNames,
$tournament->gameMaxWins,
$description,
$tournDescription,
NULL,
0, // needs to be non-null, but also a non-player ID
TRUE,
Expand Down Expand Up @@ -609,6 +664,19 @@ protected function get_tournament_status(BMTournament $tournament) {
return $status;
}

/**
* Check whether a tournament is open to join
*
* @param int $tournamentId
* @return bool
*/
protected function is_tournament_open($tournamentId) {
$tournament = $this->load_tournament($tournamentId);
$tournamentState = $tournament->tournamentState;

return ($tournamentState <= BMTournamentState::JOIN_TOURNAMENT);
}

/**
* Check whether a tournament has ended, either through completion or cancellation
*
Expand Down Expand Up @@ -1250,4 +1318,45 @@ public function dismiss_tournament($playerId, $tournamentId) {
return NULL;
}
}

/**
* Change tournament description
*
* This changes the tournament description.
*
* It is only accessible to the tournament creator before the tournament has started.
*
* @param int $playerId
* @param int $tournamentId
* @param string $tournamentDesc
* @return bool|null
*/
public function change_tournament_desc($playerId, $tournamentId, $tournamentDesc) {
try {
if (!$this->is_tournament_creator($playerId, $tournamentId)) {
$this->set_message('Only tournament creators can change the description');
return NULL;
}

if (!$this->is_tournament_open($tournamentId)) {
$this->set_message("Tournament $tournamentId has already started");
return NULL;
}

$this->set_tournament_description($tournamentId, $tournamentDesc);

$this->set_message('Tournament description saved');
return TRUE;
} catch (BMExceptionDatabase $e) {
$this->set_message('Cannot change tournament description because tournament ID was not valid');
return NULL;
} catch (Exception $e) {
error_log(
'Caught exception in BMInterface::change_tournament_desc: ' .
$e->getMessage()
);
$this->set_message('Internal error while changing a tournament description');
return NULL;
}
}
}
Loading