report_user_per_group.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if ( !class_exists( "report_user_per_group")) {
00007 class Report_user_per_group extends report_base
00008 {
00014     protected $_sThisTemplate = "report_user_per_group.tpl";
00015 
00021     public function drawReport()
00022     {
00023         $sQ = "SELECT 1 FROM oxobject2group, oxuser, oxgroups
00024                WHERE oxobject2group.oxobjectid = oxuser.oxid AND
00025                oxobject2group.oxgroupsid = oxgroups.oxid";
00026         return oxDb::getDb()->getOne( $sQ );
00027     }
00028 
00034     public function user_per_group()
00035     {
00036         $myConfig = $this->getConfig();
00037         $oDb = oxDb::getDb();
00038 
00039         global $aTitles;
00040 
00041         $aDataX = array();
00042         $aDataY = array();
00043 
00044         $sSQL = "SELECT oxgroups.oxtitle,
00045                         count(oxuser.oxid)
00046                  FROM oxobject2group,
00047                       oxuser,
00048                       oxgroups
00049                  WHERE oxobject2group.oxobjectid = oxuser.oxid  AND
00050                        oxobject2group.oxgroupsid = oxgroups.oxid
00051                  GROUP BY oxobject2group.oxgroupsid
00052                  ORDER BY oxobject2group.oxgroupsid";
00053 
00054         $rs = $oDb->execute( $sSQL);
00055         if ($rs != false && $rs->recordCount() > 0) {
00056             while (!$rs->EOF) {
00057                 if ( $rs->fields[1]) {
00058                     $aDataX[] = $rs->fields[1];
00059                     $aDataY[] = $rs->fields[0];
00060                 }
00061                 $rs->moveNext();
00062             }
00063         }
00064 
00065         header ("Content-type: image/png" );
00066 
00067         // New graph with a drop shadow
00068         if (count($aDataX) > 10)
00069             $graph = new PieGraph(800, 830);
00070         else
00071             $graph = new PieGraph(600, 600);
00072 
00073         $graph->setBackgroundImage( $myConfig->getImageDir(true)."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00074         $graph->setShadow();
00075 
00076         // Set title and subtitle
00077         //$graph->title->set($this->aTitles[$myConfig->getConfigParam( 'iAdminLanguage' ) ]);
00078         $graph->title->set($this->aTitles[oxLang::getInstance()->getObjectTplLanguage() ]);
00079 
00080         // Use built in font
00081         $graph->title->setFont(FF_FONT1, FS_BOLD);
00082 
00083         // Create the bar plot
00084         $bplot = new PiePlot3D($aDataX);
00085 
00086         $bplot->setSize(0.4);
00087         $bplot->setCenter(0.5, 0.32);
00088 
00089         // explodes all chunks of Pie from center point
00090         $bplot->explodeAll(10);
00091         $iUserCount = 0;
00092         foreach ($aDataX as $iVal)
00093             $iUserCount += $iVal;
00094         for ($iCtr = 0; $iCtr < count($aDataX); $iCtr++) {
00095             $iSLeng = strlen($aDataY[$iCtr]);
00096             if ($iSLeng > 20) {
00097                 if ($iSLeng > 23)
00098                     $aDataY[$iCtr] = trim(substr($aDataY[$iCtr], 0, 20))."...";
00099 
00100             }
00101             $aDataY[$iCtr] .= " - ".$aDataX[$iCtr]." Kund.";
00102         }
00103         $bplot->setLegends($aDataY);
00104 
00105         if (count($aDataX) > 10) {
00106             $graph->legend->pos(0.49, 0.66, 'center');
00107             $graph->legend->setFont(FF_FONT0, FS_NORMAL);
00108             $graph->legend->setColumns(4);
00109         } else {
00110             $graph->legend->pos(0.49, 0.70, 'center');
00111             $graph->legend->setFont(FF_FONT1, FS_NORMAL);
00112             $graph->legend->setColumns(2);
00113         }
00114 
00115         $graph->add($bplot);
00116 
00117         // Finally output the  image
00118         $graph->stroke();
00119     }
00120 }
00121 }