tao-test/app/taoEventLog/controller/TaoEventLog.php

101 lines
2.8 KiB
PHP
Raw Normal View History

2022-08-29 20:14:13 +02:00
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016 (original work) Open Assessment Technologies SA;
*
*
*/
namespace oat\taoEventLog\controller;
use oat\taoEventLog\model\datatable\EventLogDatatable;
use oat\taoEventLog\model\export\implementation\LogEntryCsvStdOutExporter;
use oat\taoEventLog\model\export\implementation\LogEntryRepository;
use tao_actions_CommonModule;
/**
* Sample controller
*
* @author Open Assessment Technologies SA
* @package taoEventLog
* @license GPL-2.0
*
*/
class TaoEventLog extends tao_actions_CommonModule
{
/**
* A possible entry point to tao
*/
public function index() {
$this->setView('TaoEventLog/log.tpl');
}
/**
* Load json data with results
* dates for GUI should be in user time zone
*/
public function search()
{
$this->returnJson(new EventLogDatatable());
}
/**
* Export log entries from database to csv file
* dates should be in UTC
*
* @throws \Exception
*/
public function export()
{
$delimiter = $this->getParameter('field_delimiter', ',');
$enclosure = $this->getParameter('field_encloser', '"');
$sortBy = $this->getParameter('sortby', '');
$sortOrder = $this->getParameter('sortorder', '');
$exportParameters = [];
if ($this->hasRequestParameter('filtercolumns')) {
$parameters = $this->getRequestParameter('filtercolumns');
if (is_array($parameters)) {
$exportParameters = $parameters;
}
}
$csvExporter = new LogEntryCsvStdOutExporter(
new LogEntryRepository($exportParameters, $sortBy, $sortOrder),
$delimiter,
$enclosure
);
setcookie('fileDownload', 'true', 0, '/');
$csvExporter->export();
}
/**
* @param string $name
* @param mixed $defaultValue
*
* @return string
*/
protected function getParameter($name, $defaultValue)
{
return $this->hasRequestParameter($name)
? html_entity_decode($this->getRequestParameter($name))
: $defaultValue;
}
}