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


class ExportBelegung extends ExportBasis
{
  
  public function initiate()
  {
    ExportBasis::initiate();
    $this->dboperations = new DBWorkBelegung();
  }

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

  
  public function getVarValue($varname)
  {
    switch ($this->getVarCategory($varname)) {
      default: return parent::getVarValue($varname);
      case 'k_': return $this->expCalculation->getVarValue4Kurs($this->getVarName($varname), $this->exportresults[$this->actualset]->kurs);
      case 'kort_':
        $dbwkorte = DBWorkKursorte::getDefaultInstance();
        $ort = isset($this->exportresults[$this->actualset]->kurs) ? $this->exportresults[$this->actualset]->kurs->ort : '';
        $kursortObj = $dbwkorte->getKursortbymktext($ort); 

        return $this->expCalculation->getVarValue4Kursort($this->getVarName($varname), $kursortObj); 
      case 'b_': return $this->expCalculation->getVarValue4Belegung($this->getVarName($varname), $this->exportresults[$this->actualset]);
      case 'bbest_': return $this->expCalculation->getVarValue4BelegungBest($this->getVarName($varname), $this->exportresults[$this->actualset]->kurs);
      case 't_': return $this->expCalculation->getVarValue4Teilnehmer($this->getVarName($varname), $this->exportresults[$this->actualset]->teilnehmer);
      case 'tbest_': return $this->expCalculation->getVarValue4TeilnehmerBest($this->getVarName($varname), $this->exportresults[$this->actualset]->teilnehmer);
      case 'doz_': return $this->expCalculation->getVarValue4Dozent($this->getVarName($varname), $this->exportresults[$this->actualset]->kurs->getVarValue('hauptdozent'));
      case 'wk_': return (new \Kufer\Web\Classes\Export\ExportCalculation\ExportCalcWarenkorb())->resolveVar($this->getVarName($varname), $this->exportresults[$this->actualset]->teilnehmer);
      case 'maplanend_':
        return $this->expCalculation->getVarValue4BasysUser($this->getVarName($varname), $this->getKurs()->getPlanendenMitarbeiter());
      case 'maverwaltend_':
        return $this->expCalculation->getVarValue4BasysUser($this->getVarName($varname), $this->getKurs()->getVerwaltendenMitarbeiter());
    }
  }

  
  protected function getKurs()
  {
    return $this->exportresults[$this->actualset]->kurs;
  }
}