Skip to content

Commit

Permalink
APICHANGE: rename the functions to conform with SS coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz committed Aug 4, 2011
1 parent 8277763 commit ca4bd1a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions code/Poll.php
Expand Up @@ -116,7 +116,7 @@ function getCMSFields() {
* *
* @return int * @return int
*/ */
function totalVotes($useCache = true) { function getTotalVotes($useCache = true) {
static $_cache; static $_cache;
if (!isset($_cache) || !$useCache) { if (!isset($_cache) || !$useCache) {
$query = DB::query('SELECT SUM("Votes") As "Total" FROM "PollChoice" WHERE "PollID" = ' . $this->ID); $query = DB::query('SELECT SUM("Votes") As "Total" FROM "PollChoice" WHERE "PollID" = ' . $this->ID);
Expand All @@ -131,7 +131,7 @@ function totalVotes($useCache = true) {
* Find out what is the maximum amount of votes received for one of the options. * Find out what is the maximum amount of votes received for one of the options.
* TODO: rewrite as Aggregate, so it uses in-built cache? * TODO: rewrite as Aggregate, so it uses in-built cache?
*/ */
function maxVotes($useCache = true) { function getMaxVotes($useCache = true) {
static $_cache; static $_cache;
if (!isset($_cache) || !$useCache) { if (!isset($_cache) || !$useCache) {
$query = DB::query('SELECT MAX("Votes") As "Max" FROM "PollChoice" WHERE "PollID" = ' . $this->ID); $query = DB::query('SELECT MAX("Votes") As "Max" FROM "PollChoice" WHERE "PollID" = ' . $this->ID);
Expand Down
4 changes: 2 additions & 2 deletions code/PollChoice.php
Expand Up @@ -84,9 +84,9 @@ public function canDelete($member = null) {
* @param $formatPercent If true, return 55%, if not, return 0.55 * @param $formatPercent If true, return 55%, if not, return 0.55
*/ */
function getPercentage() { function getPercentage() {
$max = $this->Poll()->maxVotes(); $max = $this->Poll()->getMaxVotes();
if ($max==0) $max = 1; if ($max==0) $max = 1;
$ratio = $this->Votes/$this->Poll()->maxVotes(); $ratio = $this->Votes/$this->Poll()->getMaxVotes();
return ((int)($ratio*100)).'%'; return ((int)($ratio*100)).'%';
} }
} }
8 changes: 6 additions & 2 deletions code/PollForm.php
Expand Up @@ -107,7 +107,7 @@ function isForcedDisplay() {
/** /**
* Collate the information from PollForm and Poll to figure out if the results should be shown. * Collate the information from PollForm and Poll to figure out if the results should be shown.
*/ */
function shouldShowResults() { function getShouldShowResults() {
return $this->poll->isVoted() || $this->isForcedDisplay(); return $this->poll->isVoted() || $this->isForcedDisplay();
} }


Expand All @@ -121,6 +121,10 @@ function getShowResultsLink() {
/** /**
* URL to an chart image that is render by Google Chart API * URL to an chart image that is render by Google Chart API
* @link http://code.google.com/apis/chart/docs/making_charts.html * @link http://code.google.com/apis/chart/docs/making_charts.html
* This is quite rudimentary, and can be modified by combination of methods:
* - defining a PollForm decorator and replaceChart method
* - creating a custom PollForm.ss template in your theme folder
* - subclassing this form for full control
* *
* @return string * @return string
*/ */
Expand All @@ -145,7 +149,7 @@ function getChart() {
} }
$labels = implode('|', $labels); $labels = implode('|', $labels);
$data = implode(',', $data); $data = implode(',', $data);
$max = (int)(($this->poll->maxVotes()+1) * 1.5); $max = (int)(($this->poll->getMaxVotes()+1) * 1.5);
$height = $this->chartOptions['height']; $height = $this->chartOptions['height'];
$width = $this->chartOptions['width']; $width = $this->chartOptions['width'];
$colours = implode($this->chartOptions['colours'], '|'); $colours = implode($this->chartOptions['colours'], '|');
Expand Down
2 changes: 1 addition & 1 deletion templates/PollForm.ss
Expand Up @@ -10,7 +10,7 @@
$Poll.Description $Poll.Description
<% end_if %> <% end_if %>


<% if shouldShowResults %> <% if ShouldShowResults %>
$Chart $Chart
<% else %> <% else %>
$DefaultForm $DefaultForm
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/PollTest.php
Expand Up @@ -5,10 +5,10 @@ class PollTest extends SapphireTest {


function testTotalVotes() { function testTotalVotes() {
$mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll'); $mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll');
$this->assertEquals(120 + 80 + 12, $mobilePoll->totalVotes()); $this->assertEquals(120 + 80 + 12, $mobilePoll->getTotalVotes());


$mobilePoll = $this->ObjFromFixture('Poll', 'color-poll'); $mobilePoll = $this->ObjFromFixture('Poll', 'color-poll');
$this->assertEquals(6 + 15 + 30, $mobilePoll->totalVotes()); $this->assertEquals(6 + 15 + 30, $mobilePoll->getTotalVotes());
} }


function testChartURL() { function testChartURL() {
Expand All @@ -22,7 +22,7 @@ function testChartURL() {


function testMaxVotes() { function testMaxVotes() {
$mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll'); $mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll');
$this->assertEquals(120, $mobilePoll->maxVotes()); $this->assertEquals(120, $mobilePoll->getMaxVotes());
} }


function testVisible() { function testVisible() {
Expand Down

0 comments on commit ca4bd1a

Please sign in to comment.