HTML and CSS Reference
In-Depth Information
protected function create_question( )
$room_id = $this->sanitize($_POST['room_id']);
$question = $this->sanitize($_POST['new-question']);
$output = $this->model->create_question($room_id, $question);
// Make sure valid output was returned
if (is_array($output) && isset($output['question_id'])) {
$room_id = $output['room_id'];
$question_id = $output['question_id'];
// Generates markup for the question (for realtime addition)
$view = new View('question');
$view->question = $question;
$view->room_id = $room_id;
$view->question_id = $question_id;
$view->vote_count = 1;
$view->answered_class = NULL;
$view->voted_class = NULL;
$view->vote_link = $this->output_vote_form(
$view->answer_link = $this->output_answer_form(
$output['markup'] = $view->render(FALSE);
} else {
throw new Exception('Error creating the room.');
// Stores a cookie so the attendee can only vote once
setcookie('voted_for_' . $question_id, 1, time() + 2592000, '/');
return $output;
This method starts by sanitizing the data that was submitted, storing it in the database using the model's
create_question() method, and checking for valid return values. It then creates a new question view and stores
all the variables to generate markup for a new question. A cookie is stored, indicating that the attendee posted the
question's first upvote; then the markup is returned.
Search WWH ::

Custom Search