summaryrefslogtreecommitdiffstats
path: root/application/classes/model
diff options
context:
space:
mode:
Diffstat (limited to 'application/classes/model')
-rw-r--r--application/classes/model/option.php12
-rw-r--r--application/classes/model/poll.php13
2 files changed, 25 insertions, 0 deletions
diff --git a/application/classes/model/option.php b/application/classes/model/option.php
new file mode 100644
index 0000000..b143913
--- /dev/null
+++ b/application/classes/model/option.php
@@ -0,0 +1,12 @@
+<?php
+class Option_Model extends ORM{
+ public $belongs_to = array('poll');
+
+ public function get($property) {
+ if ($property == 'percent') {
+ if($this->poll->total_votes==0)
+ return 0;
+ return floor($this->votes/$this->poll->total_votes*100);
+ }
+ }
+} \ No newline at end of file
diff --git a/application/classes/model/poll.php b/application/classes/model/poll.php
new file mode 100644
index 0000000..a2cfe08
--- /dev/null
+++ b/application/classes/model/poll.php
@@ -0,0 +1,13 @@
+<?php
+class Poll_Model extends ORM{
+ public $has_many=array('options');
+
+ public function get($property){
+ if ($property == 'total_votes') {
+ $total=0;
+ foreach($this->options->find_all() as $option)
+ $total += $option->votes;
+ return $total;
+ }
+ }
+} \ No newline at end of file