Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vote-abstraction' of https://github.com/TomSpeak/silver…
…stripe-polls into TomSpeak-vote-abstraction fixes #20 Conflicts: Readme.md code/Poll.php
- Loading branch information
Showing
9 changed files
with
118 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
<?php | ||
|
||
Deprecation::notification_version('0.2', 'polls'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* Default vote handler. | ||
* | ||
* If a user votes for a poll and Cookie is stored on their computer which assigns | ||
* that they have voted for a particular poll ID | ||
* | ||
*/ | ||
class CookieVoteHandler extends Vote_Backend { | ||
|
||
const COOKIE_PREFIX = 'SSPoll_'; | ||
|
||
/** | ||
* Generates a cookie to indicate the user has voted on the poll. | ||
*/ | ||
public function markAsVoted() { | ||
Cookie::set(self::COOKIE_PREFIX . $this->getPoll()->ID, 1); | ||
} | ||
|
||
/** | ||
* Checks to see if the user can vote. Verified by checking whether or not | ||
* the user has voted before. Which is the only limitation of this | ||
* cookie based implementation. | ||
* | ||
* @return bool | ||
*/ | ||
public function canVote() { | ||
return !$this->hasVoted(); | ||
} | ||
|
||
/** | ||
* Checks to see if the user has a cookie set which is generated when | ||
* they vote on a poll | ||
* | ||
* @return bool | ||
*/ | ||
public function hasVoted() { | ||
return (bool) Cookie::get(self::COOKIE_PREFIX . $this->getPoll()->ID); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* A base class to allow hooking into the polling functionality | ||
* | ||
* @abstract | ||
* | ||
* @author Tom Speak <@tomspeak> | ||
* @author Dan Hensby <@dhensby> | ||
*/ | ||
abstract class Vote_Backend { | ||
|
||
protected $poll; | ||
|
||
public function __construct($poll) { | ||
$this->setPoll($poll); | ||
} | ||
|
||
abstract function hasVoted(); | ||
|
||
abstract function canVote(); | ||
|
||
abstract function markAsVoted(); | ||
|
||
public function setPoll(Poll $poll) { | ||
$this->poll = $poll; | ||
} | ||
|
||
public function getPoll() { | ||
return $this->poll; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters