Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TaoEventLog | |
0.00% |
0 / 21 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| search | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| export | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| getParameter | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2016 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoEventLog\controller; |
| 24 | |
| 25 | use oat\taoEventLog\model\datatable\EventLogDatatable; |
| 26 | use oat\taoEventLog\model\export\implementation\LogEntryCsvStdOutExporter; |
| 27 | use oat\taoEventLog\model\export\implementation\LogEntryRepository; |
| 28 | use tao_actions_CommonModule; |
| 29 | |
| 30 | /** |
| 31 | * Sample controller |
| 32 | * |
| 33 | * @author Open Assessment Technologies SA |
| 34 | * @package taoEventLog |
| 35 | * @license GPL-2.0 |
| 36 | * |
| 37 | */ |
| 38 | class TaoEventLog extends tao_actions_CommonModule |
| 39 | { |
| 40 | /** |
| 41 | * A possible entry point to tao |
| 42 | */ |
| 43 | public function index() |
| 44 | { |
| 45 | $this->setView('TaoEventLog/log.tpl'); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Load json data with results |
| 50 | * dates for GUI should be in user time zone |
| 51 | */ |
| 52 | public function search() |
| 53 | { |
| 54 | $this->returnJson(new EventLogDatatable()); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Export log entries from database to csv file |
| 59 | * dates should be in UTC |
| 60 | * |
| 61 | * @throws \Exception |
| 62 | */ |
| 63 | public function export() |
| 64 | { |
| 65 | $delimiter = $this->getParameter('field_delimiter', ','); |
| 66 | $enclosure = $this->getParameter('field_encloser', '"'); |
| 67 | $sortBy = $this->getParameter('sortby', ''); |
| 68 | $sortOrder = $this->getParameter('sortorder', ''); |
| 69 | |
| 70 | $exportParameters = []; |
| 71 | |
| 72 | if ($this->hasRequestParameter('filtercolumns')) { |
| 73 | $parameters = $this->getRequestParameter('filtercolumns'); |
| 74 | |
| 75 | if (is_array($parameters)) { |
| 76 | $exportParameters = $parameters; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | $csvExporter = new LogEntryCsvStdOutExporter( |
| 81 | new LogEntryRepository($exportParameters, $sortBy, $sortOrder), |
| 82 | $delimiter, |
| 83 | $enclosure |
| 84 | ); |
| 85 | |
| 86 | setcookie('fileDownload', 'true', 0, '/'); |
| 87 | $csvExporter->export(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @param string $name |
| 92 | * @param mixed $defaultValue |
| 93 | * |
| 94 | * @return string |
| 95 | */ |
| 96 | protected function getParameter($name, $defaultValue) |
| 97 | { |
| 98 | return $this->hasRequestParameter($name) |
| 99 | ? html_entity_decode($this->getRequestParameter($name)) |
| 100 | : $defaultValue; |
| 101 | } |
| 102 | } |