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

namespace Kufer\Web\KuferTools\Veranstalter\KursUebersichtDerMitarbeiter\KursUebersicht\Detailsreiter\InfoAnDoz;

class InfoAnDozUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\EinzelKursUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new InfoAnDozResponse());
  }

  public static function getToolId()
  {
    return 61;
  }

  public static function getToolSectionId()
  {
    return 722;
  }

  public function hasAccess($pToolSectionId = null)
  {
    $sectId = $this->getToolSectionId();
    if (!\Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase::hasAccess()) {
      return false;
    }
    
    if (!$this->isRechtAllowed($sectId . '.0.4')) {
      return false;
    }

    return true;
  }

  protected function getAllowedIds()
  {
    $user = $this->getUser();
    $kurshelper = new \Kufer\Web\KuferTools\Utils\DatamodulHelper\Kurse\VeranstalterKurseDerMitarbeiter($this->toolSettings, $user);

    return $kurshelper->getIdsOhneFilter();
  }

  protected function getRequestedId()
  {
    return $this->request->knr;
  }

  public function action()
  {
    $user = $this->getUser();
    $kurshelper = new \Kufer\Web\KuferTools\Utils\DatamodulHelper\Kurse\VeranstalterKurseDerMitarbeiter($this->toolSettings, $user);
    $kurs = $kurshelper->getDatamodulById($this->request->knr);

    $dbwKurse = new \DBWorkKurseWT(1, true);
    $dozentenTmp = $dbwKurse->getDozentenForKurse(array($kurs->id));

    $dozenten = array();
    
    array_walk_recursive($dozentenTmp, function($dozentObj) use (&$dozenten) { $dozenten[] = $dozentObj; });

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

  protected function getResponse($kurs, $dozenten)
  {
    $this->handleResponseStrategies();
    $this->response->kurs = $kurs;
    $this->response->dozenten = $dozenten;
    $this->response->countDozenten = count($dozenten);

    return $this->response;
  }

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

class InfoAnDozRequest
{
  public $knr;
}

class InfoAnDozResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $menuPunkte;
  public $kurs;
  public $dozenten;
  public $countDozenten;
  public $user;
  public $menuBar;
}