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


class DBWorkHLDozTyp extends DBWork
{
  protected static $_cache_DozTypNotShownResult;

  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, typ, text, ohne_anz, sort';
  }

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

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

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $obj = $this->getNewObject();

    $obj->id = $this->getDatamodulValue('id');
    $obj->typ = $this->getDatamodulValue('typ');
    $obj->text = $this->getDatamodulValue('text');
    $obj->ohne_anz = $this->getDatamodulValue('ohne_anz');
    $obj->sort = $this->getDatamodulValue('sort');

    return $obj;
  }

  public function getAll()
  {
    $this->dboperation->clear();
    $this->dboperation->query('SELECT ' . $this->select . ' FROM hldoztyp ORDER BY sort ASC');

    return $this->getAllRows();
  }

  public function getByTyp($pTyp)
  {
    $typ = $this->dboperation->getString4Sql($pTyp);
    $sql = "SELECT $this->select FROM hldoztyp WHERE typ='$typ'";
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getFirstRow();
  }

  
  public function getDozTypNotShown($pRefreshCache = false)
  {
    if ($pRefreshCache || !isset(self::$_cache_DozTypNotShownResult)) {
      $sql = 'SELECT ' . $this->select . ' FROM hldoztyp WHERE ohne_anz like \'W\'';
      $this->dboperation->clear();
      $this->dboperation->query($sql);
      self::$_cache_DozTypNotShownResult = $this->getAllRows();
    }

    return self::$_cache_DozTypNotShownResult;
  }
}