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



class CreateSight
{
  
  public function createList($pDatamodul, $pSightID, $pBodyInhalt, $pBodyExpAdapter, $pDefaultExp = null, $pListenZusatzInfo = '')
  {
    
    

    $retour = '';
    $dmbasis = new DataMenuBasis(new URLParameterBasis());
    $defaultExp = $pDefaultExp;
    if ($defaultExp == null) {
      $defaultExp = new ExpKurse();
    }
    $dmbasis->getsight($pSightID);
    if ((count($pBodyInhalt) == 0)
        || ((count($pBodyInhalt) == 1) && ($pBodyInhalt[0]->isEmpty()))) {
      $dmbasis->exportadapter = $defaultExp;
      $dmbasis->dataarraynodata = array($pDatamodul);
      $retour .= $dmbasis->getnodata();
    } else {
      $dmbasis->dataarraybody = $pBodyInhalt;
      $dmbasis->dataarrayfooter = array($pDatamodul);
      $dmbasis->exportadapter = $defaultExp;

      if (isset($pDefaultExp->export->expCalculation->nrOfMainBodyElements) && $pDefaultExp->export->expCalculation->nrOfMainBodyElements > 0) {
        $dmbasis->nrOfMainBodyElements = $pDefaultExp->export->expCalculation->nrOfMainBodyElements;
      }
      $retour .= $this->_getUpperPart($dmbasis, $pDatamodul);
      
      
      $dmbasis->exportadapter = $pBodyExpAdapter;
      $dmbasis->exportadapter->setSightInfo('listenzusatzinfo', $pListenZusatzInfo);
      $retour .= $dmbasis->getbody();
      $dmbasis->exportadapter = $defaultExp;
      $retour .= $dmbasis->getfooter();
    }

    return $retour;
  }

  

  
  protected function _getUpperPart($pDmBasis, $pDatamodul)
  {
    $pDmBasis->dataarrayheader = array($pDatamodul);

    return $pDmBasis->getheader();
  }

  
  public function createEmptyHBF($pSightId, $pSightInfo)
  {
    $dmbasis = new DataMenuBasis(new URLParameterBasis());
    $dmbasis->getsight($pSightId);
    $dmbasis->dataarrayheader = $dmbasis->dataarraybody = $dmbasis->dataarrayfooter = array(new Datamodul());
    $expadapter = new ExpBasis();
    if (is_array($pSightInfo)) {
      foreach ($pSightInfo as $key => $value) {
        $expadapter->setSightInfo($key, $value);
      }
    }
    $dmbasis->exportadapter = $expadapter;
    $result = $dmbasis->getheader();
    $result .= $dmbasis->getbody();
    $result .= $dmbasis->getfooter();

    return $result;
  }
}  




class CreateSightNoColumnsAsHeader extends CreateSight
{
  
  protected function _getUpperPart($pDmBasis, $pDatamodul)
  {
    $pDmBasis->dataarraynocolumn = array($pDatamodul);

    return $pDmBasis->getnocolumn();
  }
}  







class CreateSightFassade
{
  
  public static function createListe(
    $pDatamodul,
    $pSightID,
    $pBodyInhalt,
    $pBodyExpAdapter,
    $defaultExp = null,
    $pIsHeaderDifferent = false,
    $pListenZusatzInfo = ''
  ) {
    $createSightStrategy = new CreateSight();

    if ($pIsHeaderDifferent) {
      $createSightStrategy = new CreateSightNoColumnsAsHeader();
    }

    return $createSightStrategy->createList($pDatamodul, $pSightID, $pBodyInhalt, $pBodyExpAdapter, $defaultExp, $pListenZusatzInfo);
  }
}