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

namespace Kufer\Web\KuferTools\Utils\WssField\KursPlanung;


class WssFieldKnr extends \Kufer\Web\KuferTools\Utils\WssField\WssField
{
  protected function getFieldNichtBearbeitbar($datamodulWert, $isFormular, string $requestPrefix = '')
  {
    $result = parent::getFieldNichtBearbeitbar($datamodulWert, $isFormular);
    $result .= $this->getHiddenInput($datamodulWert);

    return $result;
  }

  
  private function getHiddenInput($datamodulWert)
  {
    $name = $this->getDatamodulAndFieldName();
    $value = $datamodulWert->knr;

    return '<input type="hidden" name="' . $name . '" value="' . $value . '">';
  }

  public function getDefaultMaxLength(): ?int
  {
    return 10;
  }

  public function getValueFromPost(string $requestPrefix = '')
  {
    $value = parent::getValueFromPost($requestPrefix);

    return \StringOperations::substr($value, 0, 10);
  }
}