Beispiel #1
0
 /**
  * Renders this widget via the given view and returns the
  * HTML as a string
  *
  * @return string
  */
 public function render()
 {
     if ($this->view()->layout()->getLayout() === 'pdf') {
         $pie = new PieChart();
         $pie->alignTopLeft();
         $pie->disableLegend();
         $pie->drawPie(array('data' => $this->data, 'colors' => $this->colors));
         try {
             $png = $pie->toPng($this->size, $this->size);
             return '<img class="inlinepie" src="data:image/png;base64,' . base64_encode($png) . '" />';
         } catch (IcingaException $_) {
             return '';
         }
     }
     $template = $this->template;
     // TODO: Check whether we are XHR and don't send
     $template = str_replace('{noscript}', $this->noscript, $template);
     $template = str_replace('{url}', $this->url, $template);
     $template = str_replace('{class}', $this->class, $template);
     // style
     $template = str_replace('{size}', isset($this->size) ? $this->size : 16, $template);
     $template = str_replace('{title}', $this->title, $template);
     $template = str_replace('{colors}', implode(',', $this->colors), $template);
     // Locale-ignorant string cast. Please. Do. NOT. Remove. This. Again.
     // Problem is that implode respects locales when casting floats. This means
     // that implode(',', array(1.1, 1.2)) would read '1,1,1,2'.
     $data = array();
     foreach ($this->data as $dat) {
         $data[] = sprintf('%F', $dat);
     }
     $template = str_replace('{data}', htmlspecialchars(implode(',', $data)), $template);
     return $template;
 }