本文整理汇总了PHP中Player::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::model方法的具体用法?PHP Player::model怎么用?PHP Player::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateToken
public function validateToken($token, $player_id)
{
$check = Player::model()->findByAttributes(array('id' => $player_id, 'token' => $token));
if ($check) {
return true;
}
return false;
}
示例2: run
public function run()
{
if (Yii::app()->user->isGuest) {
$this->render('_menuGuest');
} else {
$player = Player::model()->findByAttributes(array('email' => Yii::app()->user->id));
$this->render('_menuPlayer', array('player' => $player));
}
}
示例3: getTournamentDetail
public static function getTournamentDetail($id)
{
if (!$id) {
return false;
}
$return = Yii::app()->cache->get(self::CACHE_PREFIX . $id);
if (!$return) {
$tournament = Tournament::model()->findByPk($id);
if (!$tournament) {
return false;
}
$return['t'] = $tournament;
if ($tournament->player_joined > 0) {
if (in_array($tournament->status, array('playing', 'ended', 'signing'))) {
//查询参赛者数据
$players_id = Tournament_join::model()->getDbConnection()->createCommand('select * from tournament_join where tid=' . $id)->queryAll();
$tmp = array();
$return['players_join'] = array();
foreach ($players_id as $v) {
$tmp[] = $v['uid'];
$return['players_join'][$v['uid']] = $v;
}
$players = Player::model()->findAll('id in(' . implode(',', $tmp) . ')');
//整理player的id对应
$players_arr = array();
foreach ($players_id as $v) {
$players_arr[$v['uid']] = $v['t_sn'];
}
$return['players'] = array();
foreach ($players as $p) {
$return['players'][$players_arr[$p->id]] = $p;
}
ksort($return['players']);
}
if (in_array($tournament->status, array('playing', 'ended'))) {
//查询对局数据
$games = Games::model()->findAll('tid=' . $id);
//整理对阵表
$games_table = array();
foreach ($games as $g) {
$x = $g->black_id;
$y = $g->white_id;
//如果是单循环,只填充右上的一半对阵表
if ($tournament->t_kind == 'single') {
if ($players_arr[$x] < $players_arr[$y]) {
list($x, $y) = array($y, $x);
}
}
$games_table[$players_arr[$y]][$players_arr[$x]] = $g;
}
$return['games_table'] = $games_table;
}
}
Yii::app()->cache->set(self::CACHE_PREFIX . $id, $return, 600);
}
return $return;
}
示例4: _userinfo
public function _userinfo()
{
if (!$this->userinfo) {
if (!Yii::app()->user->isGuest) {
$user_id = Yii::app()->user->getState('id');
if ($user_id) {
$this->userinfo = Player::model()->findByPk($user_id);
}
}
}
return $this->userinfo;
}
示例5: authenticate
public function authenticate()
{
$user = Player::model()->find('email=:user and password=:pass', array(':user' => $this->username, ':pass' => self::hashpwd($this->password)));
if ($user) {
$user->last_login_ip = MyController::getUserHostAddress();
$user->last_login_time = date('Y-m-d H:i:s');
$user->login_times++;
$user->save();
Yii::app()->user->setState('id', $user->id);
return true;
} else {
return false;
}
}
示例6: actionReg
public function actionReg()
{
$email = trim(Yii::app()->request->getParam('email'));
$nick = trim(Yii::app()->request->getParam('nickname'));
$password = trim(Yii::app()->request->getParam('passwd'));
$password2 = trim(Yii::app()->request->getParam('passwd2'));
$refer = trim(Yii::app()->request->getParam('refer', '/'));
if (!preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $email)) {
$this->json_return(false, '请输入一个格式正确的Email地址');
}
if (!$password || $password != $password2) {
$this->json_return(false, '2次输入的密码不一致');
}
if (!$nick) {
$this->json_return(false, '请填写昵称');
}
if (mb_strlen($nick, 'UTF-8') > 9) {
$this->json_return(false, '昵称长度请限制在9个字之内');
}
if (Player::model()->find('email=:email', array(':email' => $email))) {
$this->json_return(false, '这个Email已经被注册了,您是否已经注册过了呢?');
}
if (Player::model()->find('nickname=:nick', array(':nick' => $nick))) {
$this->json_return(false, '这个昵称已经被注册了,换一个吧');
}
$player = new Player();
$player->email = $email;
$player->nickname = $nick;
$player->password = MyUserIdentity::hashpwd($password);
$player->login_times = 0;
$player->b_win = 0;
$player->b_lose = 0;
$player->w_win = 0;
$player->w_lose = 0;
$player->draw = 0;
$player->reg_time = date('Y-m-d H:i:s');
$player->reg_ip = MyController::getUserHostAddress();
$player->last_login_time = date('Y-m-d H:i:s');
$player->last_login_ip = MyController::getUserHostAddress();
$player->score = Yii::app()->params['init_score'];
if ($player->save()) {
$identity = new MyUserIdentity($email, $password);
if ($identity->authenticate()) {
Yii::app()->user->login($identity, 3600);
$this->json_return(true, '恭喜您注册成功!', $refer);
}
}
$this->json_return(false, '注册失败啦,请与管理员联系。');
}
示例7: authenticate
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = Player::model()->findByAttributes(array('email' => $this->username));
if ($user === null) {
// No user was found!
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if (md5($this->password) !== $user->password) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
// User/pass match
$this->_id = $user->id;
$this->errorCode = self::ERROR_NONE;
}
}
return !$this->errorCode;
}
示例8: checkToChanging
public function checkToChanging()
{
$player = Player::model()->findByAttributes(array('email' => Yii::app()->user->id));
if ($this->validate()) {
if ($player->getSummExit() >= $this->summ) {
if ($player->setSummExitPlus(-$this->summ)) {
$player->setSummBuyPlus($this->summ * 1.1);
$this->redirect($this->createUrl('player/Myship'));
} else {
$this->addError('summ', 'Ошибка. Обмен не произошел!');
}
} else {
$this->addError('summ', 'Обмен не произошел, возможно не хватает средств.');
return false;
}
} else {
return false;
}
}
示例9: actionManageMatchGameByPlayer
/**
* Manages Player Results
* @param Integer $id
* @param Integer $playerId
*/
public function actionManageMatchGameByPlayer($id, $playerId)
{
$MATCH_TYPE = 2;
$ACTIVE = 1;
$model = $this->loadModel($id);
$playerModel = Player::model()->findByPK($playerId);
if ($playerModel === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
if (isset($_POST['PlayerResult'])) {
$players = $_POST['PlayerResult'];
foreach ($players as $playerResultPost) {
$catResult = isset($playerResultPost['RESULT_ID']) ? $playerResultPost['RESULT_ID'] : -1;
$matchId = isset($playerResultPost['MATCH_ID']) ? $playerResultPost['MATCH_ID'] : -1;
$playerResult = PlayerResult::model()->findByPK(array('RESULT_ID' => $catResult, 'PLAYER_ID' => $playerId, 'MATCH_ID' => $matchId));
if ($playerResult != null) {
$playerResult->attributes = $playerResultPost;
$playerResult->save();
} else {
throw new CHttpException(404, 'The requested page does not exist.');
}
}
$this->redirect(array('manage', 'id' => $matchId));
}
$catResult = new CatResult();
$catResult->TYPE_RESULT = $MATCH_TYPE;
$catResult->ACTIVE = $ACTIVE;
$catResults = array();
$catResults = $catResult->search()->getData();
$playerResults = array();
foreach ($catResults as $_catResult) {
$playerResult = PlayerResult::model()->findByPK(array('RESULT_ID' => $_catResult->ID, 'PLAYER_ID' => $playerId, 'MATCH_ID' => $id));
if ($playerResult === null) {
$playerResult = new PlayerResult();
$playerResult->MATCH_ID = $id;
$playerResult->PLAYER_ID = $playerId;
$playerResult->RESULT_ID = $_catResult->ID;
$playerResult->save();
}
$playerResults[] = $playerResult;
}
$this->renderPartial('_playerResultForm', array('model' => $model, 'playerModel' => $playerModel, 'playerResults' => $playerResults));
}
示例10: actionRun
/**
* Displays the contact page
*/
public function actionRun()
{
require __DIR__ . '/../../../vendor/autoload.php';
$evm = new EventManager();
$data = array();
$collect = function ($info) use(&$data) {
$data[] = $info;
};
$evm->on('game.run', $collect);
$evm->on('game.addplayer', $collect);
$evm->on('game.start', $collect);
$evm->on('game.turn', $collect);
$evm->on('game.end', $collect);
$evm->on('player.start', $collect);
$evm->on('player.attack', $collect);
$evm->on('player.defense', $collect);
$evm->on('player.damage', $collect);
$game = new Game($evm);
foreach (Player::model()->findAll() as $player) {
$game->addPlayer(new EPlayer($player->name, (int) $player->life, (int) $player->strong, (int) $player->speed, new EResource($player->resource->name, (int) $player->resource->attack, (int) $player->resource->defense, new Dice((int) $player->resource->dice)), $game));
}
$game->run(new Dice(20));
$this->render('run', array('data' => $data));
}
示例11: actionScorelog
public function actionScorelog()
{
$id = intval(Yii::app()->request->getParam('id'));
$player = Player::model()->findByPk($id);
if (!$id || !$player) {
throw new CHttpException(404);
}
$history = Score_log::model()->findAll("player_id={$id} order by id desc");
//TODO 分页
$this->pageTitle = '用户等级分历史记录:' . $player->nickname . ' ' . Yii::app()->params['title'];
$this->render('scorelog', array('player' => $player, 'history' => $history));
}
示例12: getLeaderBoardFriends
public function getLeaderBoardFriends($user_id, $friends, $quiz)
{
$sql = "SELECT derived.player_id, sum(derived.best_score) AS player_points \nFROM (\n SELECT tbl_game.quiz_id, tbl_game.player_id, max(tbl_game.player_points) AS best_score \n FROM `tbl_game` \n WHERE tbl_game.player_id IN {$friends} \n AND tbl_game.quiz_id = {$quiz}\n GROUP BY tbl_game.player_id\n) as derived \nGROUP BY derived.player_id\nORDER BY player_points DESC";
$players = Game::model()->findAllBySql($sql);
$arr = array();
// $player_id_arr = array();
// $player_points_arr = array();
foreach ($players as $item) {
$arr[$item->player_id] = $item->player_points;
// $player_points_arr
}
$player_point = null;
$position = array_search($user_id, array_keys($arr));
if ($position === FALSE) {
$position = null;
}
//echo $position; die;
if (isset($position)) {
$player_point = $arr[$user_id];
}
$returnArr = array();
// var_dump($player_point); die;
foreach ($players as $player) {
$itemArr = array();
$itemArr['player_info'] = Player::model()->findByPk($player->player_id);
$itemArr['player_points'] = $player->player_points;
$returnArr[] = $itemArr;
}
return array('items' => $returnArr, 'current_position' => $position, 'current_points' => $player_point);
}
示例13: actionOutsHighDartModal
public function actionOutsHighDartModal()
{
if (Yii::app()->request->isPostRequest) {
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
$message = 'success';
if (isset($_GET['data'])) {
$data = $_GET['data'];
$tournament_id = $data['tournament_id'];
$player_id = $data['player_id'];
$player = Player::model()->findByPk($player_id);
$outs = $player->getOuts($tournament_id);
$high_dart = $player->getHighDart($tournament_id);
}
echo CJSON::encode(array('status' => $message, 'outs' => $outs, 'high_dart' => $high_dart));
}
示例14: array
<div class="view">
<?php
//get player complement Data
$player = Player::model()->findByPk($data->PLAYER_ID);
$imgDel = CHtml::image(Yii::app()->request->baseUrl . '/images/del.png', '');
$imgEdit = CHtml::image(Yii::app()->request->baseUrl . '/images/update.png', '');
?>
<table>
<tr>
<td width="70%">
<b><?php
echo CHtml::encode($data->getAttributeLabel('ID'));
?>
:</b>
<?php
echo CHtml::link(CHtml::encode($data->PLAYER_ID), array('view', 'id' => $data->PLAYER_ID));
?>
<b><?php
echo CHtml::encode($player->getAttributeLabel('NAME'));
?>
:</b>
<?php
echo CHtml::encode($player->NAME);
?>
<br />
示例15: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Player::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}