File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Kms/ActionLog/ActionLogController.php
<?php
namespace App\Komma\Kms\ActionLog;
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
use App\Helpers\KommaHelpers;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\SectionController;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;
final class ActionLogController extends SectionController
{
protected $slug = "actionlog";
protected $classModelName = ActionLog::class; //We need to set a model although we don't even use it. This is because of the core of the KMS demands it
public function __construct()
{
$actionLogSection = new ActionLogSection($this->slug);
parent::__construct($actionLogSection);
$this->modelService = new ActionLogModelService();
}
public function index() {
$this->authorize('viewLogs', ActionLog::class);
// Build section tabs
$this->section->getTabs()->buildTabs();
return $this->render();
}
/**
* Triggered when the retrieve button is pressed
*
* @param Request $request
* @return \Illuminate\Contracts\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function retrieve(Request $request)
{
$this->authorize('viewLogs', ActionLog::class);
$renderedView = $this->index();
$attributes = $this->section->getAttributes();
$attributes = $this->dataService->fillAttributesFromInput($attributes);
$fromDate = null;
$troughDate = null;
$userFilter = null;
$attributes->each((function(Attribute $attribute) use(&$model, &$fromDate, &$troughDate, &$userFilter) {
$value = $attribute->getValue();
switch ($attribute->getsValueFrom()) {
case Attribute::ValueFromItself:
switch ($attribute->getsValueFromReference()) {
case 'from':
$fromDate = $value;
break;
case 'trough':
$troughDate = $value;
break;
case 'user_filter':
$userFilter = (int) $value;
}
break;
}
return $attribute;
})->bindTo($this));
$logs = $this->modelService->getLogs($fromDate, $troughDate, $userFilter)->get();
$renderedView->withLogs($logs);
return $renderedView;
}
/**
* Makes the view and returns it
*
* @return View
*/
protected function makeView(): View
{
$successes = (session()->has('successes')) ? session()->get('successes') : new MessageBag();
return view('kms/section.actionlog', [
'kms' => $this->siteService,
'sectionTabs' => $this->section->getTabs(),
'retrieveRoute' => [
'route' => route('actionlog.retrieve'),
'method' => 'POST'
],
'successes' => $successes,
'maxUploadSize' => KommaHelpers::fileUploadMaxSize()
]);
}
}