Esempio n. 1
0
 function countResponses()
 {
     $pr = new Poll_response();
     $pr->poll_id = $this->id;
     $pr->groupBy('selection');
     $pr->selectAdd('count(profile_id) as votes');
     $pr->find();
     $raw = array();
     while ($pr->fetch()) {
         // Votes list 1-based
         // Array stores 0-based
         $raw[$pr->selection - 1] = $pr->votes;
     }
     $counts = array();
     foreach (array_keys($this->getOptions()) as $key) {
         if (isset($raw[$key])) {
             $counts[$key] = $raw[$key];
         } else {
             $counts[$key] = 0;
         }
     }
     return $counts;
 }