I know 4.6 is closed, but I needed to make some improvements to poll.module for my 4.6 site. I wanted users to be able to view their own vote on a given poll, cancel their vote (so they can change their mind, if they wish), and to give admins a way to view all the votes of each user on a given poll (it's a separate tab and permission).

There's a forum thread where some other folks were interested in the functionality, so I wanted to put the patch somewhere they could get it. Since I can't attach files to a forum posts, this seemed like a reasonable place to put the code. If there's a better way to do this, please let me know. Thanks!

To allow this new functionality to work, I modified the DB schema relating to polls to be like it is in 4.7: a separate {poll_votes} table instead of the "polled" field in the {poll} table. This table also contains a "chorder" field, to record the choice offset for each nid/uid pair. i didn't change the fact that anonymous users (if allowed to vote at all) are authenticated and recorded based on their IP address.

So, to use this patch, you must modify your {poll} table and create the {poll_votes} table. I didn't spend any time worrying about a smooth update procedure, since it doesn't seem worth the time. The easiest thing is to just delete your existing {poll} and {poll_choices} tables (using DROP, either directly or via the DBA module). Then, you'll want to create the following tables:

--
-- Table structure for table 'poll'
--

CREATE TABLE poll (
  nid int(10) unsigned NOT NULL default '0',
  runtime int(10) NOT NULL default '0',
  active int(2) unsigned NOT NULL default '0',
  PRIMARY KEY (nid)
) TYPE=MyISAM;

--
-- Table structure for table 'poll_votes'
--

CREATE TABLE poll_votes (
  nid int(10) unsigned NOT NULL,
  uid int(10) unsigned NOT NULL default 0,
  chorder int(10) unsigned NOT NULL default 0,
  hostname varchar(128) NOT NULL default '',
  INDEX (nid),
  INDEX (uid),
  INDEX (chorder),
  INDEX (hostname)
) TYPE=MyISAM
/*!40100 DEFAULT CHARACTER SET utf8 */ ;

--
-- Table structure for table 'poll_choices'
--

CREATE TABLE poll_choices (
  chid int(10) unsigned NOT NULL auto_increment,
  nid int(10) unsigned NOT NULL default '0',
  chtext varchar(128) NOT NULL default '',
  chvotes int(6) NOT NULL default '0',
  chorder int(2) NOT NULL default '0',
  PRIMARY KEY (chid),
  KEY nid (nid)
) TYPE=MyISAM;

of course, dropping these tables will cause you to loose any existing or historical polls on your site. if you really want to upgrade to this new version of poll but save the old values, you can do your own SQL queries.

Anyway, this is just here in case any 4.6 folks want this new functionality. I'll try to get the same thing working in 4.7 soon and submit that as a separate issue, though i suspect since this is new functionality, it'll have to wait until 4.8 to be committed to core. We'll see...

CommentFileSizeAuthor
#1 poll_module-user_vote18.01 KBdww
poll_module-user_vote.patch8.67 KBdww

Comments

dww’s picture

StatusFileSize
new18.01 KB

for anyone unable to apply patches, here's a complete copy of the latest poll.module from 4.6 (revision 1.162.2.1) that has the patch already applied. to install, save a copy of your current poll.module file, download this, and rename it to modules/poll.module. don't forget to update your DB tables, as described in the original comment.

enjoy,
-derek