Example #1
0
 /**
  * Delete IDs from given table if they are older than X mn
  *
  *@access private
  *@param string $table Table to clean
  *@param string $fieldname field from table containing timestamp
  *@param int $mins delete IDs older than $mins minutes
  *@return int 1 if success, 0 if error
  */
 function cleanId($table, $fieldname, $mins)
 {
     global $dbauth, $l;
     $this->error = "";
     $date = dateToTimestamp(nowDate());
     $date -= $mins * 60;
     $date = timestampToDate($date);
     $query = "DELETE FROM " . $table . " WHERE\n    " . $fieldname . " < " . $date;
     $res = $dbauth->query($query);
     if ($dbauth->error()) {
         $this->error = $l['str_trouble_with_db'];
         return 0;
     }
     return 1;
 }
Example #2
0
function section_entermatch_calcSeasonRatings($rowA, $newA, $scoreA, $rowB, $newB, $scoreB, $matchDate)
{
    $season_id = 1;
    if (ENABLE_SEASONS) {
        $now = nowDate();
        echo "Match Date: " . $matchDate . "<br>";
        $res = sqlQuerySingle("select id from l_season where startdate <= '{$matchDate}' and fdate >= '{$matchDate}'");
        if ($res) {
            $season_id = $res->id;
            $INDEX_ZELO = 0;
            $INDEX_MATCHES = 1;
            $INDEX_WIN = 2;
            $INDEX_LOST = 3;
            $INDEX_DRAW = 4;
            $dataA = array();
            $dataB = array();
            $dataA[$INDEX_ZELO] = 0;
            $dataA[$INDEX_MATCHES] = 0;
            $dataA[$INDEX_WIN] = 0;
            $dataA[$INDEX_LOST] = 0;
            $dataA[$INDEX_DRAW] = 0;
            $dataB[$INDEX_ZELO] = 0;
            $dataB[$INDEX_MATCHES] = 0;
            $dataB[$INDEX_WIN] = 0;
            $dataB[$INDEX_LOST] = 0;
            $dataB[$INDEX_DRAW] = 0;
            // query data for team A
            $res = sqlQuerySingle("select 1 from l_teamscore where team = {$rowA->id} and season = {$season_id}");
            if (!$res || !mysql_fetch_assoc($res)) {
                sqlQuery("insert into l_teamscore (team,season,tsedit,tsmatch) values ({$rowA->id},{$season_id},'{$now}','{$tsActStr}')");
            }
            $res = sqlQuerySingle("select won,lost,draw,matches,zelo from l_teamscore where team = {$rowA->id} and season = {$season_id}");
            if ($res) {
                $dataA[$INDEX_ZELO] = $res->zelo;
                $dataA[$INDEX_MATCHES] = $res->matches + 1;
                $dataA[$INDEX_WIN] = $res->won;
                $dataA[$INDEX_LOST] = $res->lost;
                $dataA[$INDEX_DRAW] = $res->draw;
            }
            // query data for team B
            $res = sqlQuerySingle("select 1 from l_teamscore where team = {$rowB->id} and season = {$season_id}");
            if (!$res) {
                sqlQuery("insert into l_teamscore (team,season,tsedit,tsmatch) values ({$rowB->id},{$season_id},'{$now}','{$tsActStr}')");
            }
            $res = sqlQuerySingle("select won,lost,draw,matches,zelo from l_teamscore where team = {$rowB->id} and season = {$season_id}");
            if ($res) {
                $dataB[$INDEX_ZELO] = $res->zelo;
                $dataB[$INDEX_MATCHES] = $res->matches + 1;
                $dataB[$INDEX_WIN] = $res->won;
                $dataB[$INDEX_LOST] = $res->lost;
                $dataB[$INDEX_DRAW] = $res->draw;
            }
            // update teams seasonal elo rating
            section_entermatch_calculateRating($scoreA, $scoreB, $dataA[$INDEX_ZELO], $dataB[$INDEX_ZELO], &$newA, &$newB);
            $dataA[$INDEX_ZELO] = $newA;
            $dataB[$INDEX_ZELO] = $newB;
            // update team score
            // - this is the place to change for using score diff n points too i think
            if ($scoreA > $scoreB) {
                // Team A wins
                $dataA[$INDEX_WIN]++;
                $dataB[$INDEX_LOST]++;
            } else {
                if ($scoreA < $scoreB) {
                    // this should not happen, since it is sorted first
                    $dataA[$INDEX_LOST]++;
                    $dataB[$INDEX_WIN]++;
                } else {
                    // Team A wins
                    $dataA[$INDEX_DRAW]++;
                    $dataB[$INDEX_DRAW]++;
                }
            }
            sqlQuery("update l_teamscore \n                  set won     = {$dataA[$INDEX_WIN]},\n                      lost    = {$dataA[$INDEX_LOST]},\n                      draw    = {$dataA[$INDEX_DRAW]},\n                      matches = {$dataA[$INDEX_MATCHES]},   \n                      zelo    = {$dataA[$INDEX_ZELO]},\n                      tsedit  = '{$now}',\n                      tsmatch = '{$matchDate}'\n                  where team  = {$rowA->id} and season = {$season_id}");
            sqlQuery("update l_teamscore \n                  set won     = {$dataB[$INDEX_WIN]},\n                      lost    = {$dataB[$INDEX_LOST]},\n                      draw    = {$dataB[$INDEX_DRAW]},\n                      matches = {$dataB[$INDEX_MATCHES]},   \n                      zelo    = {$dataB[$INDEX_ZELO]},\n                      tsedit  = '{$now}',\n                      tsmatch = '{$matchDate}'\n                  where team  = {$rowB->id} and season = {$season_id}");
        }
    }
    return $season_id;
}