Permalink
Browse files

APICHANGE: rename the functions to conform with SS coding standard

  • Loading branch information...
1 parent 8277763 commit ca4bd1ac642dd840f4c4b77c93d6a628ae4a23cb @mateusz committed Jul 22, 2011
Showing with 14 additions and 10 deletions.
  1. +2 −2 code/Poll.php
  2. +2 −2 code/PollChoice.php
  3. +6 −2 code/PollForm.php
  4. +1 −1 templates/PollForm.ss
  5. +3 −3 tests/unit/PollTest.php
View
@@ -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);
View
@@ -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)).'%';
}
}
View
@@ -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'], '|');
View
@@ -10,7 +10,7 @@
$Poll.Description
<% end_if %>
- <% if shouldShowResults %>
+ <% if ShouldShowResults %>
$Chart
<% else %>
$DefaultForm
View
@@ -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() {

0 comments on commit ca4bd1a

Please sign in to comment.