public function testDeletingCustomNewsCategoryWithPosts() { $news = News::addNews(StringMocks::SampleTitleOne, StringMocks::LargeContent, $this->player_with_create_perms->getId(), $this->newsCategory->getId()); $this->assertArrayLengthEquals($this->newsCategory->getNews(), 1); $this->newsCategory->delete(); $this->assertEquals('enabled', $this->newsCategory->getStatus()); $this->assertArrayContainsModel($this->newsCategory, NewsCategory::getCategories()); $this->wipe($news); }
public function loginAsTestUserAction(Session $session, Player $user) { if (!$user->isTestUser()) { throw new Exception("The player you specified is not a test user!"); } $session->set("playerId", $user->getId()); $session->set("username", $user->getUsername()); return $this->goHome(); }
/** * Perform a search on messages using Elasticsearch * * @param string $query The query string * @return Message[] The results of the search */ private function elasticSearch($query) { $finder = \Service::getContainer()->get('fos_elastica.finder.search'); $boolQuery = new Bool(); // We have only stored "active" messages and groups on Elasticsearch's // database, so there is no check for that again if ($this->player) { // Make sure that the parent of the message (i.e. the group that the // message belongs into) has the current player as its member $recipientQuery = new Term(); $recipientQuery->setTerm('members', $this->player->getId()); $parentQuery = new HasParent($recipientQuery, 'group'); $boolQuery->addMust($parentQuery); } $fieldQuery = new Match(); $fieldQuery->setFieldQuery('content', $query)->setFieldFuzziness('content', 'auto'); $boolQuery->addMust($fieldQuery); return $finder->find($boolQuery); }
/** * Only include matches where a specific team/player played * * @param Team|Player $participant The team/player which played the matches * @param string $result The outcome of the matches (win, draw or loss) * @return self */ public function with($participant, $result = null) { if (!$participant || !$participant->isValid()) { return $this; } if ($participant instanceof Team) { $team_a_query = "team_a = ?"; $team_b_query = "team_b = ?"; } elseif ($participant instanceof Player) { $team_a_query = "FIND_IN_SET(?, team_a_players)"; $team_b_query = "FIND_IN_SET(?, team_b_players)"; } else { throw new InvalidArgumentException("Invalid model provided"); } switch ($result) { case "wins": case "win": case "victory": case "victories": $query = "({$team_a_query} AND team_a_points > team_b_points) OR ({$team_b_query} AND team_b_points > team_a_points)"; break; case "loss": case "lose": case "losses": case "defeat": case "defeats": $query = "({$team_a_query} AND team_b_points > team_a_points) OR ({$team_b_query} AND team_a_points > team_b_points)"; break; case "draw": case "draws": case "tie": case "ties": $query = "({$team_a_query} OR {$team_b_query}) AND team_a_points = team_b_points"; break; default: $query = "{$team_a_query} OR {$team_b_query}"; } $this->conditions[] = $query; $this->parameters[] = $participant->getId(); $this->parameters[] = $participant->getId(); return $this; }
public function inviteAction(Team $team, Player $player, Player $me) { if (!$me->canEdit($team)) { throw new ForbiddenException("You are not allowed to invite a player to that team!"); } elseif ($team->isMember($player->getId())) { throw new ForbiddenException("The specified player is already a member of that team."); } elseif (Invitation::hasOpenInvitation($player->getId(), $team->getId())) { throw new ForbiddenException("This player has already been invited to join the team."); } return $this->showConfirmationForm(function () use($team, $player, $me) { $invite = Invitation::sendInvite($player->getId(), $me->getId(), $team->getId()); Service::getDispatcher()->dispatch(Events::TEAM_INVITE, new TeamInviteEvent($invite)); return new RedirectResponse($team->getUrl()); }, "Are you sure you want to invite {$player->getEscapedUsername()} to {$team->getEscapedName()}?", "Player {$player->getUsername()} has been invited to {$team->getName()}"); }
public function registerResult(Player $white, Player $black, $result) { $eloWhite = new Elo($white->getId(), $this->category); $eloBlack = new Elo($black->getId(), $this->category); if ($eloWhite->isProvisional()) { $adjustment = $this->getProvisionalAdjustment($eloBlack, $result); $eloWhite->appendProvisional($eloBlack->getElo() + $adjustment); } else { $adjustment = $this->getRatingAdjustmentFor($eloWhite, $eloBlack, $result); $eloWhite->setElo($eloWhite->getElo() + $adjustment); } $this->updateBlackElo($eloWhite, $eloBlack, $result); $eloWhite->commit(); $eloBlack->commit(); }
public function load() { $this->clear(); // Alfredo Rodriguez (Maryland) $player = new Player(); $player->setFirstName('Alfredo'); $player->setLastName('Rodriguez'); $player->setHeight(72); $player->setWeight(180); $player->setBats('R'); $player->setThrows('R'); $player->setHometown('Oak Hill, Va.'); $player->setCstvId(395839); $player->setNcaaId(993788); $player->save(); print_r(sprintf("Created Player: %s (%s)\n", $player->getName(), $player->getId())); }
/** * Make sure that a player can edit a conversation * * Throws an exception if a player is not an admin or the leader of a team * @throws HTTPException * @param Player $player The player to test * @param Group $group The team * @param string $message The error message to show * @return void */ private function assertCanEdit(Player $player, Group $group, $message = "You are not allowed to edit the discussion") { if ($group->getCreator()->getId() != $player->getId()) { throw new ForbiddenException($message); } }
/** * Returned signed in user or empty Player instance when not signed in. * @return Player */ public function getUser() { if (!isset($this->user)) { if (!$this->expired()) { $user = new Player($this->getUserId()); $this->user = $user->getId() ? $user : null; } if (!isset($this->user)) { $this->user = new Player(); } } return $this->user; }
/** * Exclude object from result * * @param Player $player Object to remove from the list of results * * @return PlayerQuery The current query, for fluid interface */ public function prune($player = null) { if ($player) { $this->addUsingAlias(PlayerPeer::ID, $player->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related Player object * * @param Player|PropelObjectCollection $player The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return PlayerCourtQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByPlayer($player, $comparison = null) { if ($player instanceof Player) { return $this->addUsingAlias(PlayerCourtPeer::PLAYER_ID, $player->getId(), $comparison); } elseif ($player instanceof PropelObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(PlayerCourtPeer::PLAYER_ID, $player->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByPlayer() only accepts arguments of type Player or PropelCollection'); } }
/** * Declares an association between this object and a Player object. * * @param Player $v * @return PlayerCourt The current object (for fluent API support) * @throws PropelException */ public function setPlayer(Player $v = null) { if ($v === null) { $this->setPlayerId(NULL); } else { $this->setPlayerId($v->getId()); } $this->aPlayer = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Player object, it will not be re-added. if ($v !== null) { $v->addPlayerCourt($this); } return $this; }
protected function setUp() { $this->connectToDatabase(); $this->owner = $this->getNewPlayer(); $this->key = ApiKey::createKey("Sample Key", $this->owner->getId()); }
$number_of_quests = 0; foreach ($config['site']['quests'] as $questName => $storageID) { $bgcolor = $number_of_rows++ % 2 == 1 ? $config['site']['darkborder'] : $config['site']['lightborder']; $number_of_quests++; $main_content .= '<TR BGCOLOR="' . $bgcolor . '"><TD WIDTH=95%>' . $questName . '</TD>'; if ($player->getStorage($storageID) === null) { $main_content .= '<TD><img src="images/false.png"/></TD></TR>'; } else { $main_content .= '<TD><img src="images/true.png"/></TD></TR>'; } } $main_content .= '</TABLE></td></tr></table><br />'; } $deads = 0; //deaths list $player_deaths = $SQL->query('SELECT ' . $SQL->fieldName('id') . ', ' . $SQL->fieldName('date') . ', ' . $SQL->fieldName('level') . ' FROM ' . $SQL->tableName('player_deaths') . ' WHERE ' . $SQL->fieldName('player_id') . ' = ' . $player->getId() . ' ORDER BY ' . $SQL->fieldName('date') . ' DESC LIMIT 10'); foreach ($player_deaths as $death) { $bgcolor = $number_of_rows++ % 2 == 1 ? $config['site']['darkborder'] : $config['site']['lightborder']; $deads++; $dead_add_content .= "<tr bgcolor=\"" . $bgcolor . "\"><td width=\"20%\" align=\"center\">" . date("j M Y, H:i", $death['date']) . "</td><td>"; $killers = $SQL->query('SELECT ' . $SQL->tableName('environment_killers') . '.' . $SQL->fieldName('name') . ' AS monster_name, ' . $SQL->tableName('players') . '.' . $SQL->fieldName('name') . ' AS player_name, ' . $SQL->tableName('players') . '.' . $SQL->fieldName('deleted') . ' AS player_exists FROM ' . $SQL->tableName('killers') . ' LEFT JOIN ' . $SQL->tableName('environment_killers') . ' ON ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('id') . ' = ' . $SQL->tableName('environment_killers') . '.' . $SQL->fieldName('kill_id') . ' LEFT JOIN ' . $SQL->tableName('player_killers') . ' ON ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('id') . ' = ' . $SQL->tableName('player_killers') . '.' . $SQL->fieldName('kill_id') . ' LEFT JOIN ' . $SQL->tableName('players') . ' ON ' . $SQL->tableName('players') . '.' . $SQL->fieldName('id') . ' = ' . $SQL->tableName('player_killers') . '.' . $SQL->fieldName('player_id') . ' WHERE ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('death_id') . ' = ' . $SQL->quote($death['id']) . ' ORDER BY ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('final_hit') . ' DESC, ' . $SQL->tableName('killers') . '.' . $SQL->fieldName('id') . ' ASC')->fetchAll(); $i = 0; $count = count($killers); foreach ($killers as $killer) { $i++; if ($i == 1) { if ($count <= 4) { $dead_add_content .= "killed at level <b>" . $death['level'] . "</b> by "; } elseif ($count > 4 and $count < 10) { $dead_add_content .= "slain at level <b>" . $death['level'] . "</b> by "; } elseif ($count > 9 and $count < 15) {
public function addPlayer(Player $player) { $this->array[$player->getId()] = $player->cloneMe(); //avoid collateral effects: when the object or array is an argument && it's saved in a structure }
foreach ($config['site']['quests'] as $questName => $storageID) { $bgcolor = $number_of_rows++ % 2 == 1 ? $config['site']['darkborder'] : $config['site']['lightborder']; $number_of_quests++; $main_content .= '<TR BGCOLOR="' . $bgcolor . '"><TD WIDTH=95%>' . $questName . '</TD>'; if ($player->getStorage($storageID) === null) { $main_content .= '<TD><img src="images/false.png"/></TD></TR>'; } else { $main_content .= '<TD><img src="images/true.png"/></TD></TR>'; } } $main_content .= '</TABLE></td></tr></table><br />'; } $deads = 0; //deaths list $player_deaths = new DatabaseList('PlayerDeath'); $player_deaths->setFilter(new SQL_Filter(new SQL_Filter(new SQL_Field('player_id'), SQL_Filter::EQUAL, $player->getId()), SQL_Filter::CRITERIUM_AND, new SQL_Filter(new SQL_Field('id', 'players'), SQL_Filter::EQUAL, new SQL_Field('player_id', 'player_deaths')))); $player_deaths->addOrder(new SQL_Order(new SQL_Field('time'), SQL_Order::DESC)); $player_deaths->setLimit(20); foreach ($player_deaths as $death) { $bgcolor = $number_of_rows++ % 2 == 1 ? $config['site']['darkborder'] : $config['site']['lightborder']; $deads++; $dead_add_content .= "<tr bgcolor=\"" . $bgcolor . "\"><td width=\"20%\" align=\"center\">" . date("j M Y, H:i", $death->getTime()) . "</td><td>Died at level " . $death->getLevel() . " by " . $death->getKillerString(); if ($death->getMostDamageString() != '' && $death->getKillerString() != $death->getMostDamageString()) { $dead_add_content .= ' and ' . $death->getMostDamageString(); } $dead_add_content .= "</td></tr>"; } if ($deads > 0) { $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="' . $config['site']['vdarkborder'] . '"><TD COLSPAN=2 CLASS=white><B>Character Deaths</B></TD></TR>' . $dead_add_content . '</TABLE><br />'; } if (!$player->getHideChar()) {
/** * {@inheritdoc} */ public function serialize() { return serialize(array('team' => $this->team->getId(), 'deleter' => $this->deleter->getId())); }
public function assignLeaderAction(Team $team, Player $me, Player $player) { $this->assertCanEdit($me, $team, "You are not allowed to change the leader of this team."); if (!$team->isMember($player->getId())) { throw new ForbiddenException("The specified player is not a member of {$team->getName()}"); } elseif ($team->getLeader()->getId() == $player->getId()) { throw new ForbiddenException("{$player->getUsername()} is already the leader of {$team->getName()}"); } return $this->showConfirmationForm(function () use($player, $team) { $event = new Event\TeamLeaderChangeEvent($team, $player, $team->getLeader()); $team->setLeader($player->getId()); Service::getDispatcher()->dispatch(Events::TEAM_LEADER_CHANGE, $event); return new RedirectResponse($team->getUrl()); }, "Are you sure you want to transfer the leadership of the team to <strong>{$player->getEscapedUsername()}</strong>?", "{$player->getUsername()} is now leading {$team->getName()}", "Appoint leadership"); }
/** * Send a confirmation e-mail to a player * @param Player $player The receiving player */ private function sendConfirmationMessage($player) { if ($player->getConfirmCode() === null) { // The player has no confirmation code, don't send them a message return; } $from = $this->container->getParameter('bzion.email.from'); $title = $this->container->getParameter('bzion.site.name'); if (!$from) { $this->getLogger()->addError('Unable to send verification e-mail message to player due to the "From:" address not being specified', array('player' => array('id' => $player->getId(), 'username' => $player->getUsername()))); return; } $message = Swift_Message::newInstance()->setSubject($title . ' Email Confirmation')->setFrom(array($from => $title))->setTo($player->getEmailAddress())->setBody($this->render('Email/confirm.txt.twig', array('player' => $player)))->addPart($this->render('Email/confirm.html.twig', array('player' => $player)), 'text/html'); $this->container->get('mailer')->send($message); $this->getFlashBag()->add('info', 'Please check your inbox in order to confirm your email address.'); }
public function isDrawer(Player $player) { return $this->drawer_id == $player->getId(); }
<?php if (!empty($_POST)) { require_once 'database.php'; require_once 'Player.php'; $data = filter_input_array(INPUT_POST); try { $player = new Player($db, $data['playerId']); $player->recordSpin($data); } catch (Exception $ex) { die(json_encode(['error' => $ex->getMessage()])); } echo json_encode(['PlayerID' => $player->getId(), 'Name' => $player->getName(), 'Credits' => $player->getCredits(), 'LifetimeSpins' => $player->getLifetimeSpins(), 'LifetimeAverageReturn' => $player->getLifetimeAverageReturn()]); }
public function testMiscMethods() { $this->team = Team::createTeam("Sample Team", $this->player->getId(), "Avatar", "Description"); $team = Team::get($this->team->getId()); $this->assertEquals("now", $team->getCreationDate()); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Player $obj A Player object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null PlayerPeer::$instances[$key] = $obj; } }
private function getUserWithElo($eloValue, $category = 1) { $pl = new Player(); $pl->setUsername(uniqid('user')); $pl->setPassword(uniqid('pass')); $pl->commit(); $elo = new Elo($pl->getId(), $category); $elo->setElo($eloValue); $elo->commit(); return $pl; }
/** * Remove a member from the discussion * * @todo * * @param Player|Team $member The member to remove * @return void */ public function removeMember($member) { if ($member instanceof Player) { $this->db->query("DELETE FROM `player_groups` WHERE `group` = ? AND `player` = ?", "ii", array($this->getId(), $member->getId())); } else { throw new Exception("Not implemented yet"); } }
//-----------------------------------------------------------------------------//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------//----------------------------------------------------------------------------- if ($action == 'change_nick') { if ($logged) { $player_n = $_REQUEST['name']; $new_nick = $_REQUEST['nick']; $player = new Player(); $player->find($player_n); $player_from_account = FALSE; if (strlen($new_nick) <= 30) { if ($player->isLoaded()) { $account_players = $account_logged->getPlayersList(); if (count($account_players)) { foreach ($account_players as $acc_player) { if ($acc_player->getId() == $player->getId()) { $player_from_account = TRUE; } } if ($player_from_account) { $player->setGuildNick($new_nick); $player->save(); $main_content .= 'Guild nick of player <b>' . htmlspecialchars($player->getName()) . '</b> changed to <b>' . htmlspecialchars($new_nick) . '</b>.'; $addtolink = '&action=show&guild=' . $player->getRank()->getGuildId(); } else { $main_content .= 'This player is not from your account.'; } } else { $main_content .= 'This player is not from your account.'; } } else {
$productionMod = new ProductionMod($productionModArr[0], $productionModArr[1], $productionModArr[2], $productionModArr[3], $productionModArr[4], $productionModArr[5], $productionModArr[6]); $productionMods[$productionMod->getId()] = $productionMod; if ($productionMod->getTargetClassId() == 'Building') { $productionModLinks[$productionMod->getTargetId()][] = $productionMod; } } $buildingsArr = $buildingConn->getAllBuildings(); foreach ($buildingsArr as $buildingArr) { $buildingName = $terms[$buildingArr[1]]->getString(); $buildingDescription = $terms[$buildingArr[13]]->getString(); $building = new Building($buildingArr[0], $buildingName, $buildingArr[2], $buildingArr[3], $buildingArr[4], $buildingArr[5], $buildingArr[6], explode(",", $buildingArr[7]), explode(",", $buildingArr[8]), explode(",", $buildingArr[9]), explode(",", $buildingArr[10]), $buildingArr[11], $buildingArr[12], $buildingDescription, $buildingArr[14], $buildingArr[15]); if (isset($productionModLinks[$building->getId()])) { $building->setProductionMods($productionModLinks[$building->getId()]); } $buildings[$building->getId()] = $building; } $staticData->setBuildings($buildings); $playersArr = $playerConn->getAllPlayers(); foreach ($playersArr as $playerArr) { $player = new Player($playerArr[0], $playerArr[1], $playerArr[2], $playerArr[3], $playerArr[4], $playerArr[5], $playerArr[6], $playerArr[7], explode(",", $playerArr[8]), $playerArr[9], $playerArr[10]); $players[$player->getId()] = $player; } $staticData->setPlayers($players); $resourcesArr = $resourceConn->getAllResources(); foreach ($resourcesArr as $resourceArr) { $resourceName = $terms[$resourceArr[1]]->getString(); $resource = new Resource($resourceArr[0], $resourceName, $resourceArr[2], $resourceArr[3], $resourceArr[4], $resourceArr[5]); $resources[$resource->getId()] = $resource; } $staticData->setResources($resources); $_SESSION['staticData'] = $staticData;
/** * Find out if a player belongs to any of the conversation's teams * * This does not take into account whether the player is a distinct member * of the conversation (i.e. they have been invited separately) * * @param Player $member The player to check * @return bool */ public function isTeamMember($member) { $query = $this->db->query("SELECT COUNT(*) as c FROM players\n INNER JOIN teams ON teams.id = players.team\n INNER JOIN team_conversations ON team_conversations.team = teams.id\n WHERE team_conversations.conversation = ?\n AND players.id = ?\n LIMIT 1", array($this->getId(), $member->getId())); return $query[0]['c'] > 0; }
private function getPlayerIdByName($name) { $player = new PlayerByName($name); if (!$player->getId()) { $p = new Player(); $p->setFullName($name); $p->setOnlinePlayer(0); $p->commit(); return $p->getId(); } return $player->getId(); }