<?php


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

namespace Kufer\Web\Webbasys\Includee\Ics;

use DBWorkKurseINetAktivFilter;
use IcsAPI;
use SessionOperations;

class IcsExportKurse extends IcsExport {

  protected function getData()
  {
    $dbwKurse = new DBWorkKurseINetAktivFilter(1, true);
    $dbwKurse->newSearch();
    $dbwKurse->setOrderByValues($this->urlparameter);

    SessionOperations::setKursSearch();
    $dbwKurse->fromobject = SessionOperations::getKurssearchFromObject(true);
    $dbwKurse->toobject = SessionOperations::getKurssearchToObject(true);

    $kurse = $dbwKurse->getKurseByCategoryLimit(-1, null, 999999);

    return IcsAPI::getIcsContentKurse($kurse);
  }

  public function getFilename(): string
  {
    $allgSettings = \AllgSettingsAPI::getAllgSettings();

    $dangerousCharacters = array(" ", '"', "'", "&", "/", "\\", "?", "#", '.');
    $safe_filename = str_replace($dangerousCharacters, '_', $allgSettings->vhsname);
    return 'alleKurstermine_' . $safe_filename;
  }
}