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

namespace Kufer\Web\KuferTools\Teilnehmer\BayerischerApothekertagStudenten\SaveAnmeldeFormular;

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

  public static function getToolId()
  {
    return 48;
  }

  public static function getToolSectionId()
  {
    return 565;
  }

  public function action()
  {
    $origPerson = \SessionOperations::getVarValueWTIntern('bat_ehrengast', new \Teilnehmer());
    $person = $this->request->wssHandler->getChangedDm(
      $this->toolSettings,
      $origPerson,
      $this->request->columnValues
    );
    $wrongFields = $this->request->wssHandler->checkColumnValues($this->toolSettings, $this->request->columnValues);
    $success = true;
    if (count($wrongFields) > 0) {
      $success = false;
      $this->response->wrongFields = $wrongFields;
    } else {
      \SessionOperations::setVarValueWTIntern('bat_ehrengast', $person);
    }

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

  protected function getResponse($success)
  {
    $this->response->statusCode = $success;

    return $this->response;
  }
}

class SaveAnmeldeFormularRequest
{
  public $changedPerson;
  public $wrongFields;

  public $columnValues;
  public $wssHandler;
}

class SaveAnmeldeFormularResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $statusCode;
  public $wrongFields = array();
}