Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LogEntryCsvExporter | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| export | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| prepareFilters | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
| 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 | * @author Ivan klimchuk <klimchuk@1pt.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoEventLog\model\export\implementation; |
| 24 | |
| 25 | use common_session_SessionManager; |
| 26 | use DateTime; |
| 27 | use DateTimeImmutable; |
| 28 | use DateTimeZone; |
| 29 | use oat\oatbox\service\ServiceManager; |
| 30 | use oat\taoEventLog\model\eventLog\LoggerService; |
| 31 | use oat\taoEventLog\model\export\Exporter; |
| 32 | |
| 33 | /** |
| 34 | * @deprecated |
| 35 | * |
| 36 | * @package oat\taoEventLog\model\export\implementation |
| 37 | */ |
| 38 | class LogEntryCsvExporter implements Exporter |
| 39 | { |
| 40 | /** @var LoggerService $loggerService */ |
| 41 | private $loggerService; |
| 42 | |
| 43 | /** |
| 44 | * LogEntryCsvExporter constructor. |
| 45 | */ |
| 46 | public function __construct() |
| 47 | { |
| 48 | $this->loggerService = ServiceManager::getServiceManager()->get(LoggerService::SERVICE_ID); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param array $filters |
| 53 | * |
| 54 | * @param string $sortColumn |
| 55 | * @param string $sortOrder |
| 56 | * |
| 57 | * @return mixed |
| 58 | * @throws \common_exception_Error |
| 59 | */ |
| 60 | public function export(array $filters = [], $sortColumn = '', $sortOrder = 'asc') |
| 61 | { |
| 62 | $options = [ |
| 63 | 'limit' => $this->loggerService->getOption(LoggerService::OPTION_EXPORTABLE_QUANTITY), |
| 64 | 'sort' => $sortColumn, |
| 65 | 'order' => $sortOrder, |
| 66 | ]; |
| 67 | |
| 68 | return $this->loggerService->search($this->prepareFilters($filters), $options); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @param array $filters |
| 73 | * |
| 74 | * @return array |
| 75 | * |
| 76 | * @throws \common_exception_Error |
| 77 | * @throws \Exception |
| 78 | */ |
| 79 | private function prepareFilters(array $filters = []) |
| 80 | { |
| 81 | /** @var \common_session_Session $session */ |
| 82 | $session = common_session_SessionManager::getSession(); |
| 83 | $timeZone = new DateTimeZone($session->getTimeZone()); |
| 84 | $utc = new DateTimeZone('UTC'); |
| 85 | |
| 86 | $result = []; |
| 87 | |
| 88 | foreach ($filters as $name => $value) { |
| 89 | if (!empty($value)) { |
| 90 | switch ($name) { |
| 91 | case 'from': |
| 92 | $from = new DateTimeImmutable($filters['from'], $timeZone); |
| 93 | $result[] = ['occurred', '>', $from->setTimezone($utc)->format(DateTime::ISO8601)]; |
| 94 | break; |
| 95 | case 'to': |
| 96 | $to = new DateTimeImmutable($filters['to'], $timeZone); |
| 97 | $result[] = ['occurred', '<=', $to->setTimezone($utc)->format(DateTime::ISO8601)]; |
| 98 | break; |
| 99 | default: |
| 100 | $result[] = [$name, 'LIKE', "%$value%"]; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return $result; |
| 106 | } |
| 107 | } |