<?php class Stats_User extends TyperPage { function Stats_User() { parent::TyperPage(); //Typer_Auth::redirectGuest(); $this->status = ''; $this->content = ''; $this->q = new Queries; $this->db = new DB; $this->t=new Typer_Smarty(ROOT."layout/stats_user/"); } function getContent() { return $this->getFormular(); } function checkUser($user) { $sql = "SELECT * FROM styper_user WHERE userlogin = '{$user}'"; $res = $this->db->table ($sql); $this->User = $res[0]; return true; } else { $this->status = textSys('stats:TAKI_UZYTKOWNIK_NIE_ISTNIEJE'); return false; } } function checkRound() { if (!$this->roundId) { $sql = "SELECT roundid FROM styper_round WHERE roundactive = 1"; $roundId = $this->db->table($sql); $roundId = $roundId[0][0]; if (! $roundId) { $sql = "SELECT max(roundid) FROM styper_round"; $roundId = $this->db->table($sql); $roundId = $roundId[0][0]; } } return $roundId; } function getFormular() { $this->roundId = Verifier::verifyFromRequest(POSITIVE_CARDINAL_NUMBER, 'round', false); $user = Verifier::verifyFromRequest(NOT_NULL_STRING, 'user', false); if (($user && $this->checkUser($user)) || !$user) { $score = $this->_getScore(); $this->t->assign('rounds', $this->_getRoundsList()); $this->t->assign('types', $this->_getTypes()); $this->t->assign('score', $score); } $this->t->assign('user', $user); $this->t->assign('roundId', $this->roundId); $this->t->assign('STATUS', $this->status); $this->t->assign('LOGOUT', Typer_Auth::isUserLogged()); return $this->t->fetch('stats_user.ihtml'); } function _getScore() { $roundId = $this->roundId; if (! $roundId) { $roundId = $this->checkRound(); } $points = $this->q->getPoints(); if ( !$points) { return false; } if ( !$this->User) { $userData = Typer_Auth::getLoggedUserData(); } else { $userData = $this->User; } $score = 0; $sql = "SELECT * FROM styper_type t LEFT JOIN styper_match m ON t.matchid = m.matchid LEFT JOIN styper_round r ON r.roundid = m.roundid WHERE t.userid = '{$userData['userid']}' AND r.roundclosed = 1 AND r.roundid <= '{$roundId}' AND r.rounddeleted = 0 ORDER BY r.roundid"; $types = $this->db->table($sql); /* * rozliczenie za zgodnosc typu z wynikiem */ foreach ($types as $tkey => $tval) { continue; } if ($tval['matchhostscore'] == $tval['typehost'] && $tval['matchguestscore'] == $tval['typeguest']) { //echo "bullseye!"; $score += $points['shot']; } else if($tval['matchhostscore'] - $tval['typehost'] == $tval['matchguestscore'] - $tval['typeguest']) { //echo "bramka"; $score += $points['diff']; } else if(($tval['matchhostscore'] > $tval['matchguestscore']) && ($tval['typehost'] > $tval['typeguest']) || ($tval['matchhostscore'] < $tval['matchguestscore']) && ($tval['typehost'] < $tval['typeguest']) || ($tval['matchhostscore'] == $tval['matchguestscore']) && ($tval['typehost'] == $tval['typeguest'])) { //echo "strona"; $score += $points['side']; } if ($tval['matchspecial']) { $score += $points['round']; } } return $score; } function _getRoundsList() { $sql = "SELECT * FROM styper_round WHERE roundclosed = 1 AND roundactive = 0 AND rounddeleted = 0 ORDER BY roundid DESC"; $rounds = $this->db->table($sql); return $rounds; } function _getTypes() { if (! $this->User) { $userData = Typer_Auth::getLoggedUserData(); } else { $userData = $this->User; } $roundId = $this->roundId; if (!$roundId) { $sql = "SELECT *, m.matchid as matchno, h.teamname as hostname, g.teamname as guestname FROM styper_match m LEFT JOIN styper_team h ON h.teamid = m.matchhost LEFT JOIN styper_team g ON g.teamid = m.matchguest LEFT JOIN (SELECT * FROM styper_type WHERE userid = '{$userData['userid']}') t ON m.matchid = t.matchid LEFT JOIN styper_round r ON m.roundid = r.roundid WHERE r.roundclosed = 0 AND r.roundactive = 1"; $res = $this->db->table($sql); $this->status = textSys('stats:AKTUALNA_NIEPELNA_SYTUACJA'); return $res; } $sql = "SELECT *, m.matchid as matchno, h.teamname as hostname, g.teamname as guestname FROM styper_match m LEFT JOIN styper_team h ON h.teamid = m.matchhost LEFT JOIN styper_team g ON g.teamid = m.matchguest LEFT JOIN (SELECT * FROM styper_type WHERE userid = '{$userData['userid']}') t ON m.matchid = t.matchid LEFT JOIN styper_round r ON m.roundid = r.roundid WHERE m.roundid = '{$roundId}' AND r.roundclosed = 1 AND m.matchplayed = 1"; $types = $this->db->table($sql); return $types; } }
KotWButach - Przepraszam, już poprawiam.