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

class ComboboxStatus extends Combobox
{
  protected function getDatamodulAry()
  {
    $tmpary = array();
    $statusAry = array('A', 'P', 'W', 'S', 'I', 'U'); 
    foreach ($statusAry as $status) {
      $tmpary[] = $this->getDatamodul($status, ConstantOperations::getBelegungStatus($status));
    }

    return $tmpary;
  }

  protected function getValueFieldName()
  {
    return 'status';
  }

  protected function getTextFieldName()
  {
    return 'text';
  }

  public function getSelectedText()
  {
    $result = parent::getSelectedText();
    if ($result === '') {
      $result = $this->getNichtBearbeitbareStatusText();
    }

    return $result;
  }

  protected function getText($datamodul)
  {
    return $datamodul->getVarValue('status') . ' - ' . $datamodul->getVarValue('text');
  }

  protected function getDefaultOption()
  {
    return null;
  }

  private function getDatamodul($status, $text)
  {
    $datamodul = new class() extends \Datamodul {
      public $status;
      public $text;
    };
    $datamodul->status = $status;
    $datamodul->text = $text;

    return $datamodul;
  }

  private function getNichtBearbeitbareStatusText()
  {
    $result = $this->selectedValue;
    $text = ConstantOperations::getBelegungStatus($this->selectedValue);
    if ($text !== '') {
      $result .= ' - ' . $text;
    }

    return $result;
  }
}