Page 1 of 1

Show Poll Voters

Posted: 11 Feb 2012, 19:39
by Leinad4Mind
Show voters under vote bars for Admins and Moderators only

OPEN: viewtopic.php
FIND:

Code: Select all

		$poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
		$poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
ADD-AFTER:

Code: Select all

		/***********************************************************************************
		Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
		************************************************************************************/
		$sql_voters = '
			SELECT u.username, u.user_colour, pv.vote_user_id
			FROM ' . POLL_VOTES_TABLE . ' pv, ' . USERS_TABLE . ' u
			WHERE pv.topic_id = ' . $topic_id . '
				AND poll_option_id = ' . $poll_info[$i]['poll_option_id'] . '
				AND pv.vote_user_id = u.user_id
			ORDER BY u.username_clean ASC, pv.vote_user_id ASC';

		$results_voters = $db->sql_query($sql_voters);
		$voters_total = 0;
		$voters_string = "";

			// Add all voters to a string.
			while ($row_voters = $db->sql_fetchrow($results_voters))
			{
				$voters_total = $voters_total + 1;
				$voters_string = $voters_string . "<option style='font-weight:bold; color:#" . $row_voters['user_colour'] . "'; value='u=" . $row_voters['vote_user_id'] . "'>" . $row_voters['username'] ."</option>";
				
			}

			// Is the total nr of voters <> the nr of votes for the poll? Add this to the same string.
			if ($voters_total <> $poll_info[$i]['poll_option_total'])
			{
				$voters_string = $voters_string . "<option><> " . ($poll_info[$i]['poll_option_total'] - $voters_total) . "</option>";
			}

		// Add the string to the list.
		$poll_info[$i]['poll_option_voters'] = $voters_string;
		$db->sql_freeresult($results_voters);
		/***********************************************************************************
		Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
		************************************************************************************/


FIND:

Code: Select all

			'POLL_OPTION_VOTED'		=> (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)

Replace-With:

Code: Select all

			/***********************************************************************************
			Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
			************************************************************************************/
			// 'POLL_OPTION_VOTED'	=> (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
			'POLL_OPTION_VOTED'		=> (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false,
			'POLL_OPTION_VOTERS'		=> $poll_option['poll_option_voters'])
			/***********************************************************************************
			Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
			************************************************************************************/


OPEN:
styles/XXXX/template/viewtopic_body.php

FIND In proSilver theme:

Code: Select all

<!-- ELSE -->{poll_option.POLL_OPTION_PERCENT}<!-- ENDIF -->
Replace-With:

Code: Select all

<!-- ELSE --><!-- IF not U_ACP or not U_MCP -->{poll_option.POLL_OPTION_PERCENT}<!-- ENDIF -->
                       <!-- IF U_ACP or U_MCP -->
						<select style="font-size: xx-small;">
							<option>{L_USERNAMES}:</option>";
							<option><span style="font-weight:bold; color:#{S_USER_COLOUR};">{poll_option.POLL_OPTION_VOTERS}</span></option>
                      </select>
                       <!-- ENDIF --><!-- ENDIF -->
8-)

It exists many mods similar. I like this one in this way. Cheers!

Note: This mod is based on evaarties' show poll voters for phpBB3. There are a lot of improvement from the original version. The new features I added are: user colour and cleaning up some codes.

Show Poll Voters

Posted: 12 Feb 2012, 15:42
by master412160
I tried it out and it doesn't seem to work that good. It does work without errors but when you select usernames who votes you sometimes get <>1 or a empty value?

Show Poll Voters

Posted: 13 Feb 2012, 07:09
by Leinad4Mind
I never face that problem. How can it be reproduced?!

Show Poll Voters

Posted: 19 Feb 2012, 06:20
by webmaster
Thanks bro for yOur new MOD..!!

Show Poll Voters

Posted: 24 Feb 2012, 13:34
by RMcGirr83
The code you are using will execute a sql query for every answer within a poll. If there are 10 poll answers, then the query will generate 10 times.

This is known as a "query in loop"

Not a very efficient way of doing it, IMHO.

Show Poll Voters

Posted: 26 Feb 2012, 04:07
by Leinad4Mind
Yeah I know, it's always called till the while finish ^^''. But I don't have knowledge to do better. Maybe on the future. If you know how to solve, I am all ears.

Thks