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

class ComboboxErmaessigung extends \Combobox
{
  
  public function getOptionen(): array
  {
    $optionen = array();
    foreach ($this->dataModulAry as $datamodul) {
      $option = new \ComboboxOption();
      $option->value = $datamodul->getVarValue($this->getValueFieldName());
      $option->text = $this->getText($datamodul);
      $option->isSelected = ($datamodul->getVarValue('text') . ' (' . $datamodul->getVarValue('prozente') . '%)' == $this->selectedValue);
      $optionen[] = $option;
    }

    return $optionen;
  }

  protected function getDatamodulAry(): array
  {
    $dbwErmaess = new DBWorkErmaessigung(1, true);

    return $dbwErmaess->getErmaessigungen(true);
  }

  protected function getValueFieldName(): string
  {
    return 'nr';
  }

  protected function getTextFieldName(): string
  {
    return '';
  }

  protected function getText($datamodul): string
  {
    return $datamodul->getVarValue('nr') . ' - ' . $datamodul->getVarValue('text') . ' (' . $datamodul->getVarValue('prozente') . '%)';
  }

  protected function getDefaultOption(): ?\ComboboxOption
  {
    return null;
  }
}