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

if (!defined('BASEDIR')) {
  include_once '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'constants.php';
}


class DataMenuKategorieUebersichtGesamt extends DataMenuMain
{
  
  private $dbwKurse;

  
  public $settings;

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

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

    $this->dbwKurse = new DBWorkKurse();

    $this->dbwKurse->setOrderByValues(new URLParameterNavigation());

    $this->exportadapter = new ExpKategorien();
  }

  public function getsight($sightid = 412)
  {
    parent::getsight($sightid);
  }

  public function getdataarrayheader()
  {
    $result = new Category();
    $result->id = 0;
    $this->dataarrayheader = array($result);
  }

  public function getdataarraybody()
  {
    $dbwCat = new DBWorkCategories();

    $this->dataarraybody = $dbwCat->getCategoriesByTypeStructured(1, true);
    $this->nrOfMainBodyElements = count($this->dataarraybody);

    
    
    
    if (StringOperations::strpos($this->sight->header . $this->sight->body . $this->sight->footer, '{%kat_kursliste%}')) {
      $dbworkUebersicht = new DBWorkKurseINetAktivFilterUebersicht();
      $sett = ToolSettingsAPI::getToolSettings(4);
      $dbworkUebersicht->newSearch();
      $dbworkUebersicht->fromobject->semester = $sett->semlist;
      $dbworkUebersicht->setOrderByValues(new URLParameterNavigation());
      $katidToKursnr = $dbworkUebersicht->getKursIdsByCategory();

      $merged = array();
      foreach ($katidToKursnr as $kursnummern) {
        $merged = array_merge($merged, $kursnummern);
      }
      $merged = array_unique($merged);

      WBKursStore::getKurseByIdArray($merged);
    }
  }

  public function prepareMainmenu()
  {
    
    
    $this->getsight();
    $this->getdataarrayheader();
    $this->getdataarraybody();
    $this->getdataarrayfooter();
    $this->getdataarraynodata();
    $this->getdataarraynocolumn();
  }

  public function mainmenu()
  {
    $this->prepareMainmenu();
    if ($this->toolsettings->showClickpfad) {
      
      echo $this->getClickPath();
    }
    echo '<div class="hauptseite">' . "\n";
    $this->statusmenu();
    echo $this->getContentAnker();

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

    echo '</div>';
  }
}