<?php

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


class DataMenuKursePerKategorie extends DataMenuOhneStatus
{
  
  public $dbwork;

  public function __construct($pUrlParameter)
  {
    parent::__construct($pUrlParameter);


    $this->settings = ToolSettingsAPI::getToolSettings(4);

    

    $this->dbwork = new DBWorkKurseINetAktiv();

    

    $this->exportadapter = new ExpKurse();
    $this->exportadapter->export->initiate();
  }

  public function getdataarraybody()
  {

    
    if ($this->urlparameter->katid == '') {
      $this->dataarraybody = array();

      return;
    }

    $this->dbwork->newSearch();
    $this->dbwork->fromobject->beginn_dat = $this->urlparameter->datum;
    $this->dbwork->fromobject->kategorie = array($this->urlparameter->katid);

    $this->dbwork->fromobject->semester = $this->settings->semlist;

    $this->dbwork->orderby = 'beginn_dat, ' . $this->dbwork->dboperation->dbparser->lpad('beginn', 'k', 10, '0');

    $this->dataarraybody = $this->dbwork->getKurseByCategoryLimit(
      -1,
      '',
      $this->urlparameter->seite * $this->urlparameter->anzahl
      ,
      true 
      ,
      false 
    );
    
    if ($this->urlparameter->seite > 1) {
      $this->dataarraybody = array_slice($this->dataarraybody, ($this->urlparameter->seite - 1) * $this->urlparameter->anzahl);
    }

    $this->nrOfMainBodyElements = count($this->dataarraybody);
  }

  public function getsight($sightId = 0)
  {
    $this->sight = SightsAPI::getSight(369);
  }

  public function mainmenu()
  {
    $this->getsight();
    $this->getdataarrayheader();
    $this->getdataarraybody();
    $this->getdataarrayfooter();
    $this->getdataarraynodata();
    $this->getdataarraynocolumn();
    if ($this->toolsettings->showClickpfad) {
      echo $this->getClickPath();
    }

    $this->showheader();
    if (count($this->dataarraybody) > 0) {
      $this->showbody();
    } else {
      $this->shownodata();
    }
    $this->showfooter();
  }

  public function getContent()
  {
    $this->_init();

    $result = $this->getheader();
    if (count($this->dataarraybody) > 0) {
      $result .= $this->getbody();
    } else {
      $result .= $this->getnodata();
    }
    $result .= $this->getfooter();

    return $result;
  }

  public function _getClickPath($pName = 'Kurse nach Kategorie')
  {
    
    return $pName;
  }
}