예제 #1
0
파일: ApiKey.php 프로젝트: blast007/bzion
 /**
  * {@inheritdoc}
  */
 protected function assignResult($key)
 {
     $this->name = $key['name'];
     $this->owner = Player::get($key['owner']);
     $this->key = $key['key'];
     $this->status = $key['status'];
 }
예제 #2
0
 public function view(SS_HTTPRequest $request)
 {
     $params = $request->params();
     $game_id = $params['ID'];
     $game = Game::get()->filter('ID', $game_id)->first();
     $teams = $game->Teams();
     $allTeams = array();
     foreach ($teams as $team) {
         $teamArr = array();
         $player_one = Player::get()->filter('ID', $team->PlayerOne)->first();
         $player_two = Player::get()->filter('ID', $team->PlayerTwo)->first();
         $teamArr['Names'] = $player_one->Name . ' & ' . $player_two->Name;
         $teamArr['GamesPlayed'] = $team->getGamesPlayed();
         $teamArr['TeamID'] = $team->ID;
         if ($allTeams == array()) {
             $allTeams['TeamOne'] = $teamArr;
         } else {
             $allTeams['TeamTwo'] = $teamArr;
         }
     }
     $link = $this->Link();
     $data = new ArrayData(array('Teams' => $allTeams, 'ParentLink' => $link, 'Winner' => $game->Winner, 'Score' => $game->ScoreTeamOne . '-' . $game->ScoreTeamTwo));
     if ($data->getField('Teams') == array()) {
         $data = new ArrayData(array('Content' => 'There are no teams assigned to this game.', 'AddNewTeam' => '<a href="' . $link . 'assignteams/' . $game_id . '" class="btn btn-success">Assign a Team to this game</a>', 'ParentLink' => $this->Link()));
         Session::set('GameID', $game_id);
     }
     return $data->renderWith(array('Game', 'Page'));
 }
예제 #3
0
 public function newTeamForm()
 {
     $players = Player::get();
     $playerOne = DropdownField::create('PlayerOne', 'Player One', $players->map('ID', 'FirstName'));
     $playerTwo = DropdownField::create('PlayerTwo', 'Player Two', $players->map('ID', 'FirstName'));
     $fields = new FieldList($playerOne, $playerTwo);
     $actions = new FieldList(FormAction::create("doAddTeam")->setTitle("Add Team"));
     $required = new RequiredFields('PlayerOne', 'PlayerTwo');
     $form = Form::create($this, 'doAddTeam', $fields, $actions, $required);
     $form->setTemplate('forms/NewTeamForm');
     return $form;
 }
예제 #4
0
 public function doAddPlayer($data, Form $form)
 {
     $player_exists = Player::get()->filter(array('FirstName' => $data['FirstName'], 'Surname' => $data['Surname']))->count() > 0 ? true : false;
     if ($player_exists) {
         // todo
         // add error message because player already exists
         return $this->redirectBack();
     } else {
         $player = Player::create();
         $player->FirstName = $data['FirstName'];
         $player->Surname = $data['Surname'];
         $player->write();
         $redirectLink = $this->Link() . '?success=1';
         return $this->redirect($redirectLink);
     }
 }
예제 #5
0
파일: News.php 프로젝트: blast007/bzion
 /**
  * Get the last editor of the post
  * @return Player A Player object of the last editor
  */
 public function getLastEditor()
 {
     return Player::get($this->editor);
 }
예제 #6
0
파일: Controller.php 프로젝트: bchhun/bzion
 /**
  * Gets the currently logged in player
  * @return Player
  */
 public static function getMe()
 {
     return Player::get(self::getRequest()->getSession()->get('playerId'));
 }
예제 #7
0
파일: Message.php 프로젝트: allejo/bzion
 /**
  * Gets the creator of the message
  * @return Player An object representing the message's author
  */
 public function getAuthor()
 {
     return Player::get($this->player_from);
 }
예제 #8
0
 /**
  * Queries the database to get the team which a group of players belong to
  *
  * @param  int[] $players The IDs of players
  * @return Team  The team
  */
 private function getTeam($players)
 {
     $team = null;
     foreach ($players as $id) {
         $player = Player::get($id);
         if ($player->isTeamless()) {
             return Team::invalid();
         } elseif ($team == null) {
             $team = $player->getTeam();
         } elseif ($team->getId() != $player->getTeam()->getId()) {
             // This player is on a different team from the previous player!
             return Team::invalid();
         }
     }
     return $team;
 }
예제 #9
0
파일: Match.php 프로젝트: bchhun/bzion
 /**
  * Get the user who entered the match
  * @return Player
  */
 public function getEnteredBy()
 {
     return Player::get($this->entered_by);
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function unserialize($data)
 {
     $data = unserialize($data);
     $this->__construct(\Team::get($data['team']), \Player::get($data['deleter']));
 }
예제 #11
0
파일: Player.php 프로젝트: bchhun/bzion
 /**
  * Get a single player by their username
  *
  * @param  string $username The username to look for
  * @return Player
  */
 public static function getFromUsername($username)
 {
     return Player::get(self::fetchIdFrom($username, 'username', 's'));
 }
예제 #12
0
 /**
  * Send emails to a list of recipients
  *
  * @param  string $subject    The subject of the messages
  * @param  int[]  $recipients The IDs of the players to which the messages will be sent
  * @param  string $template   The twig template name for the e-mail body
  * @param  array  $params     Any extra parameters to pass to twig
  * @return void
  */
 public function sendEmails($subject, $recipients, $template, $params = array())
 {
     if (!$this->from) {
         return;
     }
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom(array($this->from => $this->siteTitle))->setBody($this->twig->render("Email/{$template}.txt.twig", $params))->addPart($this->twig->render("Email/{$template}.html.twig", $params), 'text/html');
     foreach ($recipients as $recipient) {
         $recipient = \Player::get($recipient);
         if (!$recipient->isVerified()) {
             continue;
         }
         $message->setTo($recipient->getEmailAddress());
         $this->mailer->send($message);
     }
 }
예제 #13
0
파일: Visit.php 프로젝트: allejo/bzion
 /**
  * Get the visiting player
  * @return Player
  */
 public function getPlayer()
 {
     return Player::get($this->player);
 }
예제 #14
0
파일: Invitation.php 프로젝트: bchhun/bzion
 /**
  * Get the sender of the invite
  *
  * @return Player
  */
 public function getSentBy()
 {
     return Player::get($this->sent_by);
 }
예제 #15
0
파일: Server.php 프로젝트: allejo/bzion
 /**
  * Get the owner of the server
  * @return Player
  */
 public function getOwner()
 {
     return Player::get($this->owner);
 }
예제 #16
0
파일: Team.php 프로젝트: allejo/bzion
 /**
  * Removes a member from the team
  *
  * @param  int  $id The id of the player to remove
  * @return void
  */
 public function removeMember($id)
 {
     if (!$this->isMember($id)) {
         throw new Exception("The player is not a member of that team");
     }
     $player = Player::get($id);
     $player->update("team", null);
     $this->update('members', --$this->members);
 }
예제 #17
0
파일: News.php 프로젝트: bchhun/bzion
 /**
  * Add a new news article
  *
  * @param string $subject    The subject of the article
  * @param string $content    The content of the article
  * @param int    $authorID   The ID of the author
  * @param int    $categoryId The ID of the category this article will be published under
  * @param string $status     The status of the article: 'published', 'disabled', or 'deleted'
  *
  * @internal param int $categoryID The ID of the category
  * @return News|bool An object representing the article that was just created or false if the article was not created
  */
 public static function addNews($subject, $content, $authorID, $categoryId = 1, $status = 'published')
 {
     $author = Player::get($authorID);
     // Only allow real players to post news articles and if the player posting has permissions to create new posts
     if ($author->isValid() && $author->hasPermission(Permission::PUBLISH_NEWS)) {
         return self::create(array('category' => $categoryId, 'subject' => $subject, 'content' => $content, 'author' => $authorID, 'editor' => $authorID, 'status' => $status), 'issiis', array('created', 'updated'));
     }
     return false;
 }
예제 #18
0
파일: TestCase.php 프로젝트: blast007/bzion
 /**
  * Clean-up all the database entries added during the test
  */
 public function tearDown()
 {
     foreach ($this->playersCreated as $id) {
         self::wipe(Player::get($id));
     }
 }
예제 #19
0
 public function getTeamNames()
 {
     $player_one = Player::get()->filter('ID', $this->PlayerOne)->first();
     $player_two = Player::get()->filter('ID', $this->PlayerTwo)->first();
     return $player_one->FirstName . ' & ' . $player_two->FirstName;
 }
예제 #20
0
파일: Page.php 프로젝트: bchhun/bzion
 /**
  * Get the user who created the page
  * @return Player The page's author
  */
 public function getAuthor()
 {
     return Player::get($this->author);
 }
예제 #21
0
파일: Ban.php 프로젝트: allejo/bzion
 /**
  * Add a new ban
  *
  * @param int         $playerID        The ID of the victim of the ban
  * @param int         $authorID        The ID of the player responsible for the ban
  * @param mixed|null $expiration      The expiration of the ban (set to NULL so that it never expires)
  * @param string      $reason          The full reason for the ban
  * @param string      $srvmsg          A summary of the ban to be displayed on server banlists (max 150 characters)
  * @param string[]    $ipAddresses     An array of IPs that have been banned
  * @param bool        $allowServerJoin Whether or not the player is allowed to join match servers
  *
  * @return Ban An object representing the ban that was just entered or false if the ban was not created
  */
 public static function addBan($playerID, $authorID, $expiration, $reason, $srvmsg = "", $ipAddresses = array(), $allowServerJoin = false)
 {
     $player = Player::get($playerID);
     if ($expiration !== null) {
         $expiration = TimeDate::from($expiration)->toMysql();
     } else {
         $player->markAsBanned();
     }
     // If there are no IPs to banned or no server ban message, then we'll allow the players to join as observers
     if (empty($srvmsg) || empty($ipAddresses)) {
         $allowServerJoin = true;
     }
     $ban = self::create(array('player' => $playerID, 'expiration' => $expiration, 'server_message' => $srvmsg, 'reason' => $reason, 'allow_server_join' => $allowServerJoin, 'author' => $authorID), array('created', 'updated'));
     if (is_array($ipAddresses)) {
         foreach ($ipAddresses as $ip) {
             $ban->addIP($ip);
         }
     } else {
         $ban->addIP($ipAddresses);
     }
     return $ban;
 }
예제 #22
0
 /**
  * Get the receiving player of the notification
  * @return Player
  */
 public function getReceiver()
 {
     return Player::get($this->receiver);
 }
예제 #23
0
<?php

require_once dirname(__FILE__) . "/_ajaxSetup.php";
$user = LoginManager::enforceLogin();
$data = json_decode($_POST['data']);
if (!isset($data->player) || !isset($data->time) || !isset($data->penalties)) {
    PageContent::ajaxError("missing parameters");
}
$player = Player::get($data->player->pid);
if (!$player) {
    PageContent::ajaxError("No pid found for player {$data->player->name}");
}
$time = new Time($player, $data->time, $data->penalties);
if (!$time->save()) {
    PageContent::ajaxError("error while saving");
}
PageContent::ajax();
예제 #24
0
 /**
  * Get the creator of the discussion
  *
  * @return Player
  */
 public function getCreator()
 {
     return Player::get($this->creator);
 }
예제 #25
0
<?php

require_once dirname(__FILE__) . "/_ajaxSetup.php";
$user = LoginManager::enforceLogin("graphs/login.php");
$data = json_decode($_POST['data']);
if (empty($data->players) || !property_exists($data, 'since') || !property_exists($data, 'until')) {
    PageContent::ajaxError("missing parameters");
}
$graphs = array();
foreach ($data->players as $pid) {
    $player = Player::get($pid);
    $times = $player->times($data->since, $data->until);
    $totalTime = 0;
    $totalPenalties = 0;
    $games = array();
    foreach ($times as $time) {
        /** @var $time Time */
        $totalTime += $time->time();
        $game = array('time' => $time->time(), 'date' => $time->date(), 'penalties' => array());
        foreach ($time->penalties() as $penalty) {
            /** @var $penalty Penalty */
            ++$totalPenalties;
            $game['penalties'] = array('time' => $penalty->time(), 'penaltyAmount' => $penalty->penaltyAmount());
        }
        $games[] = $game;
    }
    $average = count($games) == 0 ? 0 : floor($totalTime / count($games));
    $graphs[$player->pid()] = array('games' => $games, 'numGames' => count($games), 'average' => $average, "numPenalties" => $totalPenalties);
}
PageContent::ajax(array('graphs' => $graphs));