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




namespace Kufer\Web\KuferTools\Basis\KursUebersicht\Detailsreiter\Honorar\AddDozent;


use Kufer\KuferTools\Utils\DozKursHandler\DozKursInserter as DozKursInserter;
use Kufer\KuferTools\Utils\DozentenHandler\DozentInserter as DozentInserter;




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

  public function hasAccess($pToolSectionId = null)
  {
    if (!parent::hasAccess()) {
      return false;
    }
    
    elseif (!$this->request->isXsrfOk && !$this->request->isRefresh) {
      return false;
    }
    
    return true;
  }

  public function action()
  {
    $allgSettings = \AllgSettingsAPI::getAllgSettings();
    $dmzBetrieb = $this->session->isReplikat() && $allgSettings->dmzEnabled;
    
    

    
    $dozInsertHandler = new DozentInserter($this->request);
    $dozInsertHandler->setDmzBetrieb($dmzBetrieb);
    $statusMessageContainer = null;

    
    
    
    if (!$this->request->isRefresh) {

      
      $dozInfo = $dozInsertHandler->doInsert();
      
      $statusMessageContainer = $dozInsertHandler->getStatusMessageContainer();

      
      if ($dozInfo['dozId'] != -1) {
        $dozKursInsertHandler = new DozKursInserter($this->request, true);
        $dozKursInsertHandler->setDmzBetrieb($dmzBetrieb);
        

        
        
        $dozKursInsertHandler->doInsert($dozInfo['dozId']);
        $statusMessageContainer = $dozKursInsertHandler->getStatusMessageContainer();
      }
    }

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

  protected function getResponse($pStatusMessageContainer)
  {
    $this->handleResponseStrategies();
    $this->response->knr = $this->request->knr;
    
    
    $this->response->statusMessageContainer = $pStatusMessageContainer;

    return $this->response;
  }

  protected function getResponseStrategies()
  {
    return array();
  }
} 

class NewDozentRequest
{
  
  public $isRefresh;
  public $isXsrfOk;
  
  public $knr;
  
  public $wssHandler;
  public $columnValues;
}

class NewDozentResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $knr;
  public $statusMessageContainer;
}