public function get() { $messages = $this->messageController->getMessages($this::MESSAGE_KEY); //contestant take test only one time, so //if !admin && has-result >>> redirect to 'result' //(admin not blocked, need to review test-page) $contestant = Auth::user(); if ($contestant->id != 1 && $contestant->result != "") { return Redirect::to('result'); } //load random-question from database $chapters = Chapter::all(); $random_questions = array(); foreach ($chapters as $chapter) { //each chapter, load random-questions by chapter-rate //then store in $random_questions // if($chapter->rate != 0){//make sure chapter has question // $random_questions[] = $chapter->getQuestions->random($chapter->rate); // } if (count($chapter->getQuestions) > $chapter->rate) { $random_questions[] = $chapter->getQuestions->random($chapter->rate); } } //get timer from test option $test_options = TestOption::all(); $timer = $test_options[0]; return View::make('test-bootstrap', array('random_questions' => $random_questions, 'timer' => $timer, 'messages' => $messages)); }
/** * 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 = TestOption::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public static function getOptionValueByName($optionName) { $optionInfo = TestOption::model()->findByAttributes(array('option_name' => $optionName)); if ($optionInfo !== null) { return $optionInfo['option_value']; } else { return ''; } }
public function post() { //admin-navigation $admin_navigation = new AdminNavigation(); if ($admin_navigation->isNavigate()) { return $admin_navigation->goToN(); } //message-notification $messages = array(); //at this time, just one option in test-options, so $test_option = TestOption::first(); //'timer' if (Input::has($test_option->key)) { $test_option->value = Input::get($test_option->key); $test_option->save(); $messages[$test_option->key] = $test_option->key . ':saved'; $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } return Redirect::to('result'); }
public static function isSystemAdmin($userId) { $userInfo = TestUser::model()->findByPk($userId); $systemAdminStr = TestOption::model()->findByAttributes(array('option_name' => TestOption::SYSTEM_ADMIN)); $systemAdminArr = array(); if ($systemAdminStr !== null && !empty($systemAdminStr['option_value'])) { $systemAdminArr = CommonService::splitStringToArray(",", $systemAdminStr['option_value']); } if (in_array($userInfo['username'], $systemAdminArr)) { return CommonService::$TrueFalseStatus['TRUE']; } else { return CommonService::$TrueFalseStatus['FALSE']; } }