initial commit
[namibia] / module / Utility / src / Utility / Service / Report.php
1 <?php
2 namespace Utility\Service;
3
4
5
6 /**
7  * Base reporting functionality.
8  * @author andre.fourie
9  *
10  */
11 abstract class Report
12 {
13
14         /**
15          * @var \Doctrine\ORM\EntityManager
16          */
17         protected $em;
18         /**
19          * Report title.
20          * @var string
21          */
22         protected $_title  = null;
23         /**
24          * Report subject.
25          * @var string
26          */
27         protected $_subject = null;
28         /**
29          * Report description.
30          * @var string
31          */
32         protected $_description = null;
33         /**
34          * @var string
35          */
36         protected $_format = null;
37         /**
38          * Queries applied to the report.
39          * @var array
40          */
41         protected $_queries = array();
42         /**
43          * Column headers.
44          * @var array
45          */
46         protected $_headers = array();
47         /**
48          * Fields to pull from dataset.
49          * @var array
50          */
51         protected $_fields = array();
52         /**
53          * Columns to provide totals for.
54          * @var array
55          */
56         protected $_totals = array();
57         /**
58          * Columns for currency format.
59          * @var array
60          */
61         protected $_currencyFields = array();
62         /**
63          * Notes to display at end of report.
64          * @var array
65          */
66         protected $_notes = array();
67         /**
68          * Chart from report data.
69          * @var array
70          */
71         protected $_chart = array();
72         /**
73          * @var array
74          */
75         protected $_data = array();
76         /**
77          * Request object.
78          * @var Struct_ActionRequest
79          */
80         protected $_request = null;
81         /**
82          * Options to passed.
83          * @var object
84          */
85         protected $_options = array();
86         /**
87          * Data passed.
88          * @var array
89          */
90         protected $_input = array();
91
92
93         /* ---------------------------------------------------------------------- *\
94          *      Standard Interface
95         \* ---------------------------------------------------------------------- */
96         /**
97          * Process standard format request.
98          * @param array $input
99          * @param array|object $options
100          */
101         public function process(array $input, $options, $data = null)
102         {
103                 $this->em = \Utility\Registry::getEntityManager();
104                 $this->_input   = $input;
105                 $this->_options = $options;
106                 is_array($data)
107                         && $this->_data = $data;
108                 $this->build();
109                 return $this;
110         }
111
112         /**
113          * Build the dataset.
114          */
115         public function build() {}
116
117
118         /* ---------------------------------------------------------------------- *\
119          * Specifically cater for Excel Report requirements.
120         \* ---------------------------------------------------------------------- */
121         /**
122          * Retrieve report title.
123          * @return string
124          */
125         public function getTitle()
126         {
127                 return $this->_title;
128         }
129
130         /**
131          * Retrieve report subject.
132          * @return string
133          */
134         public function getSubject()
135         {
136                 return $this->_subject;
137         }
138
139         /**
140          * Retrieve report description.
141          * @return string
142          */
143         public function getDescription()
144         {
145                 return $this->_description;
146         }
147
148         /**
149          * Retrieve report format.
150          * @return string
151          */
152         public function getFormat()
153         {
154                 return $this->_format;
155         }
156
157         /**
158          * Retrieve queries to display at beginning of report.
159          * @return array
160          */
161         public function getQueries()
162         {
163                 return $this->_queries;
164         }
165
166         /**
167          * Retrieve report column headers.
168          * @return array
169          */
170         public function getHeaders()
171         {
172                 return $this->_headers;
173         }
174
175         /**
176          * Retrieve report fields.
177          * @return array
178          */
179         public function getFields()
180         {
181                 return $this->_fields;
182         }
183
184         /**
185          * Retrieve report fields to receive total value at end of report.
186          * @return array
187          */
188         public function getTotalFields()
189         {
190                 return $this->_totals;
191         }
192
193         /**
194          * Retrieve report fields to receive currency formatting.
195          * @return array
196          */
197         public function getCurrencyFields()
198         {
199                 return $this->_currencyFields;
200         }
201
202         /**
203          * Retrieve notes to be added to end of report.
204          * @return array
205          */
206         public function getNotes()
207         {
208                 return $this->_notes;
209         }
210
211         /**
212          * Retrieve chart specifications.
213          * @return array
214          */
215         public function getChart()
216         {
217                 return $this->_chart;
218         }
219
220         /**
221          * Retrieve report data.
222          * @return array
223          */
224         public function getData()
225         {
226                 return $this->_data;
227         }
228
229         /**
230          * Retrieve report data.
231          * @return array
232          */
233         public function getDataIntersection()
234         {
235                 $fields = array_flip($this->_fields);
236                 foreach ($this->_data as $id => $row)
237                 {
238                         $this->_data[$id] = array_intersect_key($row, $fields);
239                 }
240                 return $this->_data;
241         }
242
243
244 }
245