Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created October 31, 2019 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/e3d0acea2fbad0bfb7b25c8d83dfc36e to your computer and use it in GitHub Desktop.
Save Kcko/e3d0acea2fbad0bfb7b25c8d83dfc36e to your computer and use it in GitHub Desktop.
<?php
/**
* Umozni prepocitat tabulku za zapas, za kolo, souhrně
*/
class TableResult
{
public $data;
/**
* Konstruktor
*/
function __construct($soutezID = 0, $date = '0000-00-00 00:00:00', $home_team = 0, $away_team = 0)
{
$this->soutezID = $soutezID;
$this->date = $date;
$this->home_team = $home_team;
$this->away_team = $away_team;
}
function reCount($match_data, $round, $round_type = 'before')
{
if (count($match_data))
{
foreach ($match_data as $index => $r)
{
if ($r->schvaleno != '1') continue;
if ($round_type == 'before' && $r->kolo >= $round) break;
if ($round_type == 'after' && $r->kolo > $round) break;
if ($round_type == 'jaro' && $r->kolo > 11) break;
if ($round_type == 'podzim' && $r->kolo <= 11) continue;
// nastaveni promennych
$domaci = $r->id_domaci;
$hoste = $r->id_hoste;
$g1 = $r->g1;
$g2 = $r->g2;
$kontumace = 0;
$trest1 = 0;
$trest2 = 0;
$seo = $r->seo;
// vypocet
$this->data[$domaci]["ID"] = $domaci;
$this->data[$hoste]["ID"] = $hoste;
$this->data[$domaci]['seo'] = $seo;
$this->data[$hoste]['seo'] = $seo;
// domaci vyhrali
if ($g1 > $g2 && $kontumace != 3)
{
// nastavime domaci
$this->data[$domaci]["pz"]++;
$this->data[$domaci]["v"]++;
//$this->data[$domaci]["r"]++;
//$this->data[$domaci]["p"]++;
$this->data[$domaci]["gf"] += $g1;
$this->data[$domaci]["ga"] += $g2;
$this->data[$domaci]["pts"] += 3 - $trest1;
$this->data[$domaci]["trest"] += $trest1;
$this->data[$domaci]["diff"] += $g1 - $g2;
// nastavime hosty
$this->data[$hoste]["pz"]++;
//$this->data[$hoste]["v"]++;
//$this->data[$hoste]["r"]++;
$this->data[$hoste]["p"]++;
$this->data[$hoste]["gf"] += $g2;
$this->data[$hoste]["ga"] += $g1;
$this->data[$hoste]["pts"] += 0 - $trest2;
$this->data[$hoste]["trest"] += $trest2;
$this->data[$hoste]["diff"] += $g2 - $g1;
}
// vyhrali hoste
elseif ($g1 < $g2 && $kontumace != 3)
{
// nastavime domaci
$this->data[$domaci]["pz"]++;
//$this->data[$domaci]["v"]++;
//$this->data[$domaci]["r"]++;
$this->data[$domaci]["p"]++;
$this->data[$domaci]["gf"] += $g1;
$this->data[$domaci]["ga"] += $g2;
$this->data[$domaci]["pts"] += 0 - $trest1;
$this->data[$domaci]["trest"] += $trest1;
$this->data[$domaci]["diff"] += $g1 - $g2;
// nastavime hosty
$this->data[$hoste]["pz"]++;
$this->data[$hoste]["v"]++;
//$this->data[$hoste]["r"]++;
//$this->data[$hoste]["p"]++;
$this->data[$hoste]["gf"] += $g2;
$this->data[$hoste]["ga"] += $g1;
$this->data[$hoste]["pts"] += 3 - $trest2;
$this->data[$hoste]["trest"] += $trest2;
$this->data[$hoste]["diff"] += $g2 - $g1;
}
// remiza
elseif ($g1 == $g2 && $kontumace != 3)
{
// nastavime domaci
$this->data[$domaci]["pz"]++;
//$this->data[$domaci]["v"]++;
$this->data[$domaci]["r"]++;
//$this->data[$domaci]["p"]++;
$this->data[$domaci]["gf"] += $g1;
$this->data[$domaci]["ga"] += $g2;
$this->data[$domaci]["pts"] += 1 - $trest1;
$this->data[$domaci]["trest"] += $trest1;
$this->data[$domaci]["diff"] += $g1 - $g2;
// nastavime hosty
$this->data[$hoste]["pz"]++;
//$this->data[$hoste]["v"]++;
$this->data[$hoste]["r"]++;
//$this->data[$hoste]["p"]++;
$this->data[$hoste]["gf"] += $g2;
$this->data[$hoste]["ga"] += $g1;
$this->data[$hoste]["pts"] += 1 - $trest2;
$this->data[$hoste]["trest"] += $trest2;
$this->data[$hoste]["diff"] += $g2 - $g1;
}
// kontumace pro oba
elseif ($g1 == $g2 && $kontumace == 3)
{
// nastavime domaci
$this->data[$domaci]["pz"]++;
//$this->data[$domaci]["v"]++;
//$this->data[$domaci]["r"]++;
$this->data[$domaci]["p"]++;
$this->data[$domaci]["gf"] += 0;
$this->data[$domaci]["ga"] += 3;
$this->data[$domaci]["pts"] += 0 - $trest1;
$this->data[$domaci]["trest"] += $trest1;
$this->data[$domaci]["diff"] += $g1 - $g2;
// nastavime hosty
$this->data[$hoste]["pz"]++;
//$this->data[$hoste]["v"]++;
//$this->data[$hoste]["r"]++;
$this->data[$hoste]["p"]++;
$this->data[$hoste]["gf"] += 0;
$this->data[$hoste]["ga"] += 3;
$this->data[$hoste]["pts"] += 0 - $trest2;
$this->data[$hoste]["trest"] += $trest2;
$this->data[$hoste]["diff"] += $g2 - $g1;
}
} // while end
}
//print_r($data);
return true;
} // method end
/**
* Init, nastavi vsem 0-0-0 ..
*/
function init($tymy = array())
{
$tabulkoveHodnoty = array(
"pz", "v", "r", "p", "gf", "ga", "pts", "trest", "diff", "ID", "logo", "nazev"
);
$data = array();
foreach ($tymy as $tym_id => $tym_nazev)
{
foreach ($tabulkoveHodnoty as $hodnota)
{
if ($hodnota == "ID")
$data[$tym_id][$hodnota] = $tym_id;
elseif ($hodnota == "logo")
$data[$tym_id][$hodnota] = 0;
elseif ($hodnota == "nazev")
$data[$tym_id][$hodnota] = $tym_nazev;
else
$data[$tym_id][$hodnota] = 0;
}
}
return $data;
}
function getTableData()
{
$sort_arr = array();
foreach($this->data AS $uniqid => $row)
{
foreach($row AS $key=>$value)
{
$sort_arr[$key][$uniqid] = $value;
}
}
// ORDER BY PTS DESC, ROZDIL_GOLU DESC, G1 DESC, zapasy DESC, G2 ASC
array_multisort($sort_arr['pts'], SORT_NUMERIC, SORT_DESC,
$sort_arr['diff'], SORT_NUMERIC, SORT_DESC,
$sort_arr['gf'], SORT_NUMERIC, SORT_DESC,
$sort_arr['pz'], SORT_NUMERIC, SORT_DESC,
$sort_arr['ga'], SORT_NUMERIC, SORT_ASC,
$sort_arr['ID'], SORT_NUMERIC, SORT_ASC
);
$tym = $sort_arr;
return $tym;
}
function sortItAndShow()
{
$sort_arr = array();
foreach($this->data AS $uniqid => $row)
{
foreach($row AS $key=>$value)
{
$sort_arr[$key][$uniqid] = $value;
}
}
// ORDER BY PTS DESC, ROZDIL_GOLU DESC, G1 DESC, zapasy DESC, G2 ASC
array_multisort($sort_arr['pts'], SORT_NUMERIC, SORT_DESC,
$sort_arr['diff'], SORT_NUMERIC, SORT_DESC,
$sort_arr['gf'], SORT_NUMERIC, SORT_DESC,
$sort_arr['pz'], SORT_NUMERIC, SORT_DESC,
$sort_arr['ga'], SORT_NUMERIC, SORT_ASC,
$sort_arr['ID'], SORT_NUMERIC, SORT_ASC
);
$tym = $sort_arr;
/*
echo "<table class='tabulka left' style='width: 520px; margin: 0 auto;'>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Tým</th>";
echo "<th>PZ</th>";
echo "<th>V</th>";
echo "<th>R</th>";
echo "<th>P</th>";
echo "<th>Skóre</th>";
echo "<th>PTS</th>";
echo "</tr>";
*/
$counter = 1;
$positions = array();
foreach ($tym['ID'] as $value => $key )
{
/*
$logo = $this->data[$key]['logo'];
$logo_img = is_file("img/kluby-small/$logo") ? $logo : 'nologo.gif';
$nazev = $this->data[$key]['nazev'];
$style = '';
if (in_array($this->data[$key]['ID'], array($this->home_team, $this->away_team)))
{
$nazev = "<strong>" . $this->data[$key]['nazev'] . "</strong>";
$style = "style='background: #FFECEC'";
}
*/
/*
echo "<tr $style>";
echo "<td>".$counter++.".</td>";
echo "<td>". "<img src='/img/kluby-small/$logo_img' />" . " " . $nazev ."</td>";
echo "<td>".$this->data[$key]['pz']."</td>";
echo "<td>".$this->data[$key]['v']."</td>";
echo "<td>".$this->data[$key]['r']."</td>";
echo "<td>".$this->data[$key]['p']."</td>";
echo "<td>".$this->data[$key]['gf']." : ";
echo "".$this->data[$key]['ga']."</td>";
echo "<td><span class=\"pts_bold\">".$this->data[$key]['pts']."</span></td>";
echo "</tr>";
}
echo "</table>";
*/
$positions[$this->data[$key]['ID']] = $counter;
$counter++;
}
return $positions;
}
} // class end
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment