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

namespace Kufer\KuferTools\Utils\WssField;

class WssFieldAgbBestaetigtAm extends WssFieldCheckbox
{
  protected function additionalTrueConditions($value)
  {
    if ($value === '') {
      return false;
    }

    $datetime = \DateTimeObj::createFromString($value);
    if ($datetime->getDate() == DEFAULTDATE) {
      return false;
    }

    return true;
  }

  protected function getFieldNichtBearbeitbar($datamodulWert, $isFormular, string $requestPrefix = '')
  {
    $date = $datamodulWert->getVarValueEx($this->getFieldName(), $this->getDatamodulName());

    return $date === '' ? '' : $this->encodeValue('AGB wurden bestätigt am ' . $date);
  }

  protected function getPostValueToVarValue($columnValues, $value)
  {
    return \in_array($value, array('j', 'J')) ? \DateTimeObj::getNow()->getDateTime() : '';
  }
}