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

namespace Kufer\Web\KuferTools\Dozent\KursUebersicht\Detailsreiter\Termine\TerminAbsagen;

class TerminAbsagenUseCase extends \Kufer\Web\KuferTools\Dozent\KursUebersicht\EinzelKursUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new TerminAbsagenResponse());
  }

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

  public static function getToolSectionId()
  {
    return 4;
  }

  public function action()
  {
    
    

    $kurs = $this->getKurs($this->request->knr);
    $kurstage = $this->getKurstage($kurs);

    return $this->getResponse($kurs, $kurstage);
  }

  private function getKurstage($kurs)
  {
    $dbwKurstage = new \DBWorkKurseTageWT(1, true);
    $onlyLoggedInDozent = true;
    $onlyDiffrentKt = false;
    $dbwKurstage->newSearch();
    $dbwKurstage->toobject->nodoztool = true;
    $kurstage = $dbwKurstage->getKurstagebyKursNR($kurs->id, -1, $onlyLoggedInDozent, $onlyDiffrentKt);

    
    if (count($this->request->terminNummern) > 0) {
      $result = array();
      foreach ($kurstage as $kurstag) {
        if (in_array($kurstag->id, $this->request->terminNummern)) {
          $result[] = $kurstag;
        }
      }
    } else {
      $result = $kurstage;
    }

    return $result;
  }

  protected function getResponse($kurs, $kurstage)
  {
    $this->handleResponseStrategies();
    $this->response->kurs = $kurs;
    $this->response->kurstage = $kurstage;
    $this->response->dozent = \SessionOperations::getCurrentWebToolsDozent();

    return $this->response;
  }

  protected function getResponseStrategies()
  {
    return array(
        new \Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseMitRahmen($this)
    );
  }
}

class TerminAbsagenRequest
{
  public $knr;
  public $terminNummern = array();
}

class TerminAbsagenResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $kurs;
  public $kurstage;
  public $menuPunkte;
  public $user;
  public $dozent;
}