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

class AnwesenheitExtra extends Datamodul
{
  public $eanwid;
  public $estatus;
  public $ebemerkung;
  public $evon;
  public $ebis;
  public $eamscode;

  
  private $anw;

  private $estatus_lang;

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'evon':
      case 'ebis':
        return \DatamodulVarType::TYPE_TIME;
      case 'eanwid':
        return \DatamodulVarType::TYPE_INT;
    }
  }

  public function getVarValue($name)
  {
    switch ($name) {
      case 'estatus_lang':
        if (is_null($this->estatus_lang)) {
          $dbwAnwesenheitenGruendeHL = new \DBWorkHLAnwesenheitGruende();
          $grund = $dbwAnwesenheitenGruendeHL->getGrundByStatus($this->estatus);
          $this->estatus_lang = is_null($grund->schluessel) ? $this->estatus : $grund->schluessel;
        }

        return $this->estatus_lang;
      case 'isextra':
        return true;
    }

    return parent::getVarValue($name);
  }

  public function getVarValueEx($name, $datamodulname)
  {
    $datamodulnamelc = \StringOperations::strtolower($datamodulname);
    switch ($datamodulnamelc) {
      case 'dozent':
      case 'kurstag':
      case 'kurs':
        if (!is_null($this->getAnwesenheit())) {
          return $this->getAnwesenheit()->getKurstag()->getVarValueEx($name, $datamodulname);
        } else {
          break;
        }
    }

    return parent::getVarValueEx($name, $datamodulname);
  }

  public function getAnwesenheit()
  {
    if (is_null($this->anw)) {
      $dbwAnwesenheit = new \DBWorkAnwesenheit();
      $this->anw = $dbwAnwesenheit->getAnwesenheit($this->eanwid);
    }

    return $this->anw;
  }
}