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


class ExportDozenten extends ExportBasis
{
  private $_knr = '';

  public function setKnr($pKnr)
  {
    $this->_knr = $pKnr;
  }

  
  public function initiate()
  {
    ExportBasis::initiate();
  }

  
  public function export()
  {
    $this->clearResult();
    $this->exportresults = $this->exportsets;
  }

  public function add($pDoz)
  {
    array_push($this->exportsets, $pDoz);
  }

  
  public function getVarValue($varname)
  {
    switch ($this->getVarCategory($varname)) {
      default: return parent::getVarValue($varname);
      case 'doz_':
        $subvarname = $this->getVarName($varname);

        
        
        $vonDozKursBeeinflussteFelder = array('typ', 'typ_bez', 'titelweb', 'berufweb', 'qualifikationweb');

        if ($this->_knr != ''
            && $this->exportresults[$this->actualset]->id >= 0
            && in_array($subvarname, $vonDozKursBeeinflussteFelder)
           ) {
          $dbwdozhon = new DBWorkDozentenHonorar();
          $honorar = $dbwdozhon->getHonorarbyKNRDozentNR($this->_knr, ($this->exportresults[$this->actualset]->id));
          if ($subvarname == 'typ') {
            return CleanOperations::cleanStringForHtml($honorar->typ);
          } elseif ($subvarname == 'typ_bez') {
            $dbwhldoztyp = new DBWorkHLDozTyp();
            $hldoztyp = $dbwhldoztyp->getByTyp($honorar->typ);

            return CleanOperations::cleanStringForHtml($hldoztyp->text);
          } else {
            return $this->expCalculation->getVarValue4Honorar($subvarname, $honorar);
          }
        }
        
        
        return $this->expCalculation->getVarValue4Dozent($subvarname, $this->exportresults[$this->actualset]);
      case 'foto_':   
        $foto = \FotoAPI::getFotoByVarname($varname, 'D', $this->exportresults[$this->actualset]->id);
        if (!is_null($foto)) {
          return (new \Kufer\Web\Classes\Export\ExportCalculation\ExportCalcFotos())->resolveVar($foto['fotovarname'], $foto['foto'], $varname);
        } else {
          return '';
        }
        
      case 'portrait_':
        $subVarName = $this->getVarName($varname);

        $dbwPortrait = new DBWorkPortrait();
        $portrait = $dbwPortrait->getPortrait('D', $this->exportresults[$this->actualset]->id, true);

        if (isset($portrait->id)) {
          return $this->expCalculation->getVarValue4Portrait($subVarName, $portrait);
        } else {
          return '';
        }
    }
  }
}