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

namespace Kufer\Web\KuferTools\Utils;

class Referrer
{
  
  public static function aktualisiereReferrerInSession($toolId, $refererFromGet, $refererLabelFromGet, $sessionPrefix = 'referer_tool')
  {
    if (!empty($refererFromGet)) {
      \SessionOperations::setVarValueWTIntern($sessionPrefix . $toolId, $refererFromGet);
    }
    if (!empty($refererLabelFromGet)) {
      \SessionOperations::setVarValueWTIntern('label_' . $sessionPrefix . $toolId, $refererLabelFromGet);
    }
  }

  
  public static function resetReferrerInSession($toolId, $sessionPrefix = 'referer_tool')
  {
    \SessionOperations::setVarValueWTIntern($sessionPrefix . $toolId, '');
    \SessionOperations::setVarValueWTIntern('label_' . $sessionPrefix . $toolId, '');
  }

  public static function getReferrerTupleFromSession($toolId, $defaultReferer, $defaultRefererLabel, $sessionPrefix = 'referer_tool')
  {
    return array(static::getReferrerFromSession($toolId, $defaultReferer, $sessionPrefix), static::getReferrerLabelFromSession($toolId, $defaultRefererLabel, $sessionPrefix));
  }

  
  public static function getReferrerFromSession($toolId, $default, $sessionPrefix = 'referer_tool')
  {
    $referer = \SessionOperations::getVarValueWTIntern($sessionPrefix . $toolId);
    if (empty($referer)) {
      $referer = $default;
    }

    return $referer;
  }

  
  public static function getReferrerLabelFromSession($toolId, $default, $sessionPrefix = 'referer_tool')
  {
    $refererLabel = \SessionOperations::getVarValueWTIntern('label_' . $sessionPrefix . $toolId);
    if (empty($refererLabel)) {
      $refererLabel = $default;
    }

    return $refererLabel;
  }
}