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


class ExportTeilnehmer extends ExportMitPflichtUndValidierungsFehler
{
  
  public function initiate()
  {
    ExportBasis::initiate();
    $this->dboperations = new DBWorkTeilnehmer();
  }

  
  
  public function export()
  {
    $this->clearResult();
    for ($i = 0; $i < count($this->exportsets); $i++) {
      $tmp = $this->dboperations->getTeilnehm($this->exportsets[$i]->id);
      if (isset($tmp->id)) {
        array_push($this->exportresults, $tmp);
      }
    }
  }

  
  public function getVarValue($varname)
  {
    
    if ($this->getVarName($varname) === 'belegungsdaten') {
      switch ($this->getVarCategory($varname)) {
        case 'bedit_': $sightId = 426; break;
        case 'beditma_': $sightId = 428; break;
        case 'beditmehr_': $sightId = 427; break;
        case 'beditpa_': $sightId = 429; break;
        default: $sightId = null; break;
      }
      if (isset($sightId)) {
        $expFreifelder = new ExpFreifelder();
        $expFreifelder->setFehler($this->pflichtfeldFehler);

        return $this->expCalculation->createListe4Belegungsdaten($this->exportresults[$this->actualset], $sightId, $expFreifelder);
      }
    }

    switch ($this->getVarCategory($varname)) {
      default: return parent::getVarValue($varname);
      case 't_': return $this->expCalculation->getVarValue4Teilnehmer($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'tma_':
        $tnary = SessionOperations::getTeilnehmerFromSession('ma');

        return $this->expCalculation->getVarValue4Teilnehmer($this->getVarName($varname), $tnary[0]);
      case 'tmehr_':
        $tnary = SessionOperations::getTeilnehmerFromSession('mehr');

        return $this->expCalculation->getVarValue4Teilnehmer($this->getVarName($varname), $tnary[0]);
      case 'tpa_':
        $tnary = SessionOperations::getTeilnehmerFromSession('pa');

        return $this->expCalculation->getVarValue4Teilnehmer($this->getVarName($varname), $tnary[0]);
      case 'tbest_': return $this->expCalculation->getVarValue4TeilnehmerBest($this->getVarName($varname), $this->exportresults[$this->actualset], $this->actualset);
      case 'tedit_': return $this->expCalculation->getVarValue4TeilnehmerEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'teditma_': return $this->expCalculation->getVarValue4MitarbeiterEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'teditmehr_': return $this->expCalculation->getVarValue4MehrfachEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'teditpa_': return $this->expCalculation->getVarValue4PartnerEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'bedit_': return $this->expCalculation->getVarValue4BelegungEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'beditma_': return $this->expCalculation->getVarValue4BelegungMitarbeiterEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'beditmehr_': return $this->expCalculation->getVarValue4BelegungMehrfachEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'beditpa_': return $this->expCalculation->getVarValue4BelegungPartnerEdit($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'bbest_': return $this->expCalculation->getVarValue4BelegungBest($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'wk_': return (new \Kufer\Web\Classes\Export\ExportCalculation\ExportCalcWarenkorb())->resolveVar($this->getVarName($varname), $this->exportresults[$this->actualset]);
    }
  }
}