HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/ZelfVerkopen/zelfverkopen.nl/app/KommaApp/Asperion/ExportController.php
<?php

namespace App\KommaApp\Asperion;

/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

use App\KommaApp\Kms\Core\SectionController;
use App\KommaApp\Pages\Models\Page;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\MessageBag;

class ExportController extends SectionController
{
    protected $slug = "asperion";
    protected $forModelName = Page::class; //We need to set a model altough we don't even use it. This is because of the core of the KMS demands it

    /** @var ExportService $ExportService */
    protected $ExportService;

    public function __construct(ExportSection $section)
    {
        parent::__construct($section);

        $this->ExportService = $service = $this->section->getSectionService();
        if(!is_a($service, ExportService::class)) throw new \RuntimeException('The section service must be "'.ExportService::class.'". Got "'.get_class($service).'"');
    }

    public function index() {
        // Build section tabs
        $this->section->getSectionTabDirector()->buildTabs();

        return $this->section->render();
    }

    public function export(Request $request)
    {
        $from = null;
        if($request->has('DatePicker-from')) {
            $dateArray = json_decode($request->get('DatePicker-from'), true);
            $from = (new Carbon())->setDateTime($dateArray['year'], $dateArray['month'], $dateArray['day'], 0, 0, 0);
        }

        $trough = null;
        if($request->has('DatePicker-from')) {
            $dateArray = json_decode($request->get('DatePicker-trough'), true);
            $trough = (new Carbon())->setDateTime($dateArray['year'], $dateArray['month'], $dateArray['day'], 23, 59, 59);
        }
        return $this->ExportService->export($from, $trough);
    }
}