[3.2][3.3][BETA] Advanced Polls

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Suggested Hosts
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
sliptonic
Registered User
Posts: 1
Joined: Mon Feb 07, 2022 4:09 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by sliptonic »

We have a forum where a "management board" discusses and votes on issues.

We want to conduct the votes anonymously but know who voted. In other words, I don't want to know HOW the members voted but I do want to know which 6 of the 10 voted at all.

It looks like this plugin will almost meet our needs. Only disclosing the results after the poll closes is great. But it looks like the list of voters is per-option.

How difficult would it be to modify the plugin to only show a single list of voters for all options?
User avatar
jasolo
Registered User
Posts: 130
Joined: Sat Jan 20, 2018 9:17 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by jasolo »

Yes, the list of voters is per-option. To display the single list of voters without knowing what options they voted would require to code an additional setting and I'm not sure it's worth it. 🤔 As the extension is now a trick would be to activate the "Activate limit voters" setting in ACP so users must post in the topic before they can vote. That does not ensure that they vote after posting, but at least they state that they have noticed the poll.
Wahnsihansi
Registered User
Posts: 6
Joined: Sat Aug 13, 2022 3:17 pm

Re: [3.2][BETA] Advanced Polls

Post by Wahnsihansi »

jasolo wrote: Sat Nov 10, 2018 7:23 pm The following code should work. ;) In core/advancedpolls.php, before the comment "// Okay, lets push some of this information to the template", insert this:

Code: Select all

for ($i = 0; $i < $poll_options_count; $i++)
{
   $poll_options_template_data[$i]['POLL_OPTION_PERCENT'] = $poll_options_template_data[$i]['POLL_OPTION_RESULT'] / strtr($poll_options_template_data[$i]['AP_VOTERS'], array('(' => '', ')' => ''));
}
Hi there,
I am not really into PHP, I hope you can help me.
As some users mentioned before, it would be great to be able to change the scoring system from accumulated votes to average votes per user. Also, it would be nice to hide the shown percentage.

What I want is essentially a rating system like for example
Question:
How would you rate your visit at our national park?
- Cleanliness (score from 1-10)
- Signage (score from 1-10)
- Kindness of wild animals (score from 1-10)

and then in the poll result be shown the average rating.


I already tried to change the code above, but it shows me a blank page when I want to view the poll.

(Sorry if it's not 100% perfect english, I am not a native speaker)

Wahnsihansi
User avatar
jasolo
Registered User
Posts: 130
Joined: Sat Jan 20, 2018 9:17 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by jasolo »

I won't be available until September. You should activate the debugging in phpBB and check the server logs to know what causes the blank page.
Wahnsihansi
Registered User
Posts: 6
Joined: Sat Aug 13, 2022 3:17 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Wahnsihansi »

jasolo wrote: Sun Aug 14, 2022 10:09 am I won't be available until September. You should activate the debugging in phpBB and check the server logs to know what causes the blank page.
Thank you for the quick reply. It is not being taken for granted and I really appreciate it.
I found out that there is another extension that causes the blank page. The blank page is gone now.
phpdebug tells me:
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 833: A non-numeric value encountered
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 833: Division by zero
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 833: A non-numeric value encountered
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 833: Division by zero
833 is one of the lines where the changed code is (the one you recommended).
Also, the polls behaviour didn't change.

This is what the code looks like now:

Code: Select all

		// Add the button to see poll results, if you have permissions
		if ($this->auth->acl_get('m_seevoters', $topic_data['forum_id']))
		{
			$poll_template_data['U_AP_POLL_INFO'] = $poll_template_data['S_POLL_ACTION'] . '&amp;view=infopoll';
		}
		for ($i = 0; $i < $poll_options_count; $i++)
		{
			$poll_options_template_data[$i]['POLL_OPTION_PERCENT'] = $poll_options_template_data[$i]['POLL_OPTION_RESULT'] / strtr($poll_options_template_data[$i]['AP_VOTERS'], array('(' => '', ')' => ''));
		}
		// Okay, lets push some of this information to the template
After that post, Cachete contacted me by private message and I suggested him where he could find the solution, but that was months ago and I don't have his code. I think he was changing the extension to show only the averages, not as an additional option.
That would also be fine for me, it would be just great to have any kind of solution for this. I'll write cachete, maybe he can tell me his changes in the code.
Wahnsihansi
Registered User
Posts: 6
Joined: Sat Aug 13, 2022 3:17 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Wahnsihansi »

I am trying to learn a bit of PHP to solve this problem on my own, and I managed to find out which database value is shown in the pollbar - it's "poll_option_total" and the important line in the original phpBB Code (viewtopic.php) to change it is:

Code: Select all

'POLL_OPTION_RESULT' 		=> $poll_option['poll_option_total'],
I've been a complete noob so it took me many hours just to understand enough of the code to find this - I know you experts would have found it in a minute, still, I am very happy to actually have found it :)
As the poll_option_total value is changed by the extension, I am now trying to understand what the extension does and where I can change the code in order to reach what I wanted.

Edit: okay, I see that after voting, even in the original phpBB code there's still another code that sets the value on the pollbar. After refreshing it's the code shown above. Still a lot to find out for me, I guess.
Edit 2: Seems like "$vote_counts" is responsible for that.
Wahnsihansi
Registered User
Posts: 6
Joined: Sat Aug 13, 2022 3:17 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Wahnsihansi »

Ok, i tried doing the first part on my own, but I am stuck finding the problem with my code.

In line 503 of advancedpolls.php, I changed

Code: Select all

$vote_counts[$option] += (int) $voted_val[$option];
to

Code: Select all

				$sql = 'SELECT COUNT(vote_user_id) AS votersforoneoption
				FROM ' . POLL_VOTES_TABLE . '
				WHERE poll_option_id = ' . (int) $option . '
					AND topic_id = ' . (int) $topic_data['topic_id'];
				$result = $db->sql_query($sql);
				$votersforoneoption = (int) $db->sql_fetchfield('votersforoneoption');
				$db->sql_freeresult($result);

				$vote_counts[$option] = ($vote_counts[$option] + $voted_val[$option]) / $votersforoneoption;
But it's not working... there is no error message, but it won't let me vote.
(I assume I must change the value to / ($votersforoneoption + 1), as the current voter isn't added, but still not working.

When I change it to

Code: Select all

$vote_counts[$option] = ($vote_counts[$option] + $voted_val[$option]) / 2;
it's working, so it seems to be the right line; but of course I don't want to divide it by 2; I want to divide it by the number of voters on this option...


Again, I am a PHP newbie, so it might be that I am missing the obvious or ignoring some PHP rules.
Nephilim
Registered User
Posts: 60
Joined: Tue Oct 26, 2010 8:46 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Nephilim »

Hello,
since I activated php8.1.8 on my forum using phpBB 3.3.7 we got the following error messages when showing a thread with advanced polls (version 1.2.4.2):

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Trying to access array offset on value of type null
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Trying to access array offset on value of type null
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 715: Trying to access array offset on value of type null
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 717: Undefined array key "total_user_votes"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Trying to access array offset on value of type null
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Trying to access array offset on value of type null
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 715: Trying to access array offset on value of type null
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 717: Undefined array key "total_user_votes"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "username"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "user_colour"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 715: Undefined array key "username_clean"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "username"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "user_colour"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 715: Undefined array key "username_clean"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "username"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "user_colour"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 715: Undefined array key "username_clean"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "username"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 713: Undefined array key "user_colour"
[phpBB Debug] PHP Warning: in file [ROOT]/ext/wolfsblvt/advancedpolls/core/advancedpolls.php on line 715: Undefined array key "username_clean"
Settings used for the poll showing this errors.
Settings used for the poll showing this errors.
Could you please help us with this problem?!
Thx for your support! :)
Last edited by Nephilim on Fri Sep 09, 2022 7:49 am, edited 1 time in total.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: [3.2][3.3][BETA] Advanced Polls

Post by david63 »

Nephilim wrote: Fri Sep 09, 2022 6:31 am since I activated php8.1 on my forum
It would appear that this extension is not compatible with PHP 8.1.

Either disable the extension or downgrade your PHP version.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
Nephilim
Registered User
Posts: 60
Joined: Tue Oct 26, 2010 8:46 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Nephilim »

david63 wrote: Fri Sep 09, 2022 7:14 am
Nephilim wrote: Fri Sep 09, 2022 6:31 am since I activated php8.1 on my forum
It would appear that this extension is not compatible with PHP 8.1.

Either disable the extension or downgrade your PHP version.
The problem is the same on php8.0 and php7.4 will be deactivated by my hoster on 14. November 2022.
So I hope there will be a solution for this problem, because we use this extension a lot.
SeewolfPK
Registered User
Posts: 109
Joined: Sat Apr 09, 2011 10:18 am

Re: [3.2][3.3][BETA] Advanced Polls

Post by SeewolfPK »

Version 1.2.4.1 - phpBB 3.3.8 - php 8.0.20

is installed and works fine
Best wishes
Paul
Nephilim
Registered User
Posts: 60
Joined: Tue Oct 26, 2010 8:46 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Nephilim »

SeewolfPK wrote: Fri Sep 09, 2022 7:34 am Version 1.2.4.1 - phpBB 3.3.8 - php 8.0.20

is installed and works fine
On my board with php 8.0.20 and all other extensions deactivated the problem is the same.
Did you use the same settings for your poll as I showed above?
It seems in this case the problem is only showing itself, when the option "Show poll voters" is active.
Last edited by Nephilim on Fri Sep 09, 2022 7:57 am, edited 1 time in total.
SeewolfPK
Registered User
Posts: 109
Joined: Sat Apr 09, 2011 10:18 am

Re: [3.2][3.3][BETA] Advanced Polls

Post by SeewolfPK »

look
poll.jpg
poll2.jpg
Best wishes
Paul
Nephilim
Registered User
Posts: 60
Joined: Tue Oct 26, 2010 8:46 pm

Re: [3.2][3.3][BETA] Advanced Polls

Post by Nephilim »

In my case some of the voters are no longer member of the board and the username 'guest' is showed.
Perhaps it is a logical fault in this case and not one with the php-version?!
SeewolfPK
Registered User
Posts: 109
Joined: Sat Apr 09, 2011 10:18 am

Re: [3.2][3.3][BETA] Advanced Polls

Post by SeewolfPK »

I try with new User Tester
poll3.jpg
After deleting him is shown as Gast (german Version)
poll4.jpg
Best wishes
Paul
Post Reply

Return to “Extensions in Development”