<?php

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

namespace Kufer\Web\Classes\Api\SearchRestriction;

class SearchRestrictionKatGebuehrBisFilter extends SearchRestriction
{
  public function __construct()
  {
    $this->sessionName = $this->requestName = 'katgebuehrbisfilter';
  }

  public function applyRestriction($pFromObject, $pToObject)
  {
    if ($pFromObject == null || $pToObject == null || !($pFromObject instanceof \Kurs) || !($pToObject instanceof \Kurs)) {
      throw new \InvalidArgumentException('pFromObject oder pToObject ist kein Kurs');
    }

    $filterKriterium = \RequestOperations::getVarValue($this->requestName, '');

    if ($filterKriterium !== '' && $this->isValid($filterKriterium)) {
      \SessionOperations::setVarValueFilter($this->sessionName, $this->cleanFilterKriterium($filterKriterium));
    } else {
      if (\RequestOperations::isDefined($this->requestName)) { 
        
        $this->reset();
      }
    }
    $f = \SessionOperations::getVarValueFilter($this->sessionName);
    if ($f !== '') {
      $pToObject->gebuehr = $f;
    }
  }

  private function isValid($pFilterKriterium)
  {
    return \CleanOperations::isFloatMitKomma($pFilterKriterium);
  }

  private function cleanFilterKriterium($pFilterKriterium)
  {
    return \CleanOperations::cleanFloatMitKomma($pFilterKriterium);
  }

  public function getFilterValue()
  {
    $this->applyRestriction(new \Kurs(), new \Kurs());

    return \SessionOperations::getVarValueFilter($this->sessionName);
  }
}

class SearchRestrictionKatGebuehrBisRendererText extends SearchRestrictionRendererTextBase
{
  public function __construct($pFilter = null)
  {
    parent::__construct(new SearchRestrictionKatGebuehrBisFilter());
  }
}