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




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

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




abstract class NewDozentUseCase extends \Kufer\Web\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()
  {
    
    

    
    $dozInsertHandler = new DozentInserter($this->toolSettings, $this->request);
    $statusMessageContainer = null;

    
    
    
    if (!$this->request->isRefresh) {
      
      $dozInfo = $dozInsertHandler->doInsert();
      
      $statusMessageContainer = $dozInsertHandler->getStatusMessageContainer();

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

        
        
        $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\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $knr;
  public $statusMessageContainer;
}