We need support for multiple vacancies. When there is 1 vacancy, it would be a radio button; with multiple, checkboxes and validation that the number of votes cast does not exceed the number of vacancies. I will work on a patch.

Comments

liam morland’s picture

Assigned: liam morland » Unassigned
Status: Active » Needs review
StatusFileSize
new5.05 KB
liam morland’s picture

Title: Support mutiple vacancies » Support multiple vacancies
pjcdawkins’s picture

Status: Needs review » Needs work
+++ b/election_fptp.module
@@ -110,18 +141,26 @@ function election_fptp_preprocess_election_vote_confirm(&$variables) {
+    $insert_id = db_insert('election_vote')

Could you use a single multiple-value insert query instead? See this answer: http://drupal.stackexchange.com/a/53319

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new4.85 KB

Thanks for the suggestion. Rerolled using that technique.

liam morland’s picture

StatusFileSize
new5.66 KB

New version shows the number of vacancies on the ballot.

pjcdawkins’s picture

Status: Needs review » Needs work
  1. +++ b/election_fptp.module
    @@ -35,9 +35,15 @@ function election_fptp_vote_form(&$form, &$form_state) {
    +  if ((int) $post->vacancy_count === 1) {
    

    Casting a property to an integer and then comparing it to 1 has the same effect as using the == operator.

  2. +++ b/election_fptp.module
    @@ -75,11 +91,30 @@ function election_fptp_vote_form(&$form, &$form_state) {
    +  $vacancy_count = (int) $form_state['post']->vacancy_count;
    

    It doesn't seem right to me to cast the type of vacancy_count, you have this in 3 places already - is there a particular reason?

  3. +++ b/election_fptp.module
    @@ -91,13 +126,15 @@ function election_fptp_preprocess_election_vote_confirm(&$variables) {
    +      '#title' => (count($voted_for) > 1) ? t('Your chosen candidates:') : t('Your chosen candidate:'),
    

    This should use format_plural().

liam morland’s picture

Thanks. PHP sometimes does unexpected things with the == and != operators, so I am in the habit of casting and using ===. This ensures that I know exactly what is being compared. I don't think that slows things down any because PHP will do some sort of casting whenever == is used. If you don't like this style, I will write it without the casting.

I will create a patch using format_plural().

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new5.67 KB

Patch using format_plural().

liam morland’s picture

Any further comments on this patch?

liam morland’s picture

Project: Election First Past the Post » Election
Component: Code » election_fptp
Assigned: Unassigned » liam morland
Status: Needs review » Fixed

Fixed in 052efb7.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dasfuller’s picture

Just discovered an issue:

In the foreach loop in election_fptp_preprocess_election_vote_confirm(), the $candidate_id is used as the index for the $form_state['candidates'] array, but that array uses incremental indices starting at 0. So the names never appear on the vote confirmation page because candidate objects aren't getting passed into election_candidate_get_name() unless the $candidate_id matches one of the indices.

liam morland’s picture

Please make a child issue and provide steps to reproduce the problem.