コード例 #1
0
ファイル: ReportController.php プロジェクト: echiteri/iBLIS
 /**
  * Display prevalence rates chart
  *
  * @return Response
  */
 public static function getPrevalenceRatesChart($testTypeID = 0)
 {
     $from = Input::get('start');
     $to = Input::get('end');
     $months = json_decode(self::getMonths($from, $to));
     $testTypes = new Illuminate\Database\Eloquent\Collection();
     if ($testTypeID == 0) {
         $testTypes = TestType::supportPrevalenceCounts();
     } else {
         $testTypes->add(TestType::find($testTypeID));
     }
     $options = '{
         "chart": {
             "type": "spline"
         },
         "title": {
             "text":"' . trans('messages.prevalence-rates') . '"
         },
         "subtitle": {
             "text":';
     if ($from == $to) {
         $options .= '"' . trans('messages.for-the-year') . ' ' . date('Y') . '"';
     } else {
         $options .= '"' . trans('messages.from') . ' ' . $from . ' ' . trans('messages.to') . ' ' . $to . '"';
     }
     $options .= '},
         "credits": {
             "enabled": false
         },
         "navigation": {
             "buttonOptions": {
                 "align": "right"
             }
         },
         "series": [';
     $counts = count($testTypes);
     foreach ($testTypes as $testType) {
         $options .= '{
                         "name": "' . $testType->name . '","data": [';
         $counter = count($months);
         foreach ($months as $month) {
             $data = $testType->getPrevalenceCount($month->annum, $month->months);
             if ($data->isEmpty()) {
                 $options .= '0.00';
                 if ($counter == 1) {
                     $options .= '';
                 } else {
                     $options .= ',';
                 }
             } else {
                 foreach ($data as $datum) {
                     $options .= $datum->rate;
                     if ($counter == 1) {
                         $options .= '';
                     } else {
                         $options .= ',';
                     }
                 }
             }
             $counter--;
         }
         $options .= ']';
         if ($counts == 1) {
             $options .= '}';
         } else {
             $options .= '},';
         }
         $counts--;
     }
     $options .= '],
         "xAxis": {
             "categories": [';
     $count = count($months);
     foreach ($months as $month) {
         $options .= '"' . $month->label . " " . $month->annum;
         if ($count == 1) {
             $options .= '" ';
         } else {
             $options .= '" ,';
         }
         $count--;
     }
     $options .= ']
         },
         "yAxis": {
             "title": {
                 "text": "' . trans('messages.prevalence-rates-label') . '"
             },
             "min": "0",
             "max": "100"
         }
     }';
     return $options;
 }