Ejemplo n.º 1
0
 /**
  * @return Chart
  */
 public static function getChart($cate)
 {
     /** @var Chart $chart */
     $chart = new Chart();
     $db = DB::getConn();
     $stm = $db->prepare('select uid, cate, ans from Answers where cate=:cate');
     $stm->bindParam(':cate', $cate);
     $stm->execute();
     $rs = $stm->fetchAll();
     $legends = [];
     foreach ($rs as $r) {
         $results = QuestionCtrl::getResByID($r['uid'], $r['cate']);
         $mark = 0;
         $total = 0;
         foreach ($results as $result) {
             $total += $result->getPoint();
             $mark += $result->getMark();
         }
         if ($total != 0) {
             $legends[] = number_format($mark * 100 / $total, 1, '.', ',');
         }
     }
     $chart->setLegends($legends);
     return $chart;
 }