/**
  * 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;
 }
Example #2
0
 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;
 }
Example #3
0
 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());
     }
 }
Example #4
0
 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;
 }
 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;
 }
Example #6
0
 public function setLastStepDate()
 {
     $game = Game::model()->findByPk(Yii::app()->session['gameId']);
     $game->lastStepDate = time();
     $game->save();
 }
 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));
     }
 }
Example #8
0
 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);
 }
 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;
 }