<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Firma\KursUebersicht\TermineUebersicht;

class SetFilterTermineUebersichtController extends TermineUebersichtController
{
  protected function getRequestObj()
  {
    $requestObj = parent::getRequestObj();
    if (!$this->isBrowserRefresh()) {
      $requestObj->suchParameter = $this->getFilterFromPost();
      if (\RequestOperations::isDefined('terminbereich') && \RequestOperations::getVarValue('terminbereich') == 'alle') {
        $requestObj->suchParameter = array_fill_keys(array_keys($requestObj->suchParameter), '');
      }
      $requestObj->aendereFilter = true;
    }

    return $requestObj;
  }

  protected function getFilterFromPost()
  {
    $tool = 21;
    $suchApi = new \KursplanungKurstagSucheAPI();

    return $suchApi->getSearchParamsFromReq('tool' . $tool, 'searchkurstage');
  }

  private function isBrowserRefresh()
  {
    
    return !\RequestOperations::isDefined('search_datum_von');
  }
}