File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/Kms/ActionLog/ActionLogSection.php
<?php
namespace App\KommaApp\Kms\ActionLog;
//The new object oriented attributes
use App\Helpers\KommaHelpers;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\DatePicker;
use App\KommaApp\Kms\Core\Attributes\File;
use App\KommaApp\Kms\Core\Sections\NoLanguageTabsDirector;
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Kms\Core\Sections\SectionServiceInterface;
use App\KommaApp\Kms\Core\Sections\SectionTab;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use App\KommaApp\Kms\Core\ValidationSet;
use App\KommaApp\Sites\SiteServiceInterface;
use App\KommaApp\Users\Models\Role;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\MessageBag;
class ActionLogSection extends Section
{
protected $title = "Action log";
protected $subTitle = "Who did what";
protected $slug = "actionlog";
protected $hasRoutes = false;
public $showSave = [];
public $showDelete = [];
public $showCreate = [];
/**
* @var ActionLogService $sectionService
*/
protected $sectionService;
/**
* PageSection constructor.
* @param ActionLogService $actionLogService
* @param RouteService $routeService
* @param SectionServiceInterface $siteService
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct(ActionLogService $actionLogService, RouteService $routeService, SiteServiceInterface $siteService)
{
$this->title = ucfirst(__('kms/actionlog.title'));
$this->subTitle = __('kms/actionlog.subtitle');
$this->submitButtonLabel = __('kms/actionlog.retrieve');
$sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder());
parent::__construct($actionLogService, $routeService, $siteService, $sectionTabDirector);
}
/**
* Generates the attributes for this section. They all must extend the App\KommaApp\Kms\Core\Attributes\Attribute class
* This is the place where you need to setup your sections appearance. Just make sure you build an array of attributes
* and put each attribute in a AbstractSectionTabItem with a SectionTabGroups constant to link them to a tab.
*
* @see PageRepository::saveModel()
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(): Collection
{
// \Log::info("PageSection::Generating attributes");
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('kms/actionlog.title')))
->setMinimumUserRole(Role::Admin);
$attributes[] = (new DatePicker(__('kms/actionlog.from')))
->setMinimumUserRole(Role::Admin)
->mapValueFrom(Attribute::ValueFromItself, 'from');
$attributes[] = (new DatePicker(__('kms/actionlog.trough')))
->setMinimumUserRole(Role::Admin)
->mapValueFrom(Attribute::ValueFromItself, 'trough');
//****************************************************************************************************************************************\\
//*** Put the all attributes in a SectionTabItem so we can track for which tab they are. And then put SectionTabItems in a Collection ***\\
//****************************************************************************************************************************************\\
$tabItems = new Collection();
foreach($attributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
return $tabItems;
}
/**
* Returns a rendered view
*
* @return \Illuminate\Contracts\View\View
*/
public function render()
{
return parent::render();
}
/**
* Gets the action logs between two dates
*/
public function getActionLogs()
{
$fromDate = null;
$troughDate = null;
collect($this->sectionTabItems)->each(function(SectionTabItem $sectionTabItem) use(&$fromDate, &$troughDate) {
$attribute = $sectionTabItem->getAttribute();
$value = $attribute->getValue();
switch ($attribute->getsValueFrom()) {
case Attribute::ValueFromItself:
switch ($attribute->getsValueFromReference()) {
case 'from':
$fromDate = $value;
break;
case 'trough':
$troughDate = $value;
break;
}
break;
}
});
return $this->sectionService->getLogs($fromDate, $troughDate)->get();
}
/**
* Makes the view and returns it
*
* @return View
*/
protected function makeView(): View
{
$successes = (\Session::has('successes')) ? \Session::get('successes') : new MessageBag();
return \View::make('kms/section.actionlog', [
'kms' => $this->siteService,
'section' => $this,
'retrieveRoute' => [
'route' => route('actionlog.retrieve'),
'method' => 'POST'
],
'successes' => $successes,
'maxUploadSize' => KommaHelpers::fileUploadMaxSize()
]);
}
}