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

namespace Kufer\KuferTools\Utils\DatamodulHelper\KursTageHelper;

class HmRaumKurstage extends KursTageHelper
{
  private $raumIds;
  private $vonDatum;
  private $bisDatum;

  public function __construct($toolSettings, $user, $raumIds, $pVonDatum, $pBisDatum)
  {
    parent::__construct($toolSettings, $user);
    $this->raumIds = $raumIds;
    $this->vonDatum = $pVonDatum;
    $this->bisDatum = $pBisDatum;
  }

  protected function getKurstageIds($dbwKurseTage)
  {
    return $dbwKurseTage->getOnlyIds(array($dbwKurseTage, 'getKurstagebyRaumIds'), array($this->raumIds));
  }

  protected function setzeSortierung($dbwKurseTage)
  {
    if ($this->toolSettings->sortmedien == 'datumZeit') {
      $dbwKurseTage->orderby = 'kt.datum';
      $dbwKurseTage->orderby2 = 'kt.zeit_beg';
      $dbwKurseTage->orderbyasc = $dbwKurseTage->orderbyasc2 = $this->toolSettings->sortmedienasc;
      $dbwKurseTage->orderby3 = $dbwKurseTage->getRaumortOrderByPart();
      $dbwKurseTage->orderbyasc3 = $this->toolSettings->sortmedienzusatzasc;
    } else {
      $dbwKurseTage->orderby = $dbwKurseTage->getRaumortOrderByPart();
      $dbwKurseTage->orderbyasc = $this->toolSettings->sortmedienasc;
      $dbwKurseTage->orderby2 = 'kt.datum';
      $dbwKurseTage->orderby3 = 'kt.zeit_beg';
      $dbwKurseTage->orderbyasc2 = $dbwKurseTage->orderbyasc3 = $this->toolSettings->sortmedienzusatzasc;
    }

    return $dbwKurseTage;
  }

  protected function setzeFilter($dbwKurseTage, $pToolId)
  {
    $dbwKurseTage->fromobject->datum = $this->vonDatum;
    $dbwKurseTage->toobject->datum = $this->bisDatum;

    return $dbwKurseTage;
  }
}