HTML and CSS Reference
In-Depth Information
Adding Votes to a Question
Adding a new vote to a question executes the vote_question() method to store the new vote in the database and
then sets a cookie for the voter to prevent multiple votes for the same question. Add the following bold code to the
Question controller:
// Stores a cookie so the attendee can only vote once
setcookie('voted_for_' . $question_id, 1, time() + 2592000, '/');
return $output;
}
/**
* Increments the vote count for a given question
*
* @return array Information about the updated question
*/
protected function vote_question( )
{
$room_id = $this->sanitize($_POST['room_id']);
$question_id = $this->sanitize($_POST['question_id']);
// Makes sure the attendee hasn't already voted for this question
$cookie_id = 'voted_for_' . $question_id;
if (!isset($_COOKIE[$cookie_id]) || $_COOKIE[$cookie_id]!=1) {
$output = $this->model->vote_question($room_id, $question_id);
// Sets a cookie to make it harder to post multiple votes
setcookie($cookie_id, 1, time() + 2592000, '/');
} else {
$output = array('room_id'=>$room_id);
}
return $output;
}
}
Marking a Question as Answered
In order to mark a question as answered, the user submitting the form must be the presenter. This, like voting, will be
cookie-based. This method checks the presenter's cookie before executing the answer_question() method.
Add the following code shown in bold to the Question controller:
// Stores a cookie so the attendee can only vote once
setcookie('voted_for_' . $question_id, 1, time() + 2592000, '/');
return $output;
}
 
Search WWH ::




Custom Search