00001 <?php
00008 class SRFGooglePie extends SMWResultPrinter {
00009
00010 protected $m_width = 250;
00011 protected $m_heighth = 100;
00012
00017 protected function handleParameters( array $params, $outputmode ) {
00018 parent::handleParameters( $params, $outputmode );
00019
00020 $this->m_width = $this->m_params['width'];
00021 $this->m_height = $this->m_params['height'];
00022 }
00023
00024 public function getName() {
00025 return wfMsg( 'srf_printername_googlepie' );
00026 }
00027
00028 protected function getResultText( SMWQueryResult $res, $outputmode ) {
00029 $this->isHTML = true;
00030
00031 $t = "";
00032 $n = "";
00033
00034
00035 if ($res->getColumnCount() == 1) return "";
00036
00037
00038 $first = true;
00039 $max = 0;
00040
00041 while ( $row = $res->getNext() ) {
00042 $name = $row[0]->getNextDataValue()->getShortWikiText();
00043
00044 foreach ( $row as $field ) {
00045 while ( ( $object = $field->getNextDataValue() ) !== false ) {
00046
00047 if ( $object->isNumeric() ) {
00048 $nr = $object->getDataItem()->getSortKey();
00049
00050 $max = max( $max, $nr );
00051
00052 if ( $first ) {
00053 $first = false;
00054 $t .= $nr;
00055 $n = $name;
00056 } else {
00057 $t = $nr . ',' . $t;
00058 $n = $name . '|' . $n;
00059 }
00060 }
00061 }
00062 }
00063 }
00064
00065 return '<img src="http://chart.apis.google.com/chart?cht=p3&chs=' . $this->m_width . 'x' . $this->m_height . '&chds=0,' . $max . '&chd=t:' . $t . '&chl=' . $n . '" width="' . $this->m_width . '" height="' . $this->m_height . '" />';
00066 }
00067
00068 public function getParameters() {
00069 $params = parent::getParameters();
00070
00071 $params['height'] = new Parameter( 'height', Parameter::TYPE_INTEGER, 100 );
00072 $params['height']->setMessage( 'srf_paramdesc_chartheight' );
00073
00074 $params['width'] = new Parameter( 'width', Parameter::TYPE_INTEGER, 250 );
00075 $params['width']->setMessage( 'srf_paramdesc_chartwidth' );
00076
00077 return $params;
00078 }
00079
00080 }