|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2017 Francois-Xavier Soubirou. |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of ci-report. |
|
7
|
|
|
* |
|
8
|
|
|
* ci-report is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* ci-report is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with ci-report. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
namespace App\Twig; |
|
24
|
|
|
|
|
25
|
|
|
use Twig_Extension; |
|
26
|
|
|
use Twig_SimpleFunction; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* graph.js values from campaigns array class Twig extension. |
|
30
|
|
|
* |
|
31
|
|
|
* @category ci-report app |
|
32
|
|
|
* |
|
33
|
|
|
* @author Francois-Xavier Soubirou <[email protected]> |
|
34
|
|
|
* @copyright 2017 Francois-Xavier Soubirou |
|
35
|
|
|
* @license http://www.gnu.org/licenses/ GPLv3 |
|
36
|
|
|
* |
|
37
|
|
|
* @see https://www.ci-report.io |
|
38
|
|
|
*/ |
|
39
|
|
|
class GraphSuitesValues extends Twig_Extension |
|
40
|
|
|
{ |
|
41
|
|
|
/** |
|
42
|
|
|
* Returns a list of functions to add to the existing list. |
|
43
|
|
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getFunctions(): array |
|
47
|
|
|
{ |
|
48
|
|
|
return array( |
|
49
|
|
|
new Twig_SimpleFunction('graphBarSuitesValues', array($this, 'getValues')), |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Return values of graph bars for campaigns. |
|
55
|
|
|
* |
|
56
|
|
|
* @param array $suites Array of suites |
|
57
|
|
|
* |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getValues(array $suites): array |
|
61
|
|
|
{ |
|
62
|
|
|
$yAxisValues = ''; |
|
63
|
|
|
$redValues = ''; |
|
64
|
|
|
$yellowValues = ''; |
|
65
|
|
|
$greenValues = ''; |
|
66
|
|
|
|
|
67
|
|
|
foreach ($suites as $suite) { |
|
68
|
|
|
$yAxisValues .= '"#'.$suite->getRefid().'",'; |
|
69
|
|
|
$redValues .= $suite->getErrored() + $suite->getFailed().','; |
|
70
|
|
|
$yellowValues .= $suite->getSkipped().','; |
|
71
|
|
|
$greenValues .= $suite->getPassed().','; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return array( |
|
75
|
|
|
'yAxis' => $yAxisValues, |
|
76
|
|
|
'red' => $redValues, |
|
77
|
|
|
'yellow' => $yellowValues, |
|
78
|
|
|
'green' => $greenValues, |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|