本文整理汇总了PHP中Player::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::isValid方法的具体用法?PHP Player::isValid怎么用?PHP Player::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player::isValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginAction
public function loginAction(Request $request, Player $me)
{
if ($me->isValid()) {
throw new ForbiddenException("You are already logged in!");
}
$query = $request->query;
$session = $request->getSession();
$token = $query->get("token");
$username = $query->get("username");
if (!$token || !$username) {
throw new BadRequestException();
}
// Don't check whether IPs match if we're on a development environment
$checkIP = !$this->isDebug();
$info = validate_token($token, $username, array(), $checkIP);
if (!isset($info)) {
throw new ForbiddenException("There was an error processing your login. Please go back and try again.");
}
$session->set("username", $info['username']);
$session->set("groups", $info['groups']);
$redirectToProfile = false;
if (!Player::playerBZIDExists($info['bzid'])) {
// If they're new, redirect to their profile page so they can add some info
$player = Player::newPlayer($info['bzid'], $info['username']);
$redirectToProfile = true;
} else {
$player = Player::getFromBZID($info['bzid']);
if ($player->isDeleted()) {
$player->setStatus('active');
}
}
$session->set("playerId", $player->getId());
$player->updateLastLogin();
$player->setUsername($info['username']);
Visit::enterVisit($player->getId(), $request->getClientIp(), gethostbyaddr($request->getClientIp()), $request->server->get('HTTP_USER_AGENT'), $request->server->get('HTTP_REFERER'));
$this->configPromoteAdmin($player);
if ($redirectToProfile) {
$profile = Service::getGenerator()->generate('profile_show');
return new RedirectResponse($profile);
} else {
return $this->goBack();
}
}
示例2: with
/**
* 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;
}
示例3: requireLogin
/**
* Assert that the user is logged in
* @throws HTTPException
* @param string $message The message to show if the user is not logged in
* @return void
*/
protected function requireLogin($message = "You need to be signed in to do this")
{
$me = new Player($this->getRequest()->getSession()->get('playerId'));
if (!$me->isValid()) {
throw new ForbiddenException($message);
}
}
示例4: addNews
/**
* 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 = new Player($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;
}