You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature request aims to add the ability to create and manage polls within
the web forum. The feature will include models for polls, poll choices, and
poll votes. Polls will have a question and duration, poll choices will cache
the number of votes, and poll votes will have a 'counted' column to control if
the vote should be included in the scoring.
Polls can be configured:
vote_type: Allows users to vote on a single choice or multiple choices
anonymous: Control if results display the voter's name or not
Proposed Models
TopicPolls
id (integer, primary key)
topic_id (integer, foreign key)
poll_question (string, required)
description (text, optional)
anonymous (boolean, default: true): Determines if the poll votes should be anonymous
hide_results (boolean, default: false, optional): Determines if the poll results should be hidden from users even if poll has ended
start_date (datetime, default: now, required)
end_date (datetime, required)
created_at (datetime)
updated_at (datetime)
vote_type (enum, values: ['single', 'multiple'], default: 'single'): Determines if users can vote on a single choice or multiple choices
PollChoices
id (integer, primary key)
poll_id (integer, foreign key to TopicPolls, required)
choice_text (string, required)
description (text, optional)
vote_count (integer, default: 0)
created_at (datetime)
updated_at (datetime)
position (integer, required)
PollVotes
id (integer, primary key)
poll_choice_id (integer, foreign key to PollChoices, required)
user_id (integer, foreign key to Users, required)
counted (boolean, default: true)
created_at (datetime)
updated_at (datetime)
Typical Poll Operation
Creating a Poll
User optionally creates a new poll with a question and duration during the creation of a topic.
User adds multiple choices for the poll.
Editing a Poll
User can edit the question, choices and duration of a poll.
Editing and deleting a poll option should be responded.
Deleting poll option should delete an existing votes
Voting on a Poll
Users cast their votes by selecting a choice.
The vote is recorded in the PollVotes table.
The vote_count in the PollChoices table is incremented if counted is true.
Poll Duration Expiry
After the poll's end_date no more votes are allowed
The results are displayed on the topic upage
Implementation
Database Migration
Create migration files for TopicPolls, PollChoices, and PollVotes.
Model Creation
Create TopicPolls model.
Create PollChoices model.
Create PollVotes model.
Implement relations in all models
Topics: has_one polls
TopicPolls: has_many poll_choices
TopicPolls: belongs_to topics
PollChoices: belongs_to topic_polls
PollChoices: has_many poll_votes
PollVotes: belongs_to poll_choice
PollVotes: belongs_to user
Implement methods on models
TopicPolls:
is_open: Can the poll currently be voted on?
total_vote_count: Calculate the total number of votes for the poll
allowed_to_edit: Check if a user is allowed to edit the poll
allowed_to_vote: Check if a user is allowed to vote in the poll
name_for_display: Get the display name for the poll
PollChoices:
recount: Recalculate the vote count for the choice
delete: Delete the poll choice and its associated votes
vote: Set the vote for the user, aware of vote_type for the poll
PollVotes:
set_counted: Toggle the counted status of a vote, and updating the total_votes if necessary
create: Insert a new vote with increment if necessary
delete: Remove a vote and decrement the vote count if necessary
Flows and Actions
Update topic creation flow to include poll creation
Create logic for poll creation.
TopicPollsFlow
Implement poll voting logic
Create logic for editing a poll.
Implement validate_params method for input validation.
Implement set_choices method to manage poll choices (create, update, delete).
Testing
Write models unit tests
Write flow unit test
Additional Considerations
Add controls to set the counted field based on who is voting to prevent spam/abuse
The text was updated successfully, but these errors were encountered:
Feature Porposal: Add Polls to forum topics
Summary
This feature request aims to add the ability to create and manage polls within
the web forum. The feature will include models for polls, poll choices, and
poll votes. Polls will have a question and duration, poll choices will cache
the number of votes, and poll votes will have a 'counted' column to control if
the vote should be included in the scoring.
Polls can be configured:
Proposed Models
TopicPolls
id
(integer, primary key)topic_id
(integer, foreign key)poll_question
(string, required)description
(text, optional)anonymous
(boolean, default: true): Determines if the poll votes should be anonymoushide_results
(boolean, default: false, optional): Determines if the poll results should be hidden from users even if poll has endedstart_date
(datetime, default: now, required)end_date
(datetime, required)created_at
(datetime)updated_at
(datetime)vote_type
(enum, values: ['single', 'multiple'], default: 'single'): Determines if users can vote on a single choice or multiple choicesPollChoices
id
(integer, primary key)poll_id
(integer, foreign key to TopicPolls, required)choice_text
(string, required)description
(text, optional)vote_count
(integer, default: 0)created_at
(datetime)updated_at
(datetime)position
(integer, required)PollVotes
id
(integer, primary key)poll_choice_id
(integer, foreign key to PollChoices, required)user_id
(integer, foreign key to Users, required)counted
(boolean, default: true)created_at
(datetime)updated_at
(datetime)Typical Poll Operation
Creating a Poll
Editing a Poll
Voting on a Poll
vote_count
in the PollChoices table is incremented ifcounted
is true.Poll Duration Expiry
end_date
no more votes are allowedImplementation
Database Migration
Model Creation
has_one polls
has_many poll_choices
belongs_to topics
belongs_to topic_polls
has_many poll_votes
belongs_to poll_choice
belongs_to user
is_open
: Can the poll currently be voted on?total_vote_count
: Calculate the total number of votes for the pollallowed_to_edit
: Check if a user is allowed to edit the pollallowed_to_vote
: Check if a user is allowed to vote in the pollname_for_display
: Get the display name for the pollrecount
: Recalculate the vote count for the choicedelete
: Delete the poll choice and its associated votesvote
: Set the vote for the user, aware of vote_type for the pollset_counted
: Toggle thecounted
status of a vote, and updating thetotal_votes
if necessarycreate
: Insert a new vote with increment if necessarydelete
: Remove a vote and decrement the vote count if necessaryFlows and Actions
TopicPollsFlow
validate_params
method for input validation.set_choices
method to manage poll choices (create, update, delete).Testing
Additional Considerations
counted
field based on who is voting to prevent spam/abuseThe text was updated successfully, but these errors were encountered: