Skip to content

Commit

Permalink
fix ends_at was not being used
Browse files Browse the repository at this point in the history
  • Loading branch information
ivenspontes committed Feb 3, 2022
1 parent bb83dce commit fbbec30
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Helpers/PollWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function draw($poll)

$voter = $poll->canGuestVote() ? new Guest(request()) : auth(config('larapoll_config.admin_guard'))->user();

if (is_null($voter) || $voter->hasVoted($poll->id) || $poll->isLocked()) {
if (is_null($voter) || $voter->hasVoted($poll->id) || $poll->isLocked() || $poll->hasEnded()) {
if (!$poll->showResultsEnabled()) {
return 'Thanks for voting';
}
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Controllers/PollManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function index()
$poll->isComingSoon = $poll->isComingSoon();
$poll->isLocked = $poll->isLocked();
$poll->isRunning = $poll->isRunning();
$poll->hasEnded = $poll->hasEnded();
$poll->edit_link = route('poll.edit', $poll->id);
$poll->delete_link = route('poll.remove', $poll->id);
$poll->lock_link = route('poll.lock', $poll->id);
Expand Down Expand Up @@ -124,6 +125,7 @@ public function lock(Poll $poll)
$poll->isComingSoon = $poll->isComingSoon();
$poll->isLocked = $poll->isLocked();
$poll->isRunning = $poll->isRunning();
$poll->hasEnded = $poll->hasEnded();
$poll->edit_link = route('poll.edit', $poll->id);
$poll->delete_link = route('poll.remove', $poll->id);

Expand Down
2 changes: 0 additions & 2 deletions src/Http/Controllers/VoteManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class VoteManagerController extends Controller
*/
public function vote(Poll $poll, Request $request)
{

try{

$vote = $this->resolveVoter($request, $poll)
->poll($poll)
->vote($request->get('options'));
Expand Down
13 changes: 11 additions & 2 deletions src/Traits/PollAccessor.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Inani\Larapoll\Traits;


trait PollAccessor
{

Expand Down Expand Up @@ -82,7 +81,7 @@ public function isOpen()
*/
public function isRunning()
{
return $this->isOpen() && $this->hasStarted();
return $this->isOpen() && $this->hasStarted() && !$this->hasEnded();
}

/**
Expand All @@ -104,4 +103,14 @@ public function isComingSoon()
{
return $this->isOpen() && now() < $this->starts_at;
}

/**
* If the poll has already ended
*
* @return bool
*/
public function hasEnded()
{
return $this->ends_at < now();
}
}
2 changes: 1 addition & 1 deletion src/Traits/Voter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function vote($options)
if (is_null($this->poll))
throw new PollNotSelectedToVoteException();

if ($this->poll->isLocked())
if ($this->poll->isLocked() || $this->poll->hasEnded())
throw new VoteInClosedPollException();

if ($this->hasVoted($this->poll->id))
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<!--Responsive Extension Datatables CSS-->
<link href="https://cdn.datatables.net/responsive/2.2.3/css/responsive.dataTables.min.css" rel="stylesheet">


<style>
/*Overrides for Tailwind CSS */
Expand Down Expand Up @@ -113,6 +112,7 @@
<span v-if="poll.isLocked" class="label label-danger">Closed</span>
<span v-else-if="poll.isComingSoon" class="label label-info">Soon</span>
<span v-else-if="poll.isRunning" class="label label-success">Started</span>
<span v-else-if="poll.hasEnded" class="label label-success">Ended</span>
</td>
<td>
<a class="btn btn-info btn-sm" :href="poll.edit_link">
Expand Down

0 comments on commit fbbec30

Please sign in to comment.