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

class Column extends Field
{
  public $sight_field_id = 0;
  public $title = '';
  public $width = 0;
  public $fontsize = 0;
  public $bold = 0;
  public $maxlength = '';

  public $accesslevel = 1;
  
  public $x;
  
  public $y;
  
  public $mandatory_field;
  
  public $depositation_only;
  
  public $height;
  
  public $is_label;
  
  public $textfarbe;
  
  public $ausrichtung;
  
  public $head;
  
  public $tail;
  
  public $wenn_leer;
  public $responsive;

  public $hyperlink = 0;

  
  public function getAusrichtung4CSS()
  {
    switch ($this->ausrichtung) {
      default:
      case 'L':
        return 'left';
      case 'R':
        return 'right';
      case 'C':
        return 'center';
      case 'J':
        return 'justify';
    }
  }

  public function isEmpty()
  {
    $nocheck = array('canedit', 'istext', 'accesslevel');
    foreach (get_object_vars($this) as $var => $value) {
      if (!$this->isValueEmptyOrDefault($value) && !in_array($var, $nocheck)) {
        if (is_a($value, 'Datamodul')) {
          return $value->isEmpty();
        } else {
          return false;
        }
      }
    }

    return true;
  }

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'sight_field_id':
      case 'width':
      case 'fontsize':
      case 'bold':
      case 'x':
      case 'y':
      case 'height':
        return \DatamodulVarType::TYPE_INT;
      case 'mandatory_field':
      case 'depositation_only':
      case 'is_label':
        return \DatamodulVarType::TYPE_BOOL;
    }
  }

  public function getVarValue($name)
  {
    switch ($name) {
      default: return parent::getVarValue($name);
      case 'ausrichtungclass':
        switch ($this->ausrichtung) {
        default:
        case 'L': return 'left';
        case 'R': return 'right';
        case 'C': return 'center';
        case 'J': return 'justify';
        }
    }
  }
}