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

namespace Kufer\KuferTools\Veranstalter\KursUebersicht\SortierenDialog;

class SortierenDialogUseCase extends \Kufer\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new SortierenDialogResponse());
  }

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_KURSUEBERSICHT_VA;
  }

  public static function getToolSectionId()
  {
    return 622;
  }

  public function action()
  {
    $sortArryVals = $this->getSortValuesChecked();

    return $this->getResponse($sortArryVals);
  }

  private function getSortValuesChecked()
  {
    $sortArry = array();
    $i = 1;
    $kriterium = '';
    for ($x = 0; $x < 2; $x++) {
      $sortArry['kr' . $i . '_KursAsc'] = '';
      $sortArry['kr' . $i . '_KursDesc'] = '';
      $sortArry['kr' . $i . '_BeginndatAsc'] = '';
      $sortArry['kr' . $i . '_BeginndatDesc'] = '';
      $sortArry['kr' . $i . '_BeginnzeitAsc'] = '';
      $sortArry['kr' . $i . '_BeginnzeitDesc'] = '';
      $sortArry['kr' . $i . '_OrtAsc'] = '';
      $sortArry['kr' . $i . '_OrtDesc'] = '';
      $sortArry['kr' . $i . '_AussenstelleAsc'] = '';
      $sortArry['kr' . $i . '_AussenstelleDesc'] = '';

      if ($this->request->{"sortOrderValue$i"} == '') {
        $sortArry['kr' . $i . '_KursAsc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'nr' && $this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_KursDesc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'nr' && !$this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_BeginndatAsc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'beginn_dat' && $this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_BeginndatDesc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'beginn_dat' && !$this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_BeginnzeitAsc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'beginn' && $this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_BeginnzeitDesc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'beginn' && !$this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_OrtAsc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'ort' && $this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_OrtDesc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'ort' && !$this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_AussenstelleAsc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'aussenst' && $this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
        $sortArry['kr' . $i . '_AussenstelleDesc'] = ($this->toolSettings->{"sortkurse$kriterium"} == 'aussenst' && !$this->toolSettings->{"sortkurseasc$kriterium"}) ? 'checked="checked"' : '';
      } else {
        switch ($this->request->{"sortOrderValue$i"}) {
          case 'beginnauf':
            $sortArry['kr' . $i . '_BeginndatAsc'] = 'checked="checked"';
            break;
          case 'beginnab':
            $sortArry['kr' . $i . '_BeginndatDesc'] = 'checked="checked"';
            break;
          case 'kursauf':
            $sortArry['kr' . $i . '_KursAsc'] = 'checked="checked"';
            break;
          case 'kursab':
            $sortArry['kr' . $i . '_KursDesc'] = 'checked="checked"';
            break;
          case 'beginnzeitauf':
            $sortArry['kr' . $i . '_BeginnzeitAsc'] = 'checked="checked"';
            break;
          case 'beginnzeitab':
            $sortArry['kr' . $i . '_BeginnzeitDesc'] = 'checked="checked"';
            break;
          case 'ortauf':
            $sortArry['kr' . $i . '_OrtAsc'] = 'checked="checked"';
            break;
          case 'ortab':
            $sortArry['kr' . $i . '_OrtDesc'] = 'checked="checked"';
            break;
          case 'aussenstelleauf':
            $sortArry['kr' . $i . '_AussenstelleAsc'] = 'checked="checked"';
            break;
          case 'aussenstelleab':
            $sortArry['kr' . $i . '_AussenstelleDesc'] = 'checked="checked"';
            break;
        }
      }
      $i = 2;
      $kriterium = 2;
    } 

    return $sortArry;
  }

  

  protected function getResponse($sortArryVals)
  {
    $this->response->sortArryVals = $sortArryVals;

    return $this->response;
  }
}

class SortierenDialogRequest
{
  public $sortOrderValue1;
  public $sortOrderValue2;
}

class SortierenDialogResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
}