HTML and CSS Reference
In-Depth Information
Finishing the View
Several of the variables being declared are
NULL
or empty because the methods to retrieve the needed data don't exist
yet. According to the
TODO
s in the comments, the loop still needs to:
•
Check to see whether the user has already voted up the question
•
Load the vote up form for attendees, but not presenters
•
Load the answer form for presenters, but not attendees
Checking to See Whether the User Has Already Voted Up a Question
In order to determine whether or not a user has voted up a question, you'll be using a simple cookie. When a user
votes for a question, a cookie named
voted_for_n
(where n is the ID of the question) will be stored. This will allow the
app to prevent multiple votes from being submitted by a single user.
To check the cookie, add the following bold code to
output_view()
:
public function output_view( )
{
$questions = $this->get_questions();
$output = NULL;
foreach ($questions as $question) {
/*
* Questions have their own view type, so this section initializes
* and sets up variables for the question view
*/
$view = new View('question');
$view->question = $question->question;
$view->room_id = $this->room_id;
$view->question_id = $question->question_id;
$view->vote_count = $question->vote_count;
if ($question->is_answered==1) {
$view->answered_class = 'answered';
} else {
$view->answered_class = NULL;
}
// Checks if the user has already voted up this question
$cookie = 'voted_for_' . $question->question_id;
if (isset($_COOKIE[$cookie]) && $_COOKIE[$cookie]==1) {
$view->voted_class = 'voted';
} else {
$view->voted_class = NULL;
}
// TODO: Load the vote up form for attendees, but not presenters
$view->vote_link = '';
Search WWH ::
Custom Search