<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Allgemein\Raumanzeige\FilterTerminUebersicht;

class FilterTerminUebersichtUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new FilterTerminUebersichtResponse());
  }

  public static function getToolId()
  {
    return 19;
  }

  public static function getToolSectionId()
  {
    return 292;
  }

  public function action()
  {
    return $this->getResponse();
  }

  protected function getResponse()
  {
    $this->response->aussenstellen = $this->getAussenstellen();
    $this->response->gebaeude = $this->getGebaeude();
    $this->response->kursOrte = $this->getKursOrte();

    $searchApi = new \KurstagSucheAPI();
    $dbwKurstage = new \DBWorkKurseTageMin();
    $this->response->kurstagFilterVon = $searchApi->getFromObjectBySession($dbwKurstage->getNewObject(), 'tool' . $this->getToolId(), false);
    $this->response->kurstagFilterBis = $searchApi->getToObjectBySession($dbwKurstage->getNewObject(), 'tool' . $this->getToolId(), false);

    if (!\DateTimeOperations::isValidDate($this->response->kurstagFilterVon->datum)) {
      $this->response->kurstagFilterVon->datum = \DateTimeOperations::getDateNow();
    }

    if ($this->response->kurstagFilterVon->dnr !== '' && $this->response->kurstagFilterVon->dnr >= 0) {
      $this->response->nurEigene = true;
    }
    $this->response->showNurEigene = $this->showNurEigeneFilter();

    return $this->response;
  }

  
  private function showNurEigeneFilter()
  {
    $user = $this->getUser();

    return $user->dnr >= 0;
  }

  private function getAussenstellen()
  {
    $dbwAussenstellen = new \DBWorkHLAussenstellen(1, true);

    return $dbwAussenstellen->getAussenstellen();
  }

  private function getKursOrte()
  {
    $dbwKursorte = new \DBWorkKursorte(1, true);

    return $dbwKursorte->getKursorte();
  }

  private function getGebaeude()
  {
    $dbwGebaeude = new \DBWorkGebaeude(1, true);

    return $dbwGebaeude->getGebaeude();
  }
}

class FilterTerminUebersichtRequest
{
}

class FilterTerminUebersichtResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $aussenstellen;
  public $gebaeude;
  public $kursOrte;

  public $kurstagFilterVon;
  public $kurstagFilterBis;
  public $nurEigene = false;
  public $showNurEigene = false;
}