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


class DBWorkAnwVerhaltenText extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, text';
    $this->_dataModulFields = array('text', 'id');
  }

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

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

  
  public function getAnwVerhaltenTextById($pId)
  {
    $id = $this->dboperation->getInt4Sql($pId);

    $sql = 'SELECT ' . $this->select
           . ' FROM ' . $this->getTableName()
           . ' WHERE id = ' . $id;

    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getFirstRow();
  }

  
  public function insertVerhaltenText($pAnwVerhaltenText, $pDontProtocol = false, $pDmzBetrieb = false)
  {
    $pAnwVerhaltenText->id = $this->insertRecord($this->getTableName(), 'id', 'text', false);
    if (!$pDontProtocol) {
      $this->saveChanging($this->getTableName(), '', '', $pAnwVerhaltenText->id, 'id', 'I', $pDmzBetrieb);
    }
    $orgAnwVerhaltenText = $this->getOneNoFilter($pAnwVerhaltenText->id);
    $this->updateObject($pAnwVerhaltenText, $orgAnwVerhaltenText, $this->getTableName(), 'id', 'A', $pDontProtocol, $pDmzBetrieb);
    $this->setActionIDs();

    return $orgAnwVerhaltenText->id;
  }

  
  public function updateVerhaltenText($pAnwVerhaltenText, $pDontProtocol = false, $pDmzBetrieb = false)
  {
    $origVerhaltenText = $this->getOneNoFilter($pAnwVerhaltenText->id);
    $this->updateObject($pAnwVerhaltenText, $origVerhaltenText, $this->getTableName(), 'id', 'U', $pDontProtocol, $pDmzBetrieb);
    $this->setActionIDs();
  }

  
  public function deleteVerhaltenText($pId, $pDontProtocol = false, $pDmzBetrieb = false)
  {
    $cleanId = $this->dboperation->getInt4Sql($pId);
    $this->dboperation->clear();
    $this->dboperation->execute('DELETE FROM ' . $this->getTableName() . ' WHERE id=' . $cleanId);
    if (!$pDontProtocol) {
      $this->saveChanging($this->getTableName(), '', '', "'" . $cleanId . "'", '', 'D', $pDmzBetrieb);
    }
    $this->setActionIDs();
  }
}