<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, 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 (!(defined('ISKUFERTOOLS_RESPONSIVE') && ISKUFERTOOLS_RESPONSIVE)) {
      $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);
  }
}