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

namespace Kufer\KuferTools\Utils\DatamodulHelper\KursTageHelper;

abstract class KursTageHelper extends \DatamodulHelper
{
  protected $toolSettings;

  
  protected $user;

  public function __construct($toolSettings, $user)
  {
    $this->toolSettings = $toolSettings;
    $this->user = $user;
  }

  protected function getKurstageIds($dbwKurseTage)
  {
    return array();
  }

  public function getIdsMitFilter($pToolId)
  {
    static $alleKts = null;
    if (is_null($alleKts)) {
      $dbwKurseTage = $this->getDBWork();
      $dbwKurseTage = $this->setzeEinstellungen($dbwKurseTage);
      $dbwKurseTage = $this->setzeSortierung($dbwKurseTage);
      $dbwKurseTage = $this->setzeFilter($dbwKurseTage, $pToolId);
      $alleKts = $this->getKurstageIds($dbwKurseTage);
    }

    return $alleKts;
  }

  public function getIdsOhneFilter()
  {
    static $alleKts = null;
    if (is_null($alleKts)) {
      $dbwKurseTage = $this->getDBWork();
      $dbwKurseTage = $this->setzeEinstellungen($dbwKurseTage);
      $dbwKurseTage = $this->setzeSortierung($dbwKurseTage);
      $alleKts = $this->getKurstageIds($dbwKurseTage);
    }

    return $alleKts;
  }

  protected function setzeEinstellungen($dbwKurseTage)
  {
    return $dbwKurseTage;
  }

  protected function setzeSortierung($dbwKurseTage)
  {
    $dbwKurseTage->orderby = !empty($this->toolSettings->sortkt) ? $this->toolSettings->sortkt : 'kt.datum';
    $dbwKurseTage->orderbyasc = $this->toolSettings->sortktasc;
    $dbwKurseTage->orderby2 = 'kt.zeit_beg';
    $dbwKurseTage->orderbyasc2 = $this->toolSettings->sortktasc;
    $dbwKurseTage->orderby3 = 'kt.zeit_ende';
    $dbwKurseTage->orderbyasc3 = $this->toolSettings->sortktasc;
    $dbwKurseTage->orderby4 = 'kt.ort';
    $dbwKurseTage->orderbyasc4 = true;
    
    
    
    $dbwKurseTage->orderby5 = 'kt.id';
    $dbwKurseTage->orderbyasc5 = true;

    return $dbwKurseTage;
  }

  protected function setzeFilter($dbwKurseTage, $pToolId)
  {
    return $dbwKurseTage;
  }

  public function getDBWork()
  {
    $dbwKurseTage = new \DBWorkKurseTageWT(1, true);
    $dbwKurseTage->newSearch();

    return $dbwKurseTage;
  }

  public function getFilter($pToolId)
  {
    $dbwKurseTage = $this->getDBWork();

    return $this->setzeFilter($dbwKurseTage, $pToolId);
  }

  public function getDatamoduleByIds($pIds)
  {
    $dbwKt = $this->getDBWork();
    $kurstage = $dbwKt->getKurseTageByIds($pIds);

    return \ArrayOperations::sortObjectsByValueArray($kurstage, $pIds, 'id');
  }
}