|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CMEN\GoogleChartsBundle\Output; |
|
4
|
|
|
|
|
5
|
|
|
use CMEN\GoogleChartsBundle\Exception\GoogleChartsException; |
|
6
|
|
|
use CMEN\GoogleChartsBundle\GoogleCharts\Chart; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author Christophe Meneses |
|
10
|
|
|
*/ |
|
11
|
|
|
abstract class AbstractChartOutput implements ChartOutputInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Version of Google Charts used. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $version; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Locale to customize currencies, dates, and numbers. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $language; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* AbstractChartOutput constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $version |
|
31
|
|
|
* @param string $language |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($version, $language) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->version = $version; |
|
36
|
|
|
$this->language = $language; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $language |
|
41
|
|
|
* |
|
42
|
|
|
* @return $this |
|
43
|
|
|
*/ |
|
44
|
|
|
public function setLanguage($language) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->language = $language; |
|
47
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Checks if all elements ID are string and same number as charts. |
|
53
|
|
|
* |
|
54
|
|
|
* @param Chart[] $charts |
|
55
|
|
|
* @param string[] $elementsID |
|
56
|
|
|
* |
|
57
|
|
|
* @throws GoogleChartsException |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function checkElementsId(array $charts, array $elementsID) |
|
60
|
|
|
{ |
|
61
|
|
|
if (count($charts) != count($elementsID)) { |
|
62
|
|
|
throw new GoogleChartsException( |
|
63
|
|
|
'Array charts and array HTML elements ID do not have the same number of element.' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
foreach ($elementsID as $elementId) { |
|
68
|
|
|
if (!is_string($elementId)) { |
|
69
|
|
|
throw new GoogleChartsException('A string is expected for HTML element ID.'); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Checks if all elements of an array are instances of Chart. Throws an exception if not. |
|
76
|
|
|
* |
|
77
|
|
|
* @param Chart[] $charts |
|
78
|
|
|
* |
|
79
|
|
|
* @throws GoogleChartsException |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function checkChartsTypes(array $charts) |
|
82
|
|
|
{ |
|
83
|
|
|
foreach ($charts as $chart) { |
|
84
|
|
|
if (!$chart instanceof Chart) { |
|
85
|
|
|
throw new GoogleChartsException('An array of Chart is expected.'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|