*/ namespace oat\taoEventLog\model\export\implementation; use common_session_SessionManager; use DateTime; use DateTimeImmutable; use DateTimeZone; use oat\oatbox\service\ServiceManager; use oat\taoEventLog\model\eventLog\LoggerService; use oat\taoEventLog\model\export\Exporter; /** * @deprecated * * @package oat\taoEventLog\model\export\implementation */ class LogEntryCsvExporter implements Exporter { /** @var LoggerService $loggerService */ private $loggerService; /** * LogEntryCsvExporter constructor. */ public function __construct() { $this->loggerService = ServiceManager::getServiceManager()->get(LoggerService::SERVICE_ID); } /** * @param array $filters * * @param string $sortColumn * @param string $sortOrder * * @return mixed * @throws \common_exception_Error */ public function export(array $filters = [], $sortColumn = '', $sortOrder = 'asc') { $options = [ 'limit' => $this->loggerService->getOption(LoggerService::OPTION_EXPORTABLE_QUANTITY), 'sort' => $sortColumn, 'order' => $sortOrder, ]; return $this->loggerService->search($this->prepareFilters($filters), $options); } /** * @param array $filters * * @return array * * @throws \common_exception_Error * @throws \Exception */ private function prepareFilters(array $filters = []) { /** @var \common_session_Session $session */ $session = common_session_SessionManager::getSession(); $timeZone = new DateTimeZone($session->getTimeZone()); $utc = new DateTimeZone('UTC'); $result = []; foreach ($filters as $name => $value) { if (!empty($value)) { switch ($name) { case 'from': $from = new DateTimeImmutable($filters['from'], $timeZone); $result[] = ['occurred', '>', $from->setTimezone($utc)->format(DateTime::ISO8601)]; break; case 'to': $to = new DateTimeImmutable($filters['to'], $timeZone); $result[] = ['occurred', '<=', $to->setTimezone($utc)->format(DateTime::ISO8601)]; break; default: $result[] = [$name, 'LIKE', "%$value%"]; } } } return $result; } }