本文整理汇总了PHP中Game::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::model方法的具体用法?PHP Game::model怎么用?PHP Game::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game::model方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 $id the ID of the model to be loaded
* @return Game the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = Game::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例2: getBestScoreOfQuizByPlayer
public function getBestScoreOfQuizByPlayer($player_id, $quiz_id)
{
$criteria = new CDbCriteria();
$criteria->limit = 1;
$criteria->condition = "t.player_id = {$player_id} AND t.quiz_id = {$quiz_id}";
$criteria->order = "t.player_points DESC";
$data = Game::model()->find($criteria);
return $data;
}
示例3: actionGetBestGameQuizByPlayer
public function actionGetBestGameQuizByPlayer()
{
$request = Yii::app()->request;
try {
$player_id = StringHelper::filterString($request->getQuery('player_id'));
$quiz_id = StringHelper::filterString($request->getQuery('quiz_id'));
$data = Game::model()->getBestScoreOfQuizByPlayer($player_id, $quiz_id);
ResponseHelper::JsonReturnSuccess($data);
} catch (Exception $ex) {
ResponseHelper::JsonReturnError($ex->getMessage());
}
}
示例4: getSession
public static function getSession()
{
//если в куки есть сохраненная сессия и она есть в базе
if (isset($_COOKIE['gameId']) && Game::model()->gameExists($_COOKIE['gameId'])) {
$sessionId = $_COOKIE['gameId'];
} else {
//добавить новую игру в таблицу Game, записать в куки новый id
$sessionId = Game::model()->gameCreate();
setcookie('gameId', $sessionId);
}
Yii::app()->session['gameId'] = $sessionId;
return true;
}
示例5: actionCleanHistory
public function actionCleanHistory()
{
echo "Delete History";
$minDate = time() - self::ONE_WEEK;
$criteria = new CDbCriteria();
$criteria->condition = 'lastStepDate < :minDate';
$criteria->params = array(':minDate' => $minDate);
$oldGames = Game::model()->findAll($criteria);
foreach ($oldGames as $oldGame) {
echo "Delete game with id=" . $oldGame->id;
$oldGame->delete();
}
return true;
}
示例6: setLastStepDate
public function setLastStepDate()
{
$game = Game::model()->findByPk(Yii::app()->session['gameId']);
$game->lastStepDate = time();
$game->save();
}
示例7: actionGamesdataa
public function actionGamesdataa()
{
$this->logincheck();
$this->layout = 'homepage';
$gameDataModel = new GameData();
$id = Yii::app()->request->getQuery('id');
$condition = 'game_id = ' . $id . '';
$gameDataRes = $gameDataModel->findBYAttributes(array(), array('condition' => $condition));
if (!empty($gameDataRes)) {
$gameCat = Game::model()->findByPk($id);
$link = yii::app()->request->baseUrl . '/games/' . $gameCat->slug;
// breadcrumb
$bigmenudata = Bigmenu::model()->findByPk(18);
$breadCrumb = $gameDataRes->game_name;
$breadCrumb .= ' > <a href="' . yii::app()->request->baseUrl . '/games/' . $gameCat->slug . '">' . $gameCat->title . '</a>';
$breadCrumb .= ' > <a href="' . yii::app()->request->baseUrl . '/games">' . $bigmenudata->bigmenu_title . '</a>';
// end breadcrumb
$this->render('gamesdataa', array('link' => $link, 'gameDataRes' => $gameDataRes, 'breadcrumb' => $breadCrumb));
}
}
示例8: 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);
}
示例9: beforeSave
protected function beforeSave()
{
if (parent::beforeSave()) {
$this->gameId = Yii::app()->session['gameId'];
$this->cityId = City::model()->getCityIdByName($this->cityName);
Game::model()->setLastStepDate();
return true;
}
return false;
}