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

namespace Kufer\Web\Classes\Export\ExportCalculation;

abstract class ExportCalc
{
  abstract public function resolveVar(string $pVarname, ?\Datamodul $datamodul = null): string;

  protected function getDefaultVarValue(string $pVarname, $pDatamodul): string
  {
    if (!isset($pDatamodul) || !$pDatamodul instanceof \Datamodul) {
      return '';
    }

    $value = $pDatamodul->getVarValue(\StringOperations::strtolower($pVarname));
    if (!\SessionOperations::isKuferToolsResponsive()) {
      $value = \CleanOperations::cleanStringForHtml($value);
    }

    return $value;
  }

  
  public function getVorbelegungFromVarname($pVarname)
  {
    $parts = explode(TRENNER_VORBELEGUNG, $pVarname);
    array_shift($parts);

    return implode(TRENNER_VORBELEGUNG, $parts);
  }

  
  public function getVarnameWithoutVorbelegung($pVarname)
  {
    $parts = explode(TRENNER_VORBELEGUNG, $pVarname);

    return array_shift($parts);
  }
}