Beispiel #1
0
 public function showTeam($teamid)
 {
     global $tmpl;
     global $db;
     $team = new team($teamid);
     if (!$team->exists()) {
         $tmpl->setTemplate('NoPerm');
         return;
     }
     if (!$tmpl->setTemplate('teamSystemProfile')) {
         $tmpl->noTemplateFound();
         die;
     }
     // FIXME: implement something to avoid hardcoded paths
     $tmpl->assign('pmLink', '../PM/?add&teamid=' . $teamid);
     $tmpl->assign('status', $team->getStatus());
     $tmpl->assign('title', 'Team ' . htmlent($team->getName()));
     // the team's leader
     $teamLeader = $team->getLeaderId();
     $teamData = array();
     $teamData['profileLink'] = './?profile=' . $team->getID();
     $teamData['name'] = $team->getName();
     $teamData['score'] = $team->getScore();
     $teamData['scoreClass'] = $this->rankScore($teamData['score']);
     $teamData['matchSearchLink'] = '../Matches/?search_string=' . $teamData['name'] . '&search_type=team+name' . '&search_result_amount=200' . '&search=Search';
     $teamData['matchCount'] = $team->getMatchCount();
     $teamData['memberCount'] = $team->getMemberCount();
     $teamData['leaderLink'] = '../Players/?profile=' . $team->getLeaderId();
     $teamData['leaderName'] = (new \user($team->getLeaderId()))->getName();
     $teamData['activityNew'] = $team->getActivityNew();
     $teamData['activityOld'] = $team->getActivityOld();
     $teamData['created'] = $team->getCreationTimestampStr();
     $teamData['wins'] = $team->getMatchCount('won');
     $teamData['draws'] = $team->getMatchCount('draw');
     $teamData['losses'] = $team->getMatchCount('lost');
     $teamData['logo'] = $team->getAvatarURI();
     $tmpl->assign('teamDescription', $team->getDescription());
     $tmpl->assign('team', $teamData);
     $tmpl->assign('teamid', $teamid);
     $tmpl->assign('canPMTeam', \user::getCurrentUserLoggedIn() && \user::getCurrentUserId() > 0 ? true : false);
     // tell template if user can edit this team
     $tmpl->assign('canEditTeam', \user::getCurrentUserLoggedIn() && \user::getCurrentUserId() === $teamLeader || \user::getCurrentUser()->getPermission('allow_edit_any_team_profile'));
     // tell template if user can delete this team
     // either user has deletion permission for team
     // or user is leader of team and there are one or less members in team
     $tmpl->assign('canDeleteTeam', $team->getStatus() !== 'deleted' && (\user::getCurrentUser()->getPermission('team.allowDelete ' . $team->getID()) || \user::getCurrentUser()->getPermission('allow_delete_any_team') || \user::getCurrentUserId() === $team->getLeaderId()));
     $showMemberActionOptions = false;
     if (\user::getCurrentUserId() === $teamLeader || \user::getCurrentUser()->getPermission('allow_kick_any_team_members')) {
         $showMemberActionOptions = true;
     }
     $members = array();
     $memberids = $team->getUserIds();
     foreach ($memberids as $memberid) {
         $user = new \user($memberid);
         $member = array();
         // rename db result fields and assemble some additional informations
         // use a temporary array for better readable (but slower) code
         if (!$showMemberActionOptions && \user::getCurrentUserId() === $memberid) {
             $showMemberActionOptions = true;
         }
         $member['profileLink'] = '../Players/?profile=' . $user->getID();
         $member['userName'] = $user->getName();
         $member['permissions'] = $teamLeader === $memberid ? 'Leader' : 'Standard';
         if ($country = $user->getCountry()) {
             $member['countryName'] = $country->getName();
             if (strlen($country->getFlag()) > 0) {
                 $member['countryFlag'] = $country->getFlag();
             }
         }
         $member['joined'] = $user->getJoinTimestampStr();
         $member['last_login'] = $user->getLastLoginTimestampStr();
         // show leave/kick links if permission is given
         // a team leader can neither leave or be kicked
         // a leader must first give someone else leadership to leave
         if ((\user::getCurrentUserId() === $teamLeader || \user::getCurrentUser()->getPermission('allow_kick_any_team_members') || \user::getCurrentUserId() === $user->getID()) && $user->getID() !== $teamLeader) {
             $member['removeLink'] = './?remove=' . $user->getID() . '&team=' . $teamid;
             if (\user::getCurrentUserId() === $user->getID()) {
                 $member['removeDescription'] = 'Leave team';
             } else {
                 $member['removeDescription'] = 'Kick member from team';
             }
         }
         // append current member data
         $members[] = $member;
         unset($user);
     }
     $tmpl->assign('members', $members);
     $tmpl->assign('showMemberActionOptions', $showMemberActionOptions);
     // show last entered matches
     $matches = array();
     // show available options if any available
     $allowEdit = \user::getCurrentUser()->getPermission('allow_edit_match');
     $allowDelete = \user::getCurrentUser()->getPermission('allow_delete_match');
     $tmpl->assign('showMatchActionOptions', $allowEdit || $allowDelete);
     $tmpl->assign('allowEdit', $allowEdit);
     $tmpl->assign('allowDelete', $allowDelete);
     // get match data
     // sort the data by id to find out if abusers entered a match at a long time in the past
     $query = $db->prepare('SELECT `timestamp`,`team1_id`,`team2_id`,' . '(SELECT `name` FROM `teams` WHERE `id`=`team1_id`) AS `team1_name`' . ',(SELECT `name` FROM `teams` WHERE `id`=`team2_id`) AS `team2_name`' . ',`team1_points`,`team2_points`,`userid`' . ',(SELECT `users`.`name` FROM `users`' . ' WHERE `users`.`id`=`matches`.`userid`)' . ' AS `username`' . ',`matches`.`id`' . ' FROM `matches` WHERE `matches`.`team1_id`=?' . ' OR `matches`.`team2_id`=?' . ' ORDER BY `id` DESC LIMIT 0,10');
     $db->execute($query, array($teamid, $teamid));
     while ($row = $db->fetchRow($query)) {
         // rename db result fields and assemble some additional informations
         // use a temporary array for better readable (but slower) code
         $prepared = array();
         $prepared['time'] = $row['timestamp'];
         $prepared['team1Link'] = '../Teams/?profile=' . $row['team1_id'];
         $prepared['team2Link'] = '../Teams/?profile=' . $row['team2_id'];
         $prepared['team1Name'] = $row['team1_name'];
         $prepared['team2Name'] = $row['team2_name'];
         $prepared['score1'] = $row['team1_points'];
         $prepared['score2'] = $row['team2_points'];
         $prepared['lastModById'] = $row['userid'];
         $prepared['lastModByName'] = $row['username'];
         $prepared['lastModByLink'] = '../Players/?profile=' . $prepared['lastModById'];
         if ($allowEdit) {
             $prepared['editLink'] = '../Matches/?edit=' . $row['id'];
         }
         if ($allowDelete) {
             $prepared['deleteLink'] = '../Matches/?delete=' . $row['id'];
         }
         $matches[] = $prepared;
     }
     $tmpl->assign('matches', $matches);
     // invitation data visible
     // for team members
     // for users who can issue any invitation
     if (\user::getCurrentUser()->getMemberOfTeam($teamid) || \user::getCurrentUser()->getPermission('allow_invite_in_any_team')) {
         $invitationData = array();
         $invitations = invitation::getInvitationsForTeam($teamid);
         foreach ($invitations as $invitation) {
             $invitationUser = $invitation->getUsers()[0];
             $invitationData[] = array('userName' => $invitationUser->getName(), 'profileLink' => '../Players/?profile=' . $invitationUser->getID(), 'expiration' => $invitation->getExpiration());
         }
         $tmpl->assign('invitations', $invitationData);
     }
 }
Beispiel #2
0
    public function showOpponentStats($teamid)
    {
        global $tmpl;
        global $user;
        global $db;
        if (!$tmpl->setTemplate('teamSystemOpponentStats')) {
            $tmpl->noTemplateFound();
            die;
        }
        $tmpl->assign('title', 'Team opponent statistics');
        $tmpl->assign('teamid', $teamid);
        // get team name for specified teamid
        $params = array(':teamid' => array($teamid, PDO::PARAM_INT));
        $query = $db->prepare('SELECT `name` FROM `teams` WHERE `id`=:teamid LIMIT 0,1');
        if (!$db->execute($query, $params)) {
            $tmpl->assign('teamName', 'Error: No team name found for specified teamid.');
            $tmpl->display();
            $db->logError('FATAL ERROR: Invalid query to find out team name in ' . __FILE__ . ': function: showOpponentStats');
            die;
        }
        // if teamName not set, template has to present an error and stop output, too
        if ($row = $db->fetchRow($query)) {
            $tmpl->assign('teamName', $row['name']);
        } else {
            $tmpl->display();
            die;
        }
        $db->free($query);
        unset($row);
        // collect team opponent informations for specified teamid
        $teamOpponents = array();
        $query = $db->prepare('SELECT * FROM `matches` ' . 'WHERE `team1_id`=:teamid OR `team2_id`=:teamid');
        $db->execute($query, $params);
        $stats = array();
        while ($row = $db->fetchRow($query)) {
            $this->addToOpponentTeamList($teamid, $row, $stats);
        }
        $db->free($query);
        unset($row);
        foreach ($stats as $opponentTeam) {
            $opponentTeam->winRatio = round($opponentTeam->won / $opponentTeam->matchCount * 100, 2);
            $query = $db->prepare('SELECT * FROM `teams_overview`
									  JOIN `teams_profile` ON `teams_overview`.`teamid`=`teams_profile`.`teamid`
									  WHERE `teams_overview`.`teamid`=:opponentid LIMIT 1');
            $db->execute($query, array(':opponentid' => array($opponentTeam->teamId, PDO::PARAM_INT)));
            while ($nameRow = $db->fetchRow($query)) {
                $team = new team($nameRow['teamid']);
                $opponentTeam->score = $nameRow['score'];
                $opponentTeam->scoreClass = $this->rankScore($team->getScore());
                $opponentTeam->matchSearchLink = '../Matches/?search_string=' . $team->getName() . '&search_type=team+name' . '&search_result_amount=20' . '&search=Search';
                unset($team);
            }
            $opponentTeam->profileLink = './?profile=' . $opponentTeam->teamId;
            $opponentTeam->memberCount = $nameRow['member_count'];
            $opponentTeam->activityNew = $nameRow['activityNew'];
            $opponentTeam->activityOld = $nameRow['activityOld'];
            $opponentTeam->created = $nameRow['created'];
            if (empty($opponentTeam->name)) {
                $opponentTeam->name = '<span style="font-style:bold;">Could not resolve team name</span>';
            }
            $db->free($query);
        }
        // sort data
        // check if sort column is set and exists in dataset
        if (isset($_GET['sort']) && isset($opponentTeam->{$_GET['sort']})) {
            // sort ascending by default
            $order = isset($_GET['order']) && $_GET['order'] === 'desc' ? 'desc' : 'asc';
            // use user defined sorting function, utilising a closure
            uasort($stats, $this->sortOpponents($_GET['sort'], $order));
            // pass sorting infos to template
            $tmpl->assign('sortCol', $_GET['sort']);
            $tmpl->assign('sortOrder', $order === 'desc' ? 'desc' : 'asc');
        }
        // pass the opponent data to template
        $tmpl->assign('teamOpponents', $stats);
    }