芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/sommatv/lib/Controller/AuditLog.php
. */ namespace Xibo\Controller; use Xibo\Factory\AuditLogFactory; use Xibo\Service\ConfigServiceInterface; use Xibo\Service\DateServiceInterface; use Xibo\Service\LogServiceInterface; use Xibo\Service\SanitizerServiceInterface; /** * Class AuditLog * @package Xibo\Controller */ class AuditLog extends Base { /** * @var AuditLogFactory */ private $auditLogFactory; /** * Set common dependencies. * @param LogServiceInterface $log * @param SanitizerServiceInterface $sanitizerService * @param \Xibo\Helper\ApplicationState $state * @param \Xibo\Entity\User $user * @param \Xibo\Service\HelpServiceInterface $help * @param DateServiceInterface $date * @param ConfigServiceInterface $config * @param AuditLogFactory $auditLogFactory */ public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $auditLogFactory) { $this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config); $this->auditLogFactory = $auditLogFactory; } public function displayPage() { $this->getState()->template = 'auditlog-page'; } function grid() { $filterFromDt = $this->getSanitizer()->getDate('fromDt'); $filterToDt = $this->getSanitizer()->getDate('toDt'); $filterUser = $this->getSanitizer()->getString('user'); $filterEntity = $this->getSanitizer()->getString('entity'); $search = []; // Get the dates and times if ($filterFromDt == null) $filterFromDt = $this->getDate()->parse()->sub('1 day'); if ($filterToDt == null) $filterToDt = $this->getDate()->parse(); $search['fromTimeStamp'] = $filterFromDt->format('U'); $search['toTimeStamp'] = $filterToDt->format('U'); if ($filterUser != '') $search['userName'] = $filterUser; if ($filterEntity != '') $search['entity'] = $filterEntity; $rows = $this->auditLogFactory->query($this->gridRenderSort(), $this->gridRenderFilter($search)); // Do some post processing foreach ($rows as $row) { /* @var \Xibo\Entity\AuditLog $row */ $row->objectAfter = json_decode($row->objectAfter); } $this->getState()->template = 'grid'; $this->getState()->recordsTotal = $this->auditLogFactory->countLast(); $this->getState()->setData($rows); } /** * Output CSV Form */ public function exportForm() { $this->getState()->template = 'auditlog-form-export'; $this->getState()->setData([ 'help' => $this->getHelp()->link('AuditLog', 'Export') ]); } /** * Outputs a CSV of audit trail messages */ public function export() { // We are expecting some parameters $filterFromDt = $this->getSanitizer()->getDate('filterFromDt'); $filterToDt = $this->getSanitizer()->getDate('filterToDt'); if ($filterFromDt == null || $filterToDt == null) throw new \InvalidArgumentException(__('Please provide a from/to date.')); $search = [ ['fromTimeStamp', $filterFromDt->setTime(0, 0, 0)->format('U')], ['toTimeStamp', $filterToDt->setTime(0, 0, 0)->format('U')] ]; // Build the search string $search = implode(' ', array_map(function ($element) { return implode('|', $element); }, $search)); $rows = $this->auditLogFactory->query('logId', ['search' => $search]); $out = fopen('php://output', 'w'); fputcsv($out, ['ID', 'Date', 'User', 'Entity', 'Message', 'Object']); // Do some post processing foreach ($rows as $row) { /* @var \Xibo\Entity\AuditLog $row */ fputcsv($out, [$row->logId, $this->getDate()->getLocalDate($row->logDate), $row->userName, $row->entity, $row->message, $row->objectAfter]); } fclose($out); // We want to output a load of stuff to the browser as a text file. $app = $this->getApp(); $app->response()->header('Content-Type', 'text/csv'); $app->response()->header('Content-Disposition', 'attachment; filename="audittrail.csv"'); $app->response()->header('Content-Transfer-Encoding', 'binary"'); $app->response()->header('Accept-Ranges', 'bytes'); $this->setNoOutput(true); } }