Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series API #544

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions gatherling/admin/clean_decks.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use Gatherling\Database;
use Gatherling\Deck;
use Gatherling\Player;

require '../lib.php';

session_start();
Expand Down
6 changes: 6 additions & 0 deletions gatherling/admin/db-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,12 @@ function redirect_deck_update($latest_id = 0)
do_query('ALTER TABLE `players`
CHANGE COLUMN `discord_id` `discord_id` VARCHAR(20) NULL DEFAULT NULL AFTER `theme`;');
});
upgrade_db(50, 'Fix series discord fields', function () {
do_query('ALTER TABLE `series`
CHANGE COLUMN `discord_guild_id` `discord_guild_id` VARCHAR(20) NULL DEFAULT NULL AFTER `mtgo_room`,
ADD COLUMN `discord_channel_id` VARCHAR(20) NULL DEFAULT NULL AFTER `discord_guild_id`,
CHANGE COLUMN `discord_require_membership` `discord_require_membership` INT NULL DEFAULT NULL AFTER `discord_guild_invite`;');
});
$db->autocommit(true);

info('DB is up to date!');
4 changes: 2 additions & 2 deletions gatherling/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
try {
$series = new Series($seriesname);
$result = repr_json_series($series);
$result['sucess'] = true;
$result['success'] = true;
} catch (Exception $e) {
$result['sucess'] = false;
$result['success'] = false;
$result['error'] = $e->getMessage();
}
break;
Expand Down
29 changes: 28 additions & 1 deletion gatherling/api_lib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

require_once 'lib.php';

//## Helper Functions

use Gatherling\Event;
Expand All @@ -16,6 +18,7 @@ function populate($array, $src, $keys)
return $array;
}

/** @return bool */
function is_admin()
{
if (!isset($_SESSION['infobot'])) {
Expand Down Expand Up @@ -62,6 +65,12 @@ function auth()
return Player::isLoggedIn();
}

/**
* @param string $msg
* @param mixed $extra
*
* @return never
*/
function error($msg, $extra = null)
{
$result = [];
Expand All @@ -74,6 +83,12 @@ function error($msg, $extra = null)
exit(json_encode($result));
}

/**
* @param string $key
* @param mixed $default
*
* @return mixed
*/
function arg($key, $default = null)
{
if (!isset($_REQUEST[$key])) {
Expand Down Expand Up @@ -181,9 +196,14 @@ function repr_json_deck($deck)
return $json;
}

/**
* @param Gatherling\Series $series
*
* @return mixed
*/
function repr_json_series($series)
{
$json = populate([], $series, ['name', 'active', 'start_day', 'start_time', 'organizers', 'mtgo_room', 'this_season_format', 'this_season_master_link', 'this_season_season']);
$json = populate([], $series, ['name', 'active', 'start_day', 'start_time', 'organizers', 'mtgo_room', 'this_season_format', 'this_season_master_link', 'this_season_season', 'discord_guild_id', 'discord_channel_id', 'discord_channel_name', 'discord_guild_name']);

return $json;
}
Expand Down Expand Up @@ -272,6 +292,13 @@ function drop_player_from_event($event, $name)
return $result;
}

/**
* @param string $newseries
* @param bool $active
* @param string $day
*
* @return array
*/
function create_series($newseries, $active, $day)
{
$result = [];
Expand Down
2 changes: 1 addition & 1 deletion gatherling/models/Decksearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function searchByMedals($medal)
*
* @param [$color_str_input] Array of the input color
*
* @return mixed true if success/false otherwise
* @return mixed true if success/false otherwise
*/
public function searchByColor($color_str_input)
{
Expand Down
23 changes: 23 additions & 0 deletions gatherling/models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ public function getTrophyImageLink()
.self::trophy_image_tag($this->name)."\n</a>\n";
}

/**
* @param string $name
*
* @return bool
*/
public function isHost($name)
{
$ishost = !is_null($this->host) && strcasecmp($name, $this->host) == 0;
Expand All @@ -507,11 +512,17 @@ public function isHost($name)
return $ishost || $iscohost;
}

/** @return bool */
public function isFinalized()
{
return $this->finalized != 0;
}

/**
* @param string $name
*
* @return bool
*/
public function isOrganizer($name)
{
$isOrganizer = false;
Expand All @@ -528,6 +539,11 @@ public function isOrganizer($name)
return $isOrganizer;
}

/**
* @param string $playername
*
* @return bool
*/
public function authCheck($playername)
{
$player = new Player($playername);
Expand All @@ -541,6 +557,11 @@ public function authCheck($playername)
return false;
}

/**
* @throws Exception
*
* @return int
*/
public function getPlayerCount()
{
return Database::single_result_single_param('SELECT count(*) FROM entries WHERE event_id = ?', 'd', $this->id);
Expand Down Expand Up @@ -1707,6 +1728,8 @@ public function AssignMedalsbyStandings()

$t8 = [];
$t4 = [];
$sec = null;
$win = null;

switch ($medalCount) {
case 8:
Expand Down
Loading
Loading