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

namespace Kufer\KuferTools\Teilnehmer\BayerischerApothekertagStudenten\SaveAnmeldeFormular;

class SaveAnmeldeFormularUseCase extends \Kufer\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($origPerson, $this->request->columnValues);
    $wrongFields = $this->request->wssHandler->checkColumnValues($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\KuferTools\Basis\UseCase\ToolResponse
{
  public $statusCode;
  public $wrongFields = array();
}