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

namespace Kufer\Web\KuferTools\Dozent\KursUebersicht\Detailsreiter\Honorar\RavensbergHalle\HonorarPdf;

class KurstagForm extends \Kufer\Web\KuferTools\Utils\Form\AbstractForm
{
  
  public $id;

  
  public $lehrinhalte = '';

  public function validate_id(): bool
  {
    return \CleanOperations::isInt($this->id) || $this->id === 'new';
  }

  public function fromRequest(string $prefix = ''): void
  {
  }

  
  public static function getAllFromRequest(string $prefix = ''): ?array
  {
    $ids = \PostOperations::getVarValue($prefix . 'id', null);
    $lehrinhalte = \PostOperations::getVarValue($prefix . 'lehrinhalte', null);
    if (empty($ids) || empty($lehrinhalte)) {
      return null;
    }

    if (count(array_unique(array(count($ids), count($lehrinhalte)))) !== 1) {
      return null; 
    }

    $result = array();
    for ($i = 0; $i < count($ids); ++$i) {
      $kurstagForm = new KurstagForm();
      $kurstagForm->id = $ids[$i];
      $kurstagForm->lehrinhalte = $lehrinhalte[$i];

      $result[] = $kurstagForm;
    }

    return $result;
  }

  public static function fromKurstag(\Kurstag $kurstag): KurstagForm
  {
    $result = new KurstagForm();
    $result->id = $kurstag->id;
    $result->datum = $kurstag->datum;
    $result->ue = \MathOperations::floatToStringTruncateNull($kurstag->ue);
    $result->lehrinhalte = $kurstag->klassenbuchtext;

    return $result;
  }
}