1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ReportBundle package |
5
|
|
|
* |
6
|
|
|
* (c) symball <http://simonball.me> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE file |
9
|
|
|
* that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Symball\ReportBundle\Patterns; |
13
|
|
|
|
14
|
|
|
use Symball\ReportBundle\Interfaces\PatternInterface; |
15
|
|
|
use Symball\ReportBundle\Service\ReportBuilder; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* This pattern fills in the values for the various data points within the |
19
|
|
|
* current set |
20
|
|
|
* |
21
|
|
|
* @author Simon Ball <simonball at simonball dot me> |
22
|
|
|
*/ |
23
|
|
|
class DataSet implements PatternInterface |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
public function run(ReportBuilder &$context) |
27
|
|
|
{ |
28
|
|
|
$data = $context->meta()->getDataSet(); |
29
|
|
|
$nav = $context->nav(); |
30
|
|
|
|
31
|
|
|
foreach ($data as $key => $fields) { |
32
|
|
|
foreach ($fields as $fieldKey => $options) { |
33
|
|
|
// TODO Make sanity check and don't have it in the drawing code |
34
|
|
|
if (!isset($options['visible']) || $options['visible'] !== true) { |
35
|
|
|
continue; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$value = $options['value']; |
39
|
|
|
$context->write($value); |
40
|
|
|
|
41
|
|
|
// TODO Move this |
42
|
|
|
if (isset($options['display_options'])) { |
43
|
|
|
foreach ($options['display_options'] as $option) { |
44
|
|
|
switch ($option) { |
45
|
|
View Code Duplication |
case 'highlight_positive': |
|
|
|
|
46
|
|
|
if (0 < $value) { |
47
|
|
|
|
48
|
|
|
$color = $context->meta()->getOption('positive_color'); |
49
|
|
|
$context->style('bg', (string) $nav, [ |
50
|
|
|
'color' => $color |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
break; |
55
|
|
View Code Duplication |
case 'highlight_negative': |
|
|
|
|
56
|
|
|
if (0 > $value) { |
57
|
|
|
$color = $context->meta()->getOption('negative_color'); |
58
|
|
|
$context->style('bg', (string) $nav, [ |
59
|
|
|
'color' => $color |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
break; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
$nav->right(); |
67
|
|
|
} |
68
|
|
|
$nav->next(); |
69
|
|
|
} |
70
|
|
|
// Draw the edge line |
71
|
|
|
$start = $nav->coord('current', 'initial'); |
72
|
|
|
$end = $nav->coord('current', ($nav->row() - 1)); |
73
|
|
|
|
74
|
|
|
$context->style('border', $start.':'.$end, ['edge' => 'left']); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.