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


class HLKursstatus extends Datamodul
{
  
  public $wert;

  
  public $langtext;


  
  public $farbe;


  
  public $kurstext;

  
  public $anzkurs1;

  
  public $sort;

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
        default:
          return parent::getTyp($pFieldName);
        case 'sort':
        case 'farbe':
          return \DatamodulVarType::TYPE_INT;
        case 'anzkurs1':
          return \DatamodulVarType::TYPE_BOOL_WF;
      }
  }

  public function getVarValue($pName)
  {
    switch ($pName) {
      case 'farbeHex':
        return $this->colorToHex($this->farbe);
      default: return parent::getVarValue($pName);
    }
  }

  private function colorToHex($colorInt)
  {
    
    if ($colorInt == 0) {
      return 'FFFFFF';
    }

    
    
    $red = $colorInt % 256;
    $rest = floor($colorInt / 256);
    $green = $rest % 256;
    $blue = floor($rest / 256);

    $rgbDec = $red * 256 * 256 + $green * 256 + $blue;

    
    return StringOperations::lpad(dechex($rgbDec), 6, '0');
  }
}