[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!
Scam Warning
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)
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

Re: [3.2][BETA] Advanced Polls

Post by jasolo »

I have found the culprit. When the result are visible, the extension uses the official function vote_poll() in styles/prosilver/template/ajax.js and then another function from the extension. But around phpBB 3.2.5 the second line of vote_poll() was changed from:

Code: Select all

var poll = $('.topic_poll');
to:

Code: Select all

var poll = $(this).closest('.topic_poll'); 
And after that change the variable poll gets nothing when vote_poll() is used from my extension. :( Changing that file is a bad idea because that change will disappear with future phpBB updates, so the solution is to clone the old vote_poll function in my extension and use it instead of the official one. I'll release this fix soon, but I would prefer a clever fix with one or two lines and using the original function instead of cloning the old one. :roll:
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

Re: [3.2][BETA] Advanced Polls

Post by jasolo »

Thanks to kasimi for the fix! :D Better than my idea of cloning. :? The fixed version for phpBB 3.2.9 and 3.3 is here: https://github.com/jasoloz/advancedpoll ... .2.4.1.zip
User avatar
Aurelienazerty
Registered User
Posts: 193
Joined: Sat Jan 08, 2005 8:21 pm
Contact:

Re: [3.2][BETA] Advanced Polls

Post by Aurelienazerty »

Thanks it's works great !

One more thing : an improvement should be to order the voter name by something, maybe user_id it's easier, only add an ORDER BY vote_user_id line 311 in your core/advencedpolls.php
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

Re: [3.2][BETA] Advanced Polls

Post by jasolo »

The actual code shows the users in the order they voted. User_id is just the seniority of the user in the forum, I'm not sure that's more useful than who voted first. Surely you mean to order by 'username', joining the table 'users' to the query, but that could be an option. Chronological order makes sense as default.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

Hi, there's a few additions I'm looking to make, and I'm looking through advancedpolls.php, but I've only done basic coding so a lot of it is over my head. If anyone can point in the right direction, I'd appreciate it!

For listing voters in chronological order, in addition to that, I'd like to have the username followed by (x) where x is the number the vote was. For example, if User1 votes first, on a poll, their name would be first followed by (1).

And, if I understand correctly, if multiple voting is allowed and the user casts multiple votes at the same time, that number would be the same for all of their votes, correct? I'm fine with that going either way, for the purposes I'm using it for, that doesn't make a significant difference.

Then, in a poll where users can change their vote(s), I'd like to change it so that rather than getting rid of their name and vote number being removed completely, it gets striked instead. So if User1 had cast their vote on User2, but then changed the vote to User3, the vote on User2 would appear as "User 1 (1)".
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

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

Post by jasolo »

In advancedpolls.php, you should change the line 715, it contains the text for the username and the vote:

Code: Select all

$voter_list[] = '<span name="' . $user_cache[$voter_id]['username_clean'] . '">' . $username . ($poll_scoring ? ('(' . $vote_value . ')') : '') . '</span>';
If the vote order is stored in the variable $counter, then:

Code: Select all

$voter_list[] = '<span name="' . $user_cache[$voter_id]['username_clean'] . '">' . $username . '(' . $counter . ')' . ($poll_scoring ? ('(' . $vote_value . ')') : '') . '</span>';
Or if you want to put spaces around that text:

Code: Select all

$voter_list[] = '<span name="' . $user_cache[$voter_id]['username_clean'] . '">' . $username . ' (' . $counter . ') ' . ($poll_scoring ? ('(' . $vote_value . ')') : '') . '</span>';
Create and initialize the variable $counter to zero before the foreach at line 711 and increase it by one at the end of that bucle (before the closing brace at line 718). You can use another name for the variable.

The change question is more complicated. In theory the old vote is deleted from the database and the new vote is inserted, so when user1 votes before user2 and then user1 modifies his vote, this new vote should be located after the user2's one in the database. But that is not happening in the local database I use for tests, at least with the traditional polls, not the scoring ones. :!: It seems more like an update, although the code only has INSERT (line 515) and DELETE (line 472) commands. Also you should have to preserve the old vote as different (New field in the database? Or as a negative vote?) and disregard it in the count of votes.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

Thanks very much, I appreciate the insight! I was worried the second part would be harder, but I think that gives me enough to go on and if I come up with a solution I'll come back with it in case anyone else is interested.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

Hi again jasolo. I only sort of have the counter working. It does show the number, but the counter is working on a per option basis instead of poll-wide. So for example, I have a test poll with option 1, 2 and 3. When I vote for option 1, it shows admin (1), and if I vote on a second account on that same option it shows admin2 (2), but if I vote for option 2, it shows them both as admin (1) & admin2 (1), whereas I'd like for admin2 (assuming they vote second) to show as (2), the next on any option to be (3), and so on. I'm assuming I just need to make the change somewhere else in advancedpolls.php (or make the change both to line 715 and around it as you said, and elsewhere in addition to that?), but I'm not able to figure that out on my own. Any ideas?
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

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

Post by jasolo »

Yes, I thought you wanted per option basis. I was going to tell you to move the initialization of $counter before the 'for ($i' (line 707), but I'm not sure yet what you want. :? You could post captures of the poll parameters and the expected behaviour.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

Sure.

So when users vote for the same option, it does this, which is what I want:
Image

But when users vote for different options:
Image

What I am looking for is the vote admin cast in the second imagine to show as:
1 voters: admin(2)

So the counter would be a running total of all votes in the poll, and not just votes per option.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

Putting the $counter above the 'for ($i' line on 707 sort of works:
Image

as that is what I want it to look like.

But if admin changes the vote to option 1, it does this:
Image

and I would like it to still be admin(2) like in the first image.
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

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

Post by jasolo »

Then the task is not simple. I think you should add a new field to the table phpbb_poll_votes to store the timestamp, assign that value when the vote is sent and, based on that value, calculate the order of the voters when the results are shown.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

Okay. Is that something that I can feasibly do from within phpmyadmin, do you know? Or would I need a copy of the database opened in something I can more properly edit SQL databases? I have SQL server and have worked a bit with it, and while I don't have a problem doing that with my test environment, I'm not sure I'd want to go rooting around on a live boards database quite like that if I can avoid it.
syndicatemafia.boo
Registered User
Posts: 17
Joined: Sat Dec 14, 2019 1:16 am

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

Post by syndicatemafia.boo »

I believe I created the entry within the table correctly:

Image

It should store the current timestamp. But trying to do "assign that value when the vote is sent and, based on that value, calculate the order of the voters when the results are shown." is giving me issues. I believe I should be doing that once again within advancedpolls.php, within the foreach braces at around line 715, but I haven't been able to figure out what I should be adding. Apologies, I'm not much of a coder and this has me stumped.
User avatar
jasolo
Registered User
Posts: 105
Joined: Sat Jan 20, 2018 9:17 pm

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

Post by jasolo »

Making the changes in phpMyAdmin was the easy part. I think you'll have to add many lines of code.
Post Reply

Return to “Extensions in Development”