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



class DBWorkWebProtocol extends DBWork
{
  
  public $select = '';

  
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'SELECT id, user_id, sqltime, tablename, fieldname, identifier, sqltype'
      . ', status, bearbeiter, bearbdatum, actionid, ' . $this->clob('oldvalue')
      . ', ' . $this->clob('newvalue') . ' FROM web_protocol';
  }

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

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

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $tmp = $this->getNewObject();
    $tmp->id = $this->getDatamodulValue('id');
    $tmp->user_id = $this->getDatamodulValue('user_id');
    $tmp->sqltime = $this->getDatamodulValue('sqltime');
    $tmp->tablename = $this->getDatamodulValue('tablename');
    $tmp->fieldname = $this->getDatamodulValue('fieldname');
    $tmp->identifier = $this->getDatamodulValue('identifier');
    $tmp->oldvalue = $this->getDatamodulValue('oldvalue');
    $tmp->newvalue = $this->getDatamodulValue('newvalue');
    $tmp->sqltype = $this->getDatamodulValue('sqltype');
    $tmp->status = $this->getDatamodulValue('status');
    $tmp->bearbeiter = $this->getDatamodulValue('bearbeiter');
    $tmp->bearbdatum = $this->getDatamodulValue('bearbdatum');
    $tmp->actionid = $this->getDatamodulValue('actionid');

    return $tmp;
  }

  
  public function canupdate($varname)
  {
    switch ($varname) {
      default: return parent::canupdate($varname);
      case 'id': return false;
    }
  }

  
  public function getProtocolEntries()
  {
    $this->dboperation->clear();
    $this->dboperation->query($this->select);

    return $this->getAllRows();
  }

  
  public function getProtocolEntries4BookCount()
  {
    $this->dboperation->clear();
    $this->dboperation->query('SELECT id FROM web_protocol WHERE status = 0');

    return $this->dboperation->rowcount();
  }

  
  public function getProtocolEntries4Book()
  {
    $this->dboperation->clear();
    $sql = $this->select . ' WHERE status = 0';
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }

  
  public function setProtocolEntriesStatus()
  {
    $this->dboperation->clear();
    $sql = 'UPDATE web_protocol SET status = 4 WHERE status = 0';
    $this->dboperation->execute($sql);
  }
}