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


class FeedBackCode extends Datamodul
{
  
  public $code = '';
  
  public $bogenid = 0;
  
  public $knr = '';
  
  public $tnr = -1;
  
  public $belegid = 0;
  
  public $gueltigbis = '';
  
  public $eingeloestam = '';
  
  public $erfasstam = '';
  
  public $erfasstvon = '';
  
  public $dnr = -1;
  
  public $dozkursid = 0;
  
  public $is_kurscode = false;
  
  public $fuer_dozent = -1;

  
  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'id':
      case 'bogenid':
      case 'tnr':
      case 'belegid':
      case 'dnr':
      case 'dozkursid':
      case 'fuer_dozent':
        return \DatamodulVarType::TYPE_INT;
      case 'gueltigbis':
      case 'eingeloestam':
        return \DatamodulVarType::TYPE_DATE;
      case 'erfasstam':
        return \DatamodulVarType::TYPE_DATETIME;
      case 'is_kurscode':
        return DatamodulVarType::TYPE_BOOL_WF;
    }
  }

  
  public function isCodeRedeemed(): bool
  {
    return !DateTimeOperations::isDateTimeEmptyOrDefault($this->eingeloestam);
  }

  
  public function isCodeExpired(): bool
  {
    $dateToday = DateTimeOperations::getDateNow();
    if (DateTimeOperations::getAnzTage($dateToday, $this->gueltigbis) <= 0) {
      return true;
    }

    return false;
  }

  public function getDmzVarnameMappingForReceivingData(): array
  {
    return array_merge(parent::getDmzVarnameMappingForReceivingData(), array(
      'IsKurscode' => 'is_kurscode',
      'FuerDozent' => 'fuer_dozent'
    ));
  }
}