Skip to content
This repository
branch: config-documen…
Fetching contributors…

Cannot retrieve contributors at this time

file 122 lines (93 sloc) 3.701 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
<?php

abstract class BugzillaOutput {

    public $response;
    public $cache;
    
    public function __construct($config, $options, $title='') {
        $this->title = $title;
        $this->config = $config;
        $this->response = new stdClass();

        // Make our query and possibly fetch the data
        $this->query = BugzillaQuery::create($config['type'], $options, $title);


        //error_log($this->query);
        //error_log($this->query->id());
        //error_log(print_r($this->query->data, true));

    }

    protected function _render_error() {
        $what = (!empty($this->error)) ? $this->error : 'Unknown Error';
        return "<div class='bugzilla error'>Bugzilla Error: $what</div>";
    }

    public function render() {
        global $wgBugzillaURL;
        // Get our template path
        $this->template = dirname(__FILE__) . '/templates/' .
                          $this->config['type'] . '/' .
                          $this->config['display'] . '.tpl';

        //error_log($this->template);

        // Make sure a template is there
        if( !file_exists($this->template) ) {
            $this->error = 'Invalid type and display combination';
        }

        $this->_setup_template_data();

        $response = $this->response;
        ob_start(); // Start output buffering.
        require($this->template);
        $results = ob_get_clean();
        return $results;

    }
    
    protected function _getCache()
    {
        global $wgCacheObject;
        if(!$this->cache) {
            $this->cache = new $wgCacheObject;
        }
        
        return $this->cache;
    }
    
    abstract public function _setup_template_data();

}

class BugzillaTable extends BugzillaOutput {

    public function _setup_template_data() {
        if(count($this->query->data->bugs) > 0) {
            $this->response->bugs = $this->query->data->bugs;
        } else {
            $this->response->bugs = array();
        }
    }
}

abstract class BugzillaGraph extends BugzillaOutput {

}

include 'pchart/class/pDraw.class.php';
include 'pchart/class/pImage.class.php';
include 'pchart/class/pData.class.php';

class BugzillaBarGraph extends BugzillaGraph {

    public function generate_chart($chart_name)
    {
        global $wgBugzillaChartStorage, $wgBugzillaFontStorage;
        $pData = new pData();
        $pData->addPoints($this->query->data->data, 'Counts');
        $pData->setAxisName(0, 'Bugs');
        $pData->addPoints($this->query->data->x_labels, "Bugs");
        $pData->setSerieDescription("Bugs", "Bugs");
        $pData->setAbscissa("Bugs");

        $pImage = new pImage(600,300, $pData);
        $pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => 6));
        $pImage->setGraphArea(75, 30, 580, 280);
        $pImage->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10, "Pos"=>SCALE_POS_TOPBOTTOM));

        $pImage->drawBarChart();
        $pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png');
        $cache = $this->_getCache();
        $cache->set($chart_name, $chart_name . '.png');
        return $chart_name;
    }

    public function _setup_template_data() {
        global $wgBugzillaChartUrl;
        $key = md5($this->query->id . '_bar_chart');
        $cache = $this->_getCache();
        if($result = $cache->get($key)) {
            $image = $result['data'];
            $this->response->image = $wgBugzillaChartUrl . '/' . $image;
        } else {
            $this->response->image = $wgBugzillaChartUrl . '/' . $this->generate_chart($key) . '.png';
        }
    }
}

?>
Something went wrong with that request. Please try again.