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


class TNListSettings extends Datamodul
{
  
  public $listID;
  
  public $toolID;
  
  public $teilnehmer;
  
  public $columns;
  
  public $header;
  
  public $filter;
  
  public $customState;
  
  public $sort;
  
  public $footer;
  
  public $caption;
  
  public $portrait;
  
  public $padding;
  
  public $comment;
  
  public $footer1;
  
  public $footer1size;
  
  public $footer1bold;
  
  public $footer2;
  
  public $footer2size;
  
  public $footer2bold;
  
  public $footer3;
  
  public $footer3size;
  
  public $footer3bold;
  
  public $footer4;
  
  public $footer4size;
  
  public $footer4bold;
  
  public $footer5;
  
  public $footer5size;
  
  public $footer5bold;

  
  public $SpaltenUeb1;

  
  public $SpaltenUeb2;

  
  public $SpaltenUeb3;

  
  public $SpaltenUeb4;

  
  public $SpaltenUeb5;

  public $text1;
  public $text2;

  
  public function _getTeilnehmerBit($optionName)
  {
    $matches = array();
    if (preg_match('/^option([0-9]+)$/', $optionName, $matches) === 1) {
      return pow(2, (int)$matches[1] - 1);
    } else {
      return false;
    }
  }

  
  public function isTeilnehmerSet($optionName)
  {
    if ($this->teilnehmer === '') {
      $this->teilnehmer = 0;
    }

    $bit = $this->_getTeilnehmerBit($optionName);
    if (!$bit) {
      return false;
    }

    return ($this->teilnehmer & $bit) == $bit;
  }

  
  public function setTeilnehmer($optionName)
  {
    $bit = $this->_getTeilnehmerBit($optionName);
    if ($bit) {
      $this->teilnehmer = $this->teilnehmer | $bit;
    }
  }

  
  public function _getColumnsBit($optionName)
  {
    $matches = array();
    if (preg_match('/^option([0-9]+)$/', $optionName, $matches) === 1) {
      return pow(2, (int)$matches[1] - 1);
    } else {
      return false;
    }
  }

  
  public function isColumnsSet($optionName)
  {
    $bit = $this->_getColumnsBit($optionName);
    if (!$bit) {
      return false;
    }

    return ((int)$this->columns & $bit) == $bit;
  }

  
  public function setColumns($optionName)
  {
    $bit = $this->_getColumnsBit($optionName);
    if ($bit) {
      $this->columns = $this->columns | $bit;
    }
  }

  
  public function _getHeaderBit($optionName)
  {
    switch ($optionName) {
      case 'mitKursgebuehren':
        return 1;
      case 'mitDozentenTelNr':
        return 2;
      case 'ohneMinMaxTN':
        return 4;
      case 'mitDauerdetails':
        return 8;
      case 'ohneDauer':
        return 16;
      case 'ohneKursOrt':
        return 32;
    }

    return false;
  }

  
  public function isHeaderSet($optionName)
  {
    $bit = $this->_getHeaderBit($optionName);
    if (!$bit) {
      return false;
    }

    return ((int)$this->header & $bit) == $bit;
  }

  
  public function setHeader($optionName)
  {
    $bit = $this->_getHeaderBit($optionName);

    if ($bit) {
      $this->header = $this->header | $bit;
    }
  }

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'id':
      case 'listid':
      case 'toolid':
      case 'listID':
      case 'toolID':
      case 'teilnehmer':
      case 'spalten':
      case 'columns':
      case 'kopf':
      case 'fuss':
      case 'header':
      case 'footer':
      case 'portrait':
      case 'footer1size':
      case 'footer1bold':
      case 'footer2size':
      case 'footer2bold':
      case 'footer3size':
      case 'footer3bold':
      case 'footer4size':
      case 'footer4bold':
      case 'footer5size':
      case 'footer5bold':
        return \DatamodulVarType::TYPE_INT;
    }
  }
}