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

class PageDozFachVertraege extends PageBaseWT
{
  protected $_data;

  public function __construct($pTool, $pData)
  {
    parent::__construct('Verträge', 494, $pTool);
    $this->_data = $pData;
  }

  
  public function getContentHeader()
  {
    return 'Verträge';
  }

  public function getContent()
  {
    $data4Presenter = $this->_getData4Presenter();
    $presenter = new FachVertraegeDoz();

    $status = array();

    if (isset($this->_data->vertragNichtGefunden)) {
      $status['vertragNichtGefunden'] = $this->_data->vertragNichtGefunden;
    }
    if (isset($this->_data->errorHolenInfosPerDmz)) {
      $status['errorHolenInfosPerDmz'] = $this->_data->errorHolenInfosPerDmz;
    }
    if (isset($this->_data->errorBeschaefitungsverhaeltnisInkonsistent)) {
      $status['errorBeschaefitungsverhaeltnisInkonsistent'] = $this->_data->errorBeschaefitungsverhaeltnisInkonsistent;
    }

    $status['successReklamation'] = $this->_data->successReklamation;
    $status['errorReklamationDmz'] = $this->_data->errorReklamationDmz;
    $status['errorReklamationEmail'] = $this->_data->errorReklamationEmail;
    $status['successAkzeptieren'] = $this->_data->successAkzeptieren;
    $status['errorAkzeptierenDmz'] = $this->_data->errorAkzeptierenDmz;

    return $presenter->render($data4Presenter, $status);
  }

  private function _getData4Presenter()
  {
    $dataInfoAry = array();
    foreach ($this->_data->dozKurse as $dozKurs) {
      $deputate = $this->_getDeputate4DozKurs($dozKurs);
      if (count($deputate) > 0) {
        $dataInfo = new StdClass();
        $dataInfo->dozKurs = $dozKurs;
        $dataInfo->kurs = $this->_getKurs4DozKurs($dozKurs);
        $dataInfo->deputate = $deputate;
        $dataInfoAry[] = $dataInfo;
      }
    }

    return $dataInfoAry;
  }

  private function _getKurs4DozKurs($dozKurs)
  {
    foreach ($this->_data->kurse as $kurs) {
      if ($dozKurs->kurs == $kurs->id) {
        return $kurs;
      }
    }

    return new Kurs();
  }

  private function _getDeputate4DozKurs($dozKurs)
  {
    $result = array();
    foreach ($this->_data->deputate as $deputat) {
      if ($deputat->doz_kurs_id == $dozKurs->id) {
        $result[] = $deputat;
      }
    }

    return $result;
  }
}