Add bonuspoint, corr and chart calculation and update displaying of chart.
This commit is contained in:
@@ -16,12 +16,14 @@ global $table_prefix;
|
||||
|
||||
// Config constants
|
||||
define('FOOTB_BETS', $table_prefix . 'footb_bets');
|
||||
define('FOOTB_CORR', $table_prefix . 'footb_corr');
|
||||
define('FOOTB_EXTRA_BETS', $table_prefix . 'footb_extra_bets');
|
||||
define('FOOTB_EXTRA', $table_prefix . 'footb_extra');
|
||||
define('FOOTB_LEAGUES', $table_prefix . 'footb_leagues');
|
||||
define('FOOTB_MATCHDAYS', $table_prefix . 'footb_matchdays');
|
||||
define('FOOTB_MATCHES', $table_prefix . 'footb_matches');
|
||||
define('FOOTB_MATCHES_HIST', $table_prefix . 'footb_matches_hist');
|
||||
define('FOOTB_MY_CHART', $table_prefix . 'footb_my_chart');
|
||||
define('FOOTB_POINTS', $table_prefix . 'footb_points');
|
||||
define('FOOTB_RANKS', $table_prefix . 'footb_rank_matchdays');
|
||||
define('FOOTB_SEASONS', $table_prefix . 'footb_seasons');
|
||||
|
||||
@@ -2564,4 +2564,234 @@ function select_points($creator = 'm', $sum = false)
|
||||
}
|
||||
return $select_part;
|
||||
}
|
||||
|
||||
function bonuspoints($season, $league, $matchday)
|
||||
{
|
||||
global $db, $config, $lang, $league_info, $phpbb_root_path, $phpEx;
|
||||
if ($league < 40)
|
||||
{
|
||||
$league2 = $league + 50;
|
||||
$sql = 'DELETE FROM ' . FOOTB_BONUS_DAY . " WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday'";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql = 'REPLACE INTO ' . FOOTB_BONUS_DAY . ' (season, league, matchday, team_id, rank)
|
||||
SELECT season, (league + 50), matchday, (user_id + 2000), rank FROM ' . FOOTB_RANKS . " WHERE season = '$season' AND league = '$league' and matchday = '$matchday'";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql = 'SELECT team_id_home FROM ' . FOOTB_MATCHES . " WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday'";
|
||||
$result = $db->sql_query($sql);
|
||||
$id = array();
|
||||
while( $row = $db->sql_fetchrow($result))
|
||||
{
|
||||
array_push ( $id, $row['team_id_home']);
|
||||
}
|
||||
$i = 0;
|
||||
while($id[$i])
|
||||
{
|
||||
$tmp = $id[$i];
|
||||
$sql = 'UPDATE ' . FOOTB_BONUS_DAY . " SET home = '1' WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday' AND team_id = '$tmp'";
|
||||
$result = $db->sql_query($sql);
|
||||
$i++;
|
||||
}
|
||||
$sql = 'SELECT rank FROM ' . FOOTB_BONUS_DAY . " WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday'" ;
|
||||
$result = $db->sql_query($sql);
|
||||
$ranks = array();
|
||||
while( $row = $db->sql_fetchrow($result))
|
||||
{
|
||||
array_push ( $ranks, $row['rank']);
|
||||
}
|
||||
$anzahl = array_count_values ($ranks);
|
||||
If(isset($anzahl[1]))
|
||||
{
|
||||
$z1 = $anzahl[1];
|
||||
}
|
||||
Else
|
||||
{
|
||||
$z1 = "0";
|
||||
}
|
||||
If(isset($anzahl[2]))
|
||||
{
|
||||
$z2 = $anzahl[2];
|
||||
}
|
||||
Else
|
||||
{
|
||||
$z2 = "0";
|
||||
}
|
||||
If(isset($anzahl[3]))
|
||||
{
|
||||
$z3 = $anzahl[3];
|
||||
}
|
||||
Else
|
||||
{
|
||||
$z3 = "0";
|
||||
}
|
||||
|
||||
If ($z1 > 2)
|
||||
{
|
||||
$b1 = 6 / $z1;
|
||||
}
|
||||
Elseif ($z1 == 2)
|
||||
{
|
||||
$b1 = 2.5;
|
||||
}
|
||||
Else
|
||||
{
|
||||
$b1 = 3;
|
||||
}
|
||||
If ($z2 > 1)
|
||||
{
|
||||
$b2 = 3 / $z2;
|
||||
}
|
||||
Elseif ($z2 == 1)
|
||||
{
|
||||
$b2 = 2;
|
||||
}
|
||||
Else
|
||||
{
|
||||
$b2 = 0;
|
||||
}
|
||||
If ($z3 > 0)
|
||||
{
|
||||
$b3 = 1 / $z3;
|
||||
}
|
||||
Else
|
||||
{
|
||||
$b3 = 0;
|
||||
}
|
||||
$sql =
|
||||
'UPDATE ' . FOOTB_BONUS_DAY . "
|
||||
SET bonuspoints = '$b1'
|
||||
WHERE season = '$season' AND league = '$league2' and matchday = '$matchday' AND rank = '1'";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql =
|
||||
'UPDATE ' . FOOTB_BONUS_DAY . "
|
||||
SET bonuspoints = '$b2'
|
||||
WHERE season = '$season' AND league = '$league2' and matchday = '$matchday' AND rank = '2'";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql =
|
||||
'UPDATE ' . FOOTB_BONUS_DAY . "
|
||||
SET bonuspoints = '$b3'
|
||||
WHERE season = '$season' AND league = '$league2' and matchday = '$matchday' AND rank = '3'";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql =
|
||||
'UPDATE ' . FOOTB_BONUS_DAY . " SET `team_id` = `team_id`+2000 WHERE `team_id`<2000";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql = 'DELETE FROM ' . FOOTB_BONUS_DAY . " WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday' AND bonuspoints = '0'";
|
||||
$result = $db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
function corr($season, $league, $matchday)
|
||||
{
|
||||
global $db, $config, $lang, $league_info, $phpbb_root_path, $phpEx;
|
||||
if ($league < 40)
|
||||
{
|
||||
$league2 = $league + 50;
|
||||
$sql = 'DELETE FROM ' . FOOTB_CORR . " WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday'";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql = 'SELECT status FROM ' . FOOTB_MATCHDAYS . " WHERE season = '$season' AND league = '$league' AND matchday = '$matchday'";
|
||||
$result = $db->sql_query($sql);
|
||||
while($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
if ($row['status'] > 0)
|
||||
{
|
||||
$sql = 'SELECT match_no FROM ' . FOOTB_MATCHES . " WHERE season = '$season' AND league = '$league2' AND matchday = '$matchday'";
|
||||
$result = $db->sql_query($sql);
|
||||
$game = array();
|
||||
while( $row = $db->sql_fetchrow($result))
|
||||
{
|
||||
array_push ($game,$row['match_no']);
|
||||
}
|
||||
foreach($game as $nr)
|
||||
{
|
||||
$sql = 'SELECT team_id_home, team_id_guest, goals_home, goals_guest FROM ' . FOOTB_MATCHES . " WHERE season = '$season' AND league = '$league2' AND match_no = '$nr'";
|
||||
$result = $db->sql_query($sql);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
if ($row['goals_home'] == 0 and $row['goals_guest'] == 0)
|
||||
{
|
||||
$sql = 'SELECT b.goals_home, b.goals_guest FROM ' . FOOTB_BETS . ' AS b LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = b.season AND m.league = b.league AND m.match_no = b.match_no) WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday AND b.user_id = $row[team_id_home] - 2000";
|
||||
$result = $db->sql_query($sql);
|
||||
$home_empty = true;
|
||||
while($row_home = $db->sql_fetchrow($result))
|
||||
{
|
||||
if (!empty($row_home['goals_home']) or !empty($row_home['goals_guest']))
|
||||
{
|
||||
$home_empty = false;
|
||||
}
|
||||
}
|
||||
$sql = 'SELECT b.goals_home, b.goals_guest FROM ' . FOOTB_BETS . ' AS b LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = b.season AND m.league = b.league AND m.match_no = b.match_no) WHERE m.season = $season AND m.league = $league AND m.matchday = $matchday AND b.user_id = $row[team_id_guest] - 2000";
|
||||
$result = $db->sql_query($sql);
|
||||
$guest_empty = true;
|
||||
while($row_guest = $db->sql_fetchrow($result))
|
||||
{
|
||||
if (!empty($row_guest['goals_home']) or !empty($row_guest['goals_guest']))
|
||||
{
|
||||
$guest_empty = false;
|
||||
}
|
||||
}
|
||||
if ($home_empty == true)
|
||||
{
|
||||
$sql = 'REPLACE INTO ' . FOOTB_CORR . "(season, league, matchday, team_id, win, lost, draw, points, home) VALUES ($season, $league2, $matchday, $row[team_id_home], 0, 1, -1, -1, 0)";
|
||||
$result = $db->sql_query($sql);
|
||||
}
|
||||
if ($guest_empty == true)
|
||||
{
|
||||
$sql = 'REPLACE INTO ' . FOOTB_CORR . "(season, league, matchday, team_id, win, lost, draw, points, home) VALUES ($season, $league2, $matchday, $row[team_id_guest], 0, 1, -1, -1, 1)";
|
||||
$result = $db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function chart($season, $league, $matchday)
|
||||
{
|
||||
global $db, $config, $lang, $league_info, $phpbb_root_path, $phpEx;
|
||||
$league2 = $league + 50;
|
||||
$sql = 'DELETE
|
||||
FROM ' . FOOTB_MY_CHART . "
|
||||
WHERE season = $season
|
||||
AND league = $league
|
||||
AND matchday = $matchday";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql = 'REPLACE INTO ' . FOOTB_MY_CHART . '
|
||||
SELECT * FROM ' . FOOTB_RANKS . "
|
||||
WHERE season = $season
|
||||
AND league = $league
|
||||
AND matchday = $matchday";
|
||||
$result = $db->sql_query($sql);
|
||||
$sql = "SELECT
|
||||
t.*,
|
||||
SUM(IF(m.team_id_home = t.team_id,
|
||||
IF(goals_home + 0 > goals_guest, 3, IF(goals_home = goals_guest, 1, 0)),
|
||||
IF(goals_home + 0 < goals_guest, 3, IF(goals_home = goals_guest, 1, 0))
|
||||
)
|
||||
) + IFNULL((SELECT SUM(b.bonuspoints) FROM " . FOOTB_BONUS_DAY . " AS b WHERE b.team_id = t.team_id AND b.season = t.season AND b.league = t.league AND b.matchday <= $matchday),0)
|
||||
+ IFNULL((SELECT SUM(c.points) FROM " . FOOTB_CORR . " AS c WHERE c.team_id = t.team_id AND c.season = t.season AND c.league = t.league AND c.matchday <= $matchday),0)AS points,
|
||||
SUM(IF(m.team_id_home = t.team_id, goals_home - goals_guest , goals_guest - goals_home)) AS goals_diff,
|
||||
SUM(IF(m.team_id_home = t.team_id, goals_home , goals_guest)) AS goals
|
||||
FROM " . FOOTB_TEAMS . ' AS t
|
||||
LEFT JOIN ' . FOOTB_MATCHES . " AS m ON (m.season = t.season AND m.league = t.league
|
||||
AND (m.team_id_home = t.team_id OR m.team_id_guest = t.team_id) AND m.group_id = t.group_id)
|
||||
WHERE t.season = $season
|
||||
AND t.league = $league2
|
||||
AND m.matchday <= $matchday
|
||||
AND m.status IN (2, 3,5,6)
|
||||
GROUP BY t.team_id
|
||||
ORDER BY t.group_id ASC, points DESC, goals_diff DESC, goals DESC, t.team_name ASC";
|
||||
$result = $db->sql_query($sql);
|
||||
$i = 1;
|
||||
while( $row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$user_i = $row['team_id'] - 2000;
|
||||
$sql2 = 'UPDATE ' . FOOTB_MY_CHART . "
|
||||
SET rank_total = $i
|
||||
WHERE season = $season
|
||||
AND league = $league
|
||||
AND matchday = $matchday
|
||||
AND user_id = $user_i";
|
||||
$result2 = $db->sql_query($sql2);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user