<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */


class DBWorkAnwesenheitExtraProtocol extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, eanwid, estatus, ebemerkung, evon, ebis';
  }

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

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

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

    $tmp->id = $this->getDatamodulValue('id');
    $tmp->eanwid = $this->getDatamodulValue('eanwid');
    $tmp->estatus = StringOperations::strtoupper($this->getDatamodulValue('estatus'));
    $tmp->ebemerkung = $this->getDatamodulValue('ebemerkung');
    $tmp->evon = $this->getDatamodulValue('evon');
    $tmp->ebis = $this->getDatamodulValue('ebis');

    return $tmp;
  }

  
  public function insertRecord($pTablename, $pIdField, $pDummyfield, $pGentableexists = false)
  {
    $this->dboperation->clear();
    $this->dboperation->execute('INSERT INTO ' . $this->getTableName() . " (estatus, eanwid) VALUES ('', 0)");

    return $this->dboperation->getLastID($this->getTableName());
  }

  
  public function protocolAnwesenheitExtra($pAnwesenheit, $pAnwProtocolId)
  {
    if (!$pAnwesenheit->hasExtraAnwesenheiten()) {
      return;
    }

    $count = $pAnwesenheit->getCountExtraAnwesenheiten();
    for ($i = 0; $i < $count; $i++) {
      $anwesenheitExtraProtocol = $this->getNewObject();
      $anwesenheitExtraProtocol = $anwesenheitExtraProtocol->copyFrom($pAnwesenheit->getExtraAnwesenheit($i));
      $anwesenheitExtraProtocol->eanwid = $pAnwProtocolId;
      $anwesenheitExtraProtocol->id = $this->insertRecord($this->getTableName(), 'id', 'estatus', false);
      $this->saveChanging($this->getTableName(), '', '', $anwesenheitExtraProtocol->id, 'id', 'I');
      $orgobj = $this->getNewObject();
      $orgobj->id = $anwesenheitExtraProtocol->id;
      $this->updateObject($anwesenheitExtraProtocol, $orgobj, $this->getTableName(), 'id', 'A', false);
      $this->setActionIDs();
    }

    return;
  }
}