<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


namespace Kufer\KuferTools\Veranstalter\KursUebersicht\KursDetails\KursBearbeiten;


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

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_KURSUEBERSICHT_VA;
  }

  protected function getKursHelper()
  {
    return \Kufer\KuferTools\Utils\DatamodulHelper\KursHelper\KursHelperFactory::getKursHelperByToolID($this->getToolId(), $this->toolSettings);
  }

  public function getAllKursnrOhneFilter()
  {
    $kurshelper = $this->getKursHelper();

    return $kurshelper->getIdsOhneFilter();
  }

  public function getKurs($knr)
  {
    $dbwKurse = new \DBWorkKurseWT(1, true);

    return $dbwKurse->getKurs($knr);
  }

  
  public static function getToolSectionId()
  {
    return 621;
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!parent::hasAccess()) {
      return false;
    }

    if (!$this->isRechtAllowed('632.0.4')) {
      return false;
    }

    $alleKursnummern = $this->getAllKursnrOhneFilter();

    return in_array($this->request->knr, $alleKursnummern);
  }

  public function action()
  {
    $kurs = $this->getKurs($this->request->knr);

    return $this->getResponse($kurs);
  }

  protected function getResponse($pKurs)
  {
    
    $this->handleResponseStrategies();
    $this->response->kurs = $pKurs;
    
    
    $this->response->kurs->showRaumHinterlegungsButton = $this->toolSettings->kurse_hl_raum;
    $this->response->kurs->showBeginnHinterlegungsButton = $this->toolSettings->kurse_hl_beginn;
    $this->response->kurs->showEndeHinterlegungsButton = $this->toolSettings->kurse_hl_ende;
    $this->response->kurs->kursortFeldReadonly = $this->toolSettings->kurse_kursort_feld_readonly;
    $this->response->kurs->showAussenstellenHintelegungButton = $this->toolSettings->kurse_hl_aussenstelle;
    $this->response->kursortEinschraenkungAussenstelle = $this->toolSettings->kurse_kursort_einschraenkung_aussenstelle;

    return $this->response;
  }

  protected function getResponseStrategies()
  { 
    
    return array(new \Kufer\KuferTools\Utils\ResponseStrategies\ResponseWss($this));
  }
}

class KursBearbeitenRequest
{
  public $knr;
}

class KursBearbeitenResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $kurs;
  public $columns;
}