public function next() { $q_id = Param::get('id'); $selection_id = Param::get('selection'); $question = Question::get(); $answer = Answer::get($q_id); $this->set(['question' => $question, 'answer' => $answer, 'selection_id' => $selection_id]); $this->render('index'); }
function run_handler(&$RES, $test, $answered_question_id, $answer_id) { $t = DBkitModel::get("SELECT MAX(`order`) AS question_count FROM questions WHERE `test_id` = %d", $test->id); $question_count = $t->question_count; $action = next_action($RES, $question_count); if ($action == 'random') { $action = array(1, $question_count); } if ($action == 'next') { $action = $RES->question_ord + 1; } if (is_integer($action) && $action > $question_count) { $action = 'finish'; } $answered_question_ids = collect_attrs($RES->answers, 'question_id'); $id_cond = empty($answered_question_ids) ? "TRUE" : "`id` NOT IN ?"; if (is_integer($action)) { $t = DBkitModel::get("SELECT MIN(`order`) AS `order` FROM `questions` WHERE `test_id`=%d AND `order`>=%d AND {$id_cond}", $test->id, $action, $answered_question_ids); if (!$t) { // TODO: what to do when the question_ord returned by the handler does not exist? } $question = Question::get("WHERE `order` = %d AND `test_id` = %d LIMIT 1", $t->order, $test->id); } else { if (is_array($action)) { $t = DBkitModel::query("SELECT `id` FROM `questions` WHERE `test_id`=%d AND `order` BETWEEN %d AND %d AND {$id_cond}", $test->id, $action[0], $action[1], $answered_question_ids); if (empty($t)) { $action = 'finish'; } else { $t = $t[mt_rand(0, count($t) - 1)]; $question = Question::get("WHERE `id` = %d AND `test_id` = %d LIMIT 1", $t->id, $test->id); } } } if ($question) { $RES->question_id = $question->id; $RES->question_ord = $question->order; $RES->question_no++; if (!is_null($answered_question_id)) { stat_question_answered($RES->session_id, $test->id, $RES->partner_id, $RES->day, $answered_question_id, $answer_id, $RES->question_id, $RES->paid); } return $question; } if ($action == 'finish') { $RES->finished = true; if ($RES->paid) { $RES->sms_chal = random_string(REATESTER_SMS_CHAL_LENGTH); $RES->sms_resp = random_string(REATESTER_SMS_RESP_LENGTH); } else { $RES->sms_chal = $RES->sms_resp = null; } stat_test_finished($RES->session_id, $test->id, $RES->partner_id, $RES->day, $answered_question_id, $answer_id, $RES->paid, $RES->sms_chal, $RES->sms_resp); redirect("/tests/{$test->id}/"); die; } die("Internal error: invalid handler action '{$action}'"); }
function get_question($employee_id, $question_no = '') { $data = array(); $q = new Question(); $q->where('employee_id', $employee_id); $q->where('question_no', $question_no); $q->order_by('question_no'); $q->get(); return $q; }
if (!$answer->is_empty()) { $answer->normalize(); $answer->put(); } } jsdie("questionSaved", $question->id, $is_new); } if ($is_new) { $title = "Новый вопрос"; $question = new Question(); $question->id = 'new'; $question->test_id = $_REQUEST['test_id']; $question->wakeup(); $answers = array(); } else { if (!($question = Question::get("WHERE id = %s", $id))) { redirect("/", "Извините, этот вопрос уже удален."); } $title = "{$question->text}"; $answers = Answer::query("WHERE question_id = %s ORDER BY `order`", $question->id); } $max_answer_order = 0; foreach ($answers as $answer) { $max_answer_order = max($max_answer_order, $answer->order); } $to_add = max(3, 5 - count($answers)); for ($i = 1; $i <= $to_add; $i++) { $answer = new Answer(); $answer->order = $max_answer_order + $i; $answer->id = "new" . $i; $answer->wakeup();
?> <a href="meetings/report/<?php echo $meeting->id; ?> " class="btn">ดูรายงาน</a><br /><br /> <?php } ?> <?php if (mysql_to_unix($meeting->close_date) > time()) { ?> <?php $question = new Question(); $question->where('meeting_id', $meeting->id); $question->where('(user_id = ' . $this->session->userdata('id') . ' or r_id = ' . $this->session->userdata('id') . ')'); $question->get(); if (!$question->exists()) { ?> <a href="questions/form/<?php echo $meeting->id; ?> " class="btn">ลงทะเบียน</a> <?php } ?> <?php } ?> </td> </tr> <?php
} break; case 'question': switch ($action) { case 'add': $_POST['question'] = array_key_exists('question', $_POST) ? $_POST['question'] : ''; $_POST['correct'] = array_key_exists('correct', $_POST) ? $_POST['correct'] : null; $_POST['answer-explanation'] = array_key_exists('answer-explanation', $_POST) ? $_POST['answer-explanation'] : ''; $alternatives = array(); for ($i = 0; $i < 4; $i++) { $alternatives[] = $_POST['alt-' . $i]; } $response = Question::add($_POST['question'], $alternatives, $_POST['correct'], $_POST['answer-explanation'], $_POST['gid']); break; case 'get': $response = Question::get($params[0], $params[1]); break; case 'my': $params[0] = count($params) >= 1 ? $params[0] : null; $response = Question::getMine($params[0]); break; case 'answer': $_POST['qid'] = array_key_exists('qid', $_POST) ? $_POST['qid'] : ''; $_POST['aid'] = array_key_exists('aid', $_POST) ? $_POST['aid'] : ''; $response = Question::answer($_POST['qid'], $_POST['aid']); break; } break; // end $model } header(200);
public function getAdminQuestions() { $questions = Question::get(); return View::make('admin.questions.all')->with('questions', $questions); }
function init() { $question = new Question(); $func = array_shift($this->param); if (is_numeric($func)) { $this->id = $func; } else { if ($func != '') { $_SERVER['REQUEST_METHOD'] = 'POST'; $course_id = array_shift($this->param); Security::checkEditor($course_id); switch ($func) { case 'save': $data['course_id'] = $course_id; $data['type_id'] = $_POST['type_id']; $data['data'] = $_POST['data']; $data['count'] = $_POST['count']; $data['answer'] = $_POST['answer']; $id = $_POST['id']; try { $question->update($id, $data); } catch (Exception $e) { } header('Location: /admin_questions/' . $data['course_id']); exit; break; case 'delete': try { $question_id = array_shift($this->param); $question->delete($question_id); echo "ok"; } catch (Exception $e) { echo $e; } header('Location: /admin_questions/' . $course_id); exit; break; case 'find': try { $data = array('course_id' => $course_id, 'type_id' => 0, 'data' => '', 'answer' => ''); $q_id = $question->add($data); $data['id'] = $q_id; echo json_encode($data); } catch (Exception $e) { echo $e; } exit; break; case 'load': try { $question_id = array_shift($this->param); $data = $question->get(array('course_id' => $course_id, 'id' => $question_id)); echo json_encode($data); } catch (Exception $e) { echo $e; } exit; break; default: } } else { header('Location: /404'); exit; } } }
/** * Display a listing of the resource. * * @return Response */ public function index() { return Response::json(Question::get(), 200); }
<?php include '../lib/common.inc.php'; $id = $_REQUEST['question_id']; if (!($question = Question::get("SELECT **, (SELECT count(*) FROM answers WHERE question_id=questions.id) AS answer_count FROM _T_ WHERE id = %s", $id))) { error_redirect("/", "Извините, этот вопрос уже удален."); } echo render_partial('question.haml', array('question' => $question));
function displayBody() { parent::displayBody(); $translator = new Translator(); $course = new Course(); $training = new Training(); $t_data = $training->get(array('exam_hash' => $this->exam_hash, 'user_id' => $_SESSION['user_id'])); $c_data = $course->get(array('id' => $t_data['course_id'])); foreach ($c_data as $key => $val) { $c_data[$key] = htmlspecialchars($val, ENT_QUOTES); } echo <<<EOF <div class="container-fluid"> <div class="col-lg-10 col-lg-offset-1" id="window"> \t<div class="row" > \t<div class="col-xs-10"> \t <h4>{$c_data[category_name]}</h4> \t <h2>{$c_data[name]}</h2> \t</div> \t<div class="col-xs-2 text-right" id="top_buttons"> \t <a href="#" id="fullscreen"><span class="glyphicon glyphicon-fullscreen"></span></a> \t <a href="#" id="inscreen" class="collapse"><span class="glyphicon glyphicon-remove"></span></a> \t</div> \t</div> EOF; try { $d2 = new DateTime('now'); $diff = $d2->diff(new DateTime($t_data['finished'])); $diff = $diff->format('%r%i'); if ($diff < 0) { throw new Exception("Time out", self::TIMEOUT); } $exam = new Exam(); $enum = $exam->enumerate(array('training_id' => $t_data['id']), intval($this->page), 1, 'id'); $cnt = $exam->getCount(array('training_id' => $t_data['id'])); $current = $this->page + 1; $back = $this->page > 0 ? $this->page - 1 : 0; $next = $this->page + 1; if (!$enum) { throw new Exception("Not found", self::NOTFOUND); } $e_data = $enum->current(); $question = new Question(); $q_data = $question->get(array('id' => $e_data['question_id'])); echo <<<EOF \t<div class="embed-responsive embed-responsive-16by9" id="fullscreen_media"> \t<p>{$translator->Question}: {$current} / {$cnt}</p> \t<p> {$translator->Time_remain}: {$diff}</p> \t{$q_data[data]} \t<hr> \t{$translator->Answer}: \t <form action="?" method="post"> \t <input type="hidden" name="id" value="{$e_data[id]}"> EOF; switch ($q_data['type_id']) { case Question::SINGLE: echo "<ol>"; for ($i = 1; $i <= $q_data['count']; $i++) { echo "<li><input type=\"radio\" name=\"answer\" value=\"{$i}\" " . ($i == $e_data['answer'] ? 'checked' : '') . "></li>" . NL; } echo "</ol>"; break; case Question::MULTI: echo "<ol>"; $e_data['answer'] = explode(',', $e_data['answer']); for ($i = 1; $i <= $q_data['count']; $i++) { echo "<li><input type=\"checkbox\" name=\"answer[]\" value=\"{$i}\" " . (in_array($i, $e_data['answer']) ? 'checked' : '') . "></li>" . NL; } echo "</ol>"; break; case Question::TEXT: echo "<input type=\"text\" name=\"answer\" value=\"{$e_data['answer']}\">" . NL; break; default: } $back = $this->page > 0 ? $this->page - 1 : 0; $next = $this->page + 1; echo <<<EOF \t <input type="submit" class="btn btn-primary"> \t </form> \t</div> EOF; } catch (Exception $e) { switch ($e->getCode()) { case self::TIMEOUT: echo <<<EOF <div class="bs-callout bs-callout-danger" id="callout-type-b-i-elems"> <h4>{$translator->Timeout}</h4> <p>{$translator->Timeout_Desc}</p> <p class="text-muted">{$translator->BackCourses}</p> </div> EOF; $training->update($t_data['id'], array('status_id' => Training::FAILED)); break; case self::NOTFOUND: echo <<<EOF <div class="embed-responsive embed-responsive-16by9" id="fullscreen_media"> <div class="bs-callout bs-callout-info" id="callout-type-b-i-elems"> <h4>{$translator->Not_found}</h4> <p>{$translator->Not_found_Desc}</p> <p class="text-muted">{$translator->BackExam}</p> </div> </div> EOF; break; default: echo $e; echo <<<EOF <div class="bs-callout bs-callout-danger" id="callout-type-b-i-elems"> <h4>{$translator->Error}</h4> <p>{$translator->Error_Desc}</p> <p class="text-muted">{$translator->BackExam}</p> </div> EOF; } // echo "<script>window.history.back();</script>"; } echo <<<EOF \t<nav id="bottom_buttons"> \t <ul class="pager"> \t <li class="previous"><a href="{$back}" id="back"><span aria-hidden="true">←</span> {$translator->Back}</a></li> \t <li class="top"><a href="0" id="top">{$translator->Top}</a>| \t\t<a href="/result/{$t_data[id]}" onclick='return confirm("{$translator->AreYouSure}");'>{$translator->Finish}</a></li> \t <li class="next"><a href="{$next}" id="next">{$translator->Next} <span aria-hidden="true">→</span></a></li> \t </ul> \t</nav> </div> </div> <!-- /container --> EOF; }