Skip to content

Commit f70e27f

Browse files
authored
Merge pull request #101 from VSEphpbb/vote-fix
Disable vote button if user already voted
2 parents 3003168 + 574e93c commit f70e27f

4 files changed

Lines changed: 28 additions & 27 deletions

File tree

event/listener.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,25 @@ public function show_idea($event)
203203
$this->auth->acl_get('f_vote', (int) $this->config['ideas_forum_id']) &&
204204
$event['topic_data']['topic_status'] != ITEM_LOCKED);
205205

206+
$s_voted_up = $s_voted_down = false;
207+
if ($idea['idea_votes_up'] || $idea['idea_votes_down'])
208+
{
209+
$votes = $this->ideas->get_voters($idea['idea_id']);
210+
211+
foreach ($votes as $vote)
212+
{
213+
$this->template->assign_block_vars('votes_' . ($vote['vote_value'] ? 'up' : 'down'), array(
214+
'USER' => $vote['user'],
215+
));
216+
217+
if ($this->user->data['user_id'] == $vote['user_id'])
218+
{
219+
$s_voted_up = ((int) $vote['vote_value'] === 1);
220+
$s_voted_down = ((int) $vote['vote_value'] === 0);
221+
}
222+
}
223+
}
224+
206225
$this->template->assign_vars(array(
207226
'IDEA_ID' => $idea['idea_id'],
208227
'IDEA_TITLE' => $idea['idea_title'],
@@ -226,6 +245,9 @@ public function show_idea($event)
226245
'S_IS_MOD' => $mod,
227246
'S_CAN_EDIT' => $mod || $own,
228247
'S_CAN_VOTE' => $can_vote,
248+
'S_CAN_VOTE_UP' => $can_vote && !$s_voted_up,
249+
'S_CAN_VOTE_DOWN' => $can_vote && !$s_voted_down,
250+
'S_VOTED' => $s_voted_up || $s_voted_down,
229251

230252
'U_CHANGE_STATUS' => $this->link_helper->get_idea_link($idea['idea_id'], 'status', true),
231253
'U_EDIT_DUPLICATE' => $this->link_helper->get_idea_link($idea['idea_id'], 'duplicate', true),
@@ -236,27 +258,6 @@ public function show_idea($event)
236258
'U_IDEA_VOTE' => $this->link_helper->get_idea_link($idea['idea_id'], 'vote', true),
237259
));
238260

239-
if ($idea['idea_votes_up'] || $idea['idea_votes_down'])
240-
{
241-
$s_voted = false;
242-
243-
$votes = $this->ideas->get_voters($idea['idea_id']);
244-
245-
foreach ($votes as $vote)
246-
{
247-
$this->template->assign_block_vars('votes_' . ($vote['vote_value'] ? 'up' : 'down'), array(
248-
'USER' => $vote['user'],
249-
));
250-
251-
if ($this->user->data['user_id'] == $vote['user_id'])
252-
{
253-
$s_voted = true;
254-
}
255-
}
256-
257-
$this->template->assign_var('S_VOTED', $s_voted);
258-
}
259-
260261
// Use Ideas breadcrumbs
261262
$this->template->destroy_block_vars('navlinks');
262263
$this->template->assign_block_vars('navlinks', array(

styles/prosilver/template/idea_body.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<dt class="idealabel">{{ lang('RATING') ~ lang('COLON') }}</dt>
1616
<dd>
1717
<div class="rating">
18-
<a {% if S_CAN_VOTE %}href="{{ U_IDEA_VOTE }}"{% endif %} class="minivoteup {{ S_CAN_VOTE ? 'voteup' : 'dead' }}" title="{{ lang('VOTE_UP') }}" data-l-err="{{ lang('ERROR') }}" data-l-msg="{{ lang('VOTE_ERROR') ~ lang('COLON') }}"><span>{{ IDEA_VOTES_UP }}</span></a> &nbsp;
19-
<a {% if S_CAN_VOTE %}href="{{ U_IDEA_VOTE }}"{% endif %} class="minivotedown {{ S_CAN_VOTE ? 'votedown' : 'dead' }}" title="{{ lang('VOTE_DOWN') }}" data-l-err="{{ lang('ERROR') }}" data-l-msg="{{ lang('VOTE_ERROR') ~ lang('COLON') }}"><span>{{ IDEA_VOTES_DOWN }}</span></a>
18+
<a {% if S_CAN_VOTE %}href="{{ U_IDEA_VOTE }}"{% endif %} class="minivoteup {{ S_CAN_VOTE_UP ? 'voteup' : 'dead' }}" title="{{ lang('VOTE_UP') }}" data-l-err="{{ lang('ERROR') }}" data-l-msg="{{ lang('VOTE_ERROR') ~ lang('COLON') }}"><span>{{ IDEA_VOTES_UP }}</span></a> &nbsp;
19+
<a {% if S_CAN_VOTE %}href="{{ U_IDEA_VOTE }}"{% endif %} class="minivotedown {{ S_CAN_VOTE_DOWN ? 'votedown' : 'dead' }}" title="{{ lang('VOTE_DOWN') }}" data-l-err="{{ lang('ERROR') }}" data-l-msg="{{ lang('VOTE_ERROR') ~ lang('COLON') }}"><span>{{ IDEA_VOTES_DOWN }}</span></a>
2020
<a href="#" class="votes bg3" data-l-msg="{{ lang('CLICK_TO_VIEW') }}">{{ lang('TOTAL_POINTS', IDEA_POINTS) }} {{ IDEA_VOTES ? lang('CLICK_TO_VIEW') }}</a> <span class="successvoted bg3" data-l-err="{{ lang('VOTE_FAIL') }}"></span>
2121
</div>
2222
<div class="clear"></div>

styles/prosilver/template/ideas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
successVoted: $('.successvoted'),
2929
votes: $('.votes'),
3030
votesList: $('.voteslist'),
31-
voteDown: $('.votedown'),
32-
voteUp: $('.voteup'),
31+
voteDown: $('.minivotedown'),
32+
voteUp: $('.minivoteup'),
3333
voteRemove: $('#vote-remove')
3434
};
3535

tests/functional/ideas_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function test_new_idea()
4444
$this->assertContains($this->lang('IDEAS'), $crawler->filter('#nav-breadcrumbs')->text());
4545
$this->assertContains($idea['title'], $crawler->filter('h2')->text());
4646
$this->assertContains($idea['message'], $crawler->filter('.content')->text());
47-
$this->assertContains('1', $crawler->filter('.rating > .voteup')->text());
48-
$this->assertContains('0', $crawler->filter('.rating > .votedown')->text());
47+
$this->assertContains('1', $crawler->filter('.rating > .minivoteup')->text());
48+
$this->assertContains('0', $crawler->filter('.rating > .minivotedown')->text());
4949
}
5050

5151
/**

0 commit comments

Comments
 (0)