From ca4bd1ac642dd840f4c4b77c93d6a628ae4a23cb Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Fri, 22 Jul 2011 15:19:00 +1200 Subject: [PATCH] APICHANGE: rename the functions to conform with SS coding standard --- code/Poll.php | 4 ++-- code/PollChoice.php | 4 ++-- code/PollForm.php | 8 ++++++-- templates/PollForm.ss | 2 +- tests/unit/PollTest.php | 6 +++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/code/Poll.php b/code/Poll.php index a9d2ad6..ede221d 100644 --- a/code/Poll.php +++ b/code/Poll.php @@ -116,7 +116,7 @@ function getCMSFields() { * * @return int */ - function totalVotes($useCache = true) { + function getTotalVotes($useCache = true) { static $_cache; if (!isset($_cache) || !$useCache) { $query = DB::query('SELECT SUM("Votes") As "Total" FROM "PollChoice" WHERE "PollID" = ' . $this->ID); @@ -131,7 +131,7 @@ function totalVotes($useCache = true) { * 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? */ - function maxVotes($useCache = true) { + function getMaxVotes($useCache = true) { static $_cache; if (!isset($_cache) || !$useCache) { $query = DB::query('SELECT MAX("Votes") As "Max" FROM "PollChoice" WHERE "PollID" = ' . $this->ID); diff --git a/code/PollChoice.php b/code/PollChoice.php index 183a7e3..11c946a 100644 --- a/code/PollChoice.php +++ b/code/PollChoice.php @@ -84,9 +84,9 @@ public function canDelete($member = null) { * @param $formatPercent If true, return 55%, if not, return 0.55 */ function getPercentage() { - $max = $this->Poll()->maxVotes(); + $max = $this->Poll()->getMaxVotes(); if ($max==0) $max = 1; - $ratio = $this->Votes/$this->Poll()->maxVotes(); + $ratio = $this->Votes/$this->Poll()->getMaxVotes(); return ((int)($ratio*100)).'%'; } } diff --git a/code/PollForm.php b/code/PollForm.php index 72e6ba6..37ad31f 100644 --- a/code/PollForm.php +++ b/code/PollForm.php @@ -107,7 +107,7 @@ function isForcedDisplay() { /** * 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(); } @@ -121,6 +121,10 @@ function getShowResultsLink() { /** * URL to an chart image that is render by Google Chart API * @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 */ @@ -145,7 +149,7 @@ function getChart() { } $labels = implode('|', $labels); $data = implode(',', $data); - $max = (int)(($this->poll->maxVotes()+1) * 1.5); + $max = (int)(($this->poll->getMaxVotes()+1) * 1.5); $height = $this->chartOptions['height']; $width = $this->chartOptions['width']; $colours = implode($this->chartOptions['colours'], '|'); diff --git a/templates/PollForm.ss b/templates/PollForm.ss index 3fa2725..7d4ab0b 100644 --- a/templates/PollForm.ss +++ b/templates/PollForm.ss @@ -10,7 +10,7 @@ $Poll.Description <% end_if %> - <% if shouldShowResults %> + <% if ShouldShowResults %> $Chart <% else %> $DefaultForm diff --git a/tests/unit/PollTest.php b/tests/unit/PollTest.php index 054a818..e9b53cb 100644 --- a/tests/unit/PollTest.php +++ b/tests/unit/PollTest.php @@ -5,10 +5,10 @@ class PollTest extends SapphireTest { function testTotalVotes() { $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'); - $this->assertEquals(6 + 15 + 30, $mobilePoll->totalVotes()); + $this->assertEquals(6 + 15 + 30, $mobilePoll->getTotalVotes()); } function testChartURL() { @@ -22,7 +22,7 @@ function testChartURL() { function testMaxVotes() { $mobilePoll = $this->ObjFromFixture('Poll', 'mobile-poll'); - $this->assertEquals(120, $mobilePoll->maxVotes()); + $this->assertEquals(120, $mobilePoll->getMaxVotes()); } function testVisible() {