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


class DBWorkHLInfoFelder extends DBWorkHLBasis
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);

    $this->select = 'id, text, stammdaten, sort';
    $this->orderby = 'sort';
    $this->orderbyasc = true;
  }

  
  public function getNewObject()
  {
    return new HLInfoFelder();
  }

  public function getTableName(): string
  {
    return 'hlinfofelder';
  }

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $obj = $this->getNewObject();
    $obj->id = $this->getDatamodulValue('id');
    $obj->text = $this->getDatamodulValue('text');
    $obj->stammdaten = $this->getDatamodulValue('stammdaten');
    $obj->sort = $this->getDatamodulValue('sort');

    return $obj;
  }

  
  public function getAll()
  {
    $sql = "SELECT $this->select FROM hlinfofelder " . $this->getCompleteOrderByDefault('sort');
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }

  
  public function getOne($pId)
  {
    $id = $this->dboperation->getInt4Sql($pId);
    $sql = "SELECT $this->select FROM hlinfofelder WHERE id = '$id'";
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getFirstRow();
  }

  
  public function getHLInfoFelderByTyp($pTyp)
  {
    if (!in_array($pTyp, array('K', 'DI', 'DA', 'TI', 'TA', 'AD', 'R', 'Z'))) {
      return array();
    }
    $sql = "SELECT $this->select from hlinfofelder where stammdaten like '%$pTyp;W%' "
        . $this->getCompleteOrderByDefault('sort');
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }
}