public function actionRank()
 {
     //$rank = GameEventReportDayModel::model()->getRank(10);
     $rank = array();
     $thread = GameEventThreadModel::model()->findAll();
     if ($thread) {
         foreach ($thread as $value) {
             $sql = "SELECT thread_id,point, user_phone,id,SEC_TO_TIME(TIME_TO_SEC(time(time_end))-TIME_TO_SEC(time(time_start))) as time_play\n\t\t\t\t\t\tFROM game_event_report_day\n\t\t\t\t\t\twhere thread_id=:thread_id\n\t\t\t\t\t\tORDER BY point DESC,time_play ASC\n\t\t\t\t\t\tlimit 1";
             $command = Yii::app()->db->createCommand($sql);
             $command->bindParam(':thread_id', $value->id, PDO::PARAM_INT);
             $rank[] = $command->queryRow();
         }
     }
     $rankSort = array();
     foreach ($rank as $value) {
         if ($value) {
             $rankSort[$value['point']] = $value;
         }
     }
     krsort($rankSort);
     $this->render('rank', array('rank' => $rankSort));
 }
 public function actionDeleteQuestion()
 {
     $threadId = Yii::app()->request->getParam('thread_id', null);
     $questionId = Yii::app()->request->getParam('question_id', null);
     $questionId = (int) $questionId;
     if ($threadId && $questionId) {
         $model = GameEventThreadModel::model()->findByPk($threadId);
         $oldQuestionList = explode(',', $model['question_list']);
         $newQuestionList = '';
         foreach ($oldQuestionList as $question) {
             $newQuestionList .= $questionId == (int) $question ? '' : ',' . trim($question);
         }
         $newQuestionList = $newQuestionList != '' ? substr($newQuestionList, 1) : '';
         $model->question_list = $newQuestionList;
         $model->save();
         $this->redirect(Yii::app()->createUrl("event/gameEventQuestion/view", array("id" => $threadId)));
     }
     /*
     		if(Yii::app()->request->isPostRequest)
     		{
     // we only allow deletion via POST request
     $this->loadModel($id)->delete();
     	
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if(!isset($_GET['ajax']))
     	$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
     		}
     		else
     throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
     */
 }
 public function actionAddQuestion()
 {
     $flag = true;
     $threadId = Yii::app()->request->getParam('thread_id', "");
     if (Yii::app()->getRequest()->ispostRequest) {
         $flag = false;
         $questionList = $_POST['cid'];
         $model = GameEventThreadModel::model()->findByPk($threadId);
         $oldQuestionList = explode(',', $model['question_list']);
         $newQuestionList = $model['question_list'] ? ',' . $model['question_list'] : '';
         foreach ($questionList as $question) {
             $newQuestionList .= in_array($question, $oldQuestionList) ? '' : ',' . $question;
         }
         $newQuestionList = $newQuestionList != '' ? substr($newQuestionList, 1) : '';
         $model->question_list = $newQuestionList;
         $model->save();
         //AdminCollectionItemModel::model()->addList($this->userId, $collect_id, $albumList, 'album');
     }
     if ($flag) {
         Yii::app()->user->setState('pageSize', 20);
         $questionModel = new GameEventQuestionModel();
         $questionModel->unsetAttributes();
         if (isset($_GET['GameEventQuestionModel'])) {
             $questionModel->attributes = $_GET['GameEventQuestionModel'];
         }
         $questionModel->setAttributes(array('status' => GameEventQuestionModel::PUBLISHED));
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
         $this->renderPartial('addQuestion', array('questionModel' => $questionModel, 'thread_id' => $threadId), false, true);
     }
 }