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

class DataMenuKursFinderAjax extends DataMenuMainTopLeft
{
  public function __construct($urlparameter)
  {
    parent::__construct($urlparameter);
    $param = new URLParameterFilter();
    if ($param->clearAllKatfilter()) {
      SessionOperations::resetKursKategorieRestrictions();
    }
    
    SessionOperations::setKursSearch();
    SessionOperations::applyKursKategorieRestrictions(new Kurs(), new Kurs());
  }

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

  public function showbody()
  {
    GetOperations::setVarValue('noform', '1');
    $cacheKey = $this->getCacheKey();
    
    $cache = Kufer\Web\KuferWEB\Api\HtmlCacheFile::getInstance();
    $content = $cache->get($cacheKey);
    if (is_null($content)) {
      $datamenu = new DataMenuKursFinderAjaxResult($this->urlparameter);
      ob_start();
      echo $datamenu->content();
      $content = ob_get_contents();
      ob_end_clean();
      $cache->set($cacheKey, $content);
    }
    echo $content;
  }

  private function getCacheKey()
  {
    $filterWerte = SessionOperations::getKursKategorieFilterValues();
    $fromObj = SessionOperations::getKurssearchFromObject(true);
    $toObj = SessionOperations::getKurssearchToObject(true);

    return sha1(implode('#', $filterWerte) . serialize($fromObj) . serialize($toObj) . serialize($this->urlparameter));
  }
}