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


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

    $this->select = 'ID, TNr, Typ, Taetigkeit, Von, Bis';
  }

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

  
  public function _idOk($pID)
  {
    return !empty($pID) && is_numeric($pID);
  }

  
  public function _TNrOk($pTNr)
  {
    return !empty($pTNr) && is_numeric($pTNr);
  }

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

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

    $obj->id = $this->getDatamodulValue('ID');
    $obj->tnr = $this->getDatamodulValue('TNr');
    $obj->taetigkeit = $this->getDatamodulValue('Taetigkeit');
    $obj->von = $this->getDatamodulValue('Von');
    $obj->bis = $this->getDatamodulValue('Bis');

    return $obj;
  }

  
  public function getWerdegangById($pID)
  {
    if (!$this->_idOK($pID)) {
      return;
    }
    $this->dboperation->clear();
    $this->dboperation->query("SELECT $this->select FROM adr_werdegang WHERE ID = $pID AND Typ = 'T'");

    if ($this->dboperation->rowcount() == 0) {
      return;
    }

    return $this->getFirstRow();
  }

  
  public function getWerdegangByTNr($pTNr)
  {
    if (!$this->_TNrOK($pTNr)) {
      return;
    }
    $this->dboperation->clear();
    $this->dboperation->query("SELECT $this->select FROM adr_werdegang WHERE TNr = $pTNr AND Typ = 'T'");

    if ($this->dboperation->rowcount() == 0) {
      return;
    }

    return $this->getAllRows();
  }
}