Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 258 lines (200 sloc) 8.131 kb
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
1 <?php
2
3 abstract class BugzillaOutput {
4
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
5 public $response;
6 public $cache;
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
7
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
8 public function __construct($config, $options, $title='') {
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
9 $this->title = $title;
10 $this->config = $config;
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
11 $this->error = false;
56e22ec @brandonsavage Removing SMARTY templating from the extension.
brandonsavage authored
12 $this->response = new stdClass();
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
13
14 // Make our query and possibly fetch the data
15 $this->query = BugzillaQuery::create($config['type'], $options, $title);
16
d0a1f77 @LegNeato Report json errors to the user
LegNeato authored
17 // Bubble up any query errors
18 if( $this->query->error ) {
19 $this->error = $this->query->error;
20 }
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
21 }
22
d0a1f77 @LegNeato Report json errors to the user
LegNeato authored
23 protected function _render_error($error) {
24 $this->template = dirname(__FILE__) . '/templates/error.tpl';
25 ob_start(); // Start output buffering.
26 require($this->template);
27 return ob_get_clean();
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
28 }
29
30 public function render() {
31 // Get our template path
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
32 $this->template = dirname(__FILE__) . '/templates/' .
33 $this->config['type'] . '/' .
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
34 $this->config['display'] . '.tpl';
35
36 // Make sure a template is there
37 if( !file_exists($this->template) ) {
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
38 $this->error = 'Invalid type ' .
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
39 '(' . htmlspecialchars($this->config['type']) . ')' .
40 ' and display ' .
41 '(' . htmlspecialchars($this->config['display']) . ')' .
42 ' combination';
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
43 }
44
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
45 // If there are any errors (either from the template path above or
d0a1f77 @LegNeato Report json errors to the user
LegNeato authored
46 // elsewhere) output them
47 if( $this->error ) {
48 return $this->_render_error($this->error);
49 }
50
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
51 $this->setup_template_data();
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
52
56e22ec @brandonsavage Removing SMARTY templating from the extension.
brandonsavage authored
53 $response = $this->response;
54 ob_start(); // Start output buffering.
55 require($this->template);
56 $results = ob_get_clean();
57 return $results;
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
58
59 }
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
60
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
61 protected function _getCache()
62 {
7f1d0a1 @rdalverny More generic layout for caching.
rdalverny authored
63 if (!$this->cache) {
64 $this->cache = Bugzilla::getCache();
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
65 }
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
66
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
67 return $this->cache;
68 }
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
69
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
70 abstract protected function setup_template_data();
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
71
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
72 }
73
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
74 class BugzillaBugListing extends BugzillaOutput {
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
75
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
76 protected function setup_template_data() {
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
77
78 global $wgBugzillaDefaultFields;
79
80 $this->response->bugs = array();
81 $this->response->fields = array();
82
83 // Set the bug data for the templates
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
84 if(isset($this->query->data['bugs']) && count($this->query->data['bugs']) > 0) {
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
85 $this->response->bugs = $this->query->data['bugs'];
86 }
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
87
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
88 // Set the field data for the templates
89 if( isset($this->query->options['include_fields']) &&
90 !empty($this->query->options['include_fields']) ) {
91 // User specified some fields
92 $tmp = @explode(',', $this->query->options['include_fields']);
93 foreach( $tmp as $tmp_field ) {
94 $field = trim($tmp_field);
95 // Catch if the user specified the same field multiple times
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
96 if( !empty($field) &&
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
97 !in_array($field, $this->response->fields) ) {
98 array_push($this->response->fields, $field);
99 }
100 }
101 }else {
102 // If the user didn't specify any fields in the query config use
103 // default fields
104 $this->response->fields = $wgBugzillaDefaultFields;
56e22ec @brandonsavage Removing SMARTY templating from the extension.
brandonsavage authored
105 }
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
106 }
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
107
108 }
109
110 class BugzillaList extends BugzillaBugListing {
111
112 }
113
114 class BugzillaTable extends BugzillaBugListing {
115
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
116 }
117
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
118
119 /* Graphing */
120
5608d76 @brandonsavage Typical PHP standards dictate that you should avoid calling methods
brandonsavage authored
121 abstract class BugzillaGraph extends BugzillaOutput {
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
122
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
123 protected function _get_size() {
124
125 switch($this->config['size']) {
126
127 // whitelist
128 case 'small':
129 case 'medium':
130 case 'large':
131 return $this->config['size'];
132 break;
133
134 default:
135 return 'large';
136 }
137 }
138
139 public function setup_template_data() {
140 include_once 'pchart/class/pDraw.class.php';
141 include_once 'pchart/class/pImage.class.php';
142 include_once 'pchart/class/pData.class.php';
143
144 global $wgBugzillaChartUrl;
145
146 $key = md5($this->query->id . $this->_get_size() . get_class($this));
147 $cache = $this->_getCache();
148 if($result = $cache->get($key)) {
9f56cca @brandonsavage Improving the caching mechanism, in preparation for providing a memcache...
brandonsavage authored
149 $image = $result;
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
150 $this->response->image = $wgBugzillaChartUrl . '/' . $image;
151 } else {
152 $this->response->image = $wgBugzillaChartUrl . '/' . $this->generate_chart($key) . '.png';
fc6efe7 @reedy Fix Undefined index: bugs in BugzillaOutput.class.php on line 85
reedy authored
153 }
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
154 }
155
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
156 }
157
bf20a79 @LegNeato Add a new pie chart type. Support small/medium/large pie chart size
LegNeato authored
158 class BugzillaPieGraph extends BugzillaGraph {
159
160 public function generate_chart($chart_name)
161 {
162 include_once "pchart/class/pPie.class.php";
163
164 global $wgBugzillaChartStorage;
165 global $wgBugzillaFontStorage;
166
167 // TODO: Make all this size stuff trivial for other
168 // graph types to plug into
169 switch($this->_get_size()) {
170 case 'small':
171 $imgX = 200;
172 $imgY = 65;
173 $radius = 30;
174 $font = 6;
175 break;
176
177 case 'medium':
178 $imgX = 400;
179 $imgY = 125;
180 $radius = 60;
181 $font = 7;
182 break;
183
184 case 'large':
185 default:
186 $imgX = 500;
187 $imgY = 245;
188 $radius = 120;
189 $font = 9;
190 }
191
192 $padding = 5;
193
194 $startX = ( isset($startX) ) ? $startX : $radius;
195 $startY = ( isset($startY) ) ? $startY : $radius;
196
197 $pData = new pData();
198 $pData->addPoints($this->query->data['data'], 'Counts');
199 $pData->setAxisName(0, 'Bugs');
200 $pData->addPoints($this->query->data['x_labels'], "Bugs");
201 $pData->setSerieDescription("Bugs", "Bugs");
202 $pData->setAbscissa("Bugs");
203
204 $pImage = new pImage($imgX, $imgY, $pData);
205 $pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => $font));
206 $pPieChart = new pPie($pImage, $pData);
207
208 $pPieChart->draw2DPie($startX,
209 $startY,
210 array(
211 "Radius" => $radius,
212 "ValuePosition" => PIE_VALUE_INSIDE,
213 "WriteValues"=>PIE_VALUE_NATURAL,
214 "DrawLabels"=>FALSE,
215 "LabelStacked"=>TRUE,
216 "ValueR" => 0,
217 "ValueG" => 0,
218 "ValueB" => 0,
219 "Border"=>TRUE));
220
221 // Legend
222 $pImage->setShadow(FALSE);
223 $pPieChart->drawPieLegend(2*$radius + 2*$padding, $padding, array("Alpha"=>20));
224
225 $pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png');
226 $cache = $this->_getCache();
227 $cache->set($chart_name, $chart_name . '.png');
228 return $chart_name;
229 }
230 }
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
231
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
232 class BugzillaBarGraph extends BugzillaGraph {
233
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
234 public function generate_chart($chart_name)
235 {
236 global $wgBugzillaChartStorage, $wgBugzillaFontStorage;
237 $pData = new pData();
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
238 $pData->addPoints($this->query->data['data'], 'Counts');
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
239 $pData->setAxisName(0, 'Bugs');
5a4db4a @LegNeato Fix support for jquery tables, add the ability to specify fields,
LegNeato authored
240 $pData->addPoints($this->query->data['x_labels'], "Bugs");
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
241 $pData->setSerieDescription("Bugs", "Bugs");
242 $pData->setAbscissa("Bugs");
243
244 $pImage = new pImage(600,300, $pData);
245 $pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => 6));
246 $pImage->setGraphArea(75, 30, 580, 280);
1e43de6 @LegNeato Make bar charts use whole numbers in the scale
LegNeato authored
247 $pImage->drawScale(array("CycleBackground"=>TRUE,'Factors'=>array(1),"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10, "Pos"=>SCALE_POS_TOPBOTTOM));
8c4fd3a @brandonsavage Adding charting library and improving the charting of the application.
brandonsavage authored
248
249 $pImage->drawBarChart();
250 $pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png');
251 $cache = $this->_getCache();
252 $cache->set($chart_name, $chart_name . '.png');
253 return $chart_name;
254 }
255
b62c6d9 @LegNeato Big refactoring.
LegNeato authored
256 }
257
Something went wrong with that request. Please try again.