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

namespace Kufer\Web\KuferTools\Basis\Kursdetails\Detailsreiter\Teilnehmer\SammelEinzelBearbeitung;

use Kufer\Web\KuferTools\Utils\WssHandler;

abstract class HandleSammelEinzelBearbeitungController extends \Kufer\Web\KuferTools\Basis\Controller\Controller
{
  protected function getNewRequestObj(): HandleSammelEinzelBearbeitungRequest
  {
    return new HandleSammelEinzelBearbeitungRequest();
  }

  protected function getRequestObj()
  {
    $result = $this->getNewRequestObj();
    $result->knr = \GetOperations::getVarValue('knr');
    $result->belids = \PostOperations::getVarValue('belids', array());

    $wssHandler = new WssHandler($this->getToolId(), $this->getFormToolSectionId(), HandleSammelEinzelBearbeitungUseCase::getUser());
    $result->columnValuesMap = array();
    foreach ($result->belids as $belid) {
      $result->columnValuesMap[$belid] = $wssHandler->getColumnValuesFromPost('form' . $belid);
    }
    $result->wssHandler = $wssHandler;
    $action = $this->getActionVal();

    return $this->handleXsrf($result, $action, $result->knr);
  }

  abstract protected function getToolId(): int;

  abstract protected function getFormToolSectionId();

  protected function getPresenter($pUseCaseResponse)
  {
    return new SammelEinzelBearbeitungFormularPresenter($pUseCaseResponse, false);
  }
}