add Models for Vertragsbestandteiltyp and VertragsbestandteilFreitexttyp, implement IValidation Interface on AbstrcatBestandteil, add OverlapChecker checking for overlapping VBs against DB

This commit is contained in:
Harald Bamberger
2023-10-23 17:58:18 +02:00
parent 479df7189c
commit 05e2808f00
12 changed files with 245 additions and 49 deletions
@@ -1,18 +1,26 @@
<?php
namespace vertragsbestandteil;
use vertragsbestandteil\IValidation;
/**
* Description of AbstractBestandteil
*
* @author bambi
*/
abstract class AbstractBestandteil
abstract class AbstractBestandteil implements IValidation
{
protected $isvalid;
protected $validationerrors;
protected $modifiedcolumns;
protected $fromdb;
public function __construct()
{
$this->isvalid = false;
$this->validationerrors = array();
$this->modifiedcolumns = array();
$this->fromdb = false;
}
@@ -37,5 +45,25 @@ abstract class AbstractBestandteil
}
}
public function isValid()
{
return $this->isvalid;
}
public function getValidationErrors()
{
return $this->validationerrors;
}
public function addValidationError($errormsg)
{
if( !in_array($errormsg, $this->validationerrors, true) )
{
$this->validationerrors[] = $errormsg;
}
$this->isvalid = false;
}
abstract public function hydrateByStdClass($data, $fromdb=false);
}
@@ -16,7 +16,7 @@ const TYPE_ECHT_FREI = 'echterfreier';
const TYPE_WERKVERTRAG = 'werkvertrag';
const TYPE_UEBERLASSUNG = 'ueberlassungsvertrag';
class Dienstverhaeltnis extends AbstractBestandteil implements IValidation {
class Dienstverhaeltnis extends AbstractBestandteil {
protected $dienstverhaeltnis_id;
protected $mitarbeiter_uid;
protected $vertragsart_kurzbz;
@@ -27,15 +27,10 @@ class Dienstverhaeltnis extends AbstractBestandteil implements IValidation {
protected $insertvon;
protected $updateamum;
protected $updatevon;
protected $isvalid;
protected $validationerrors;
public function __construct()
{
parent::__construct();
$this->isvalid = false;
$this->validationerrors = array();
}
public function hydrateByStdClass($data, $fromdb=false)
@@ -211,16 +206,6 @@ EOTXT;
return $this;
}
public function isValid()
{
return $this->isvalid;
}
public function getValidationErrors()
{
return $this->validationerrors;
}
public function validate() {
//do Validation here
$ci = get_instance();
@@ -7,7 +7,7 @@ use DateTimeImmutable;
/**
* Salary always depends on employment (Dienstverhältnis) and optionally on part of contract (Vetragsbestandteil)
*/
class Gehaltsbestandteil extends AbstractBestandteil implements IValidation, \JsonSerializable
class Gehaltsbestandteil extends AbstractBestandteil implements \JsonSerializable
{
protected $gehaltsbestandteil_id;
protected $dienstverhaeltnis_id;
@@ -26,15 +26,10 @@ class Gehaltsbestandteil extends AbstractBestandteil implements IValidation, \Js
protected $insertvon;
protected $updateamum;
protected $updatevon;
protected $isvalid;
protected $validationerrors;
public function __construct()
{
parent::__construct();
$this->isvalid = false;
$this->validationerrors = array();
}
public function hydrateByStdClass($data, $fromdb=false)
@@ -326,16 +321,6 @@ EOTXT;
return $txt;
}
public function isValid()
{
return $this->isvalid;
}
public function getValidationErrors()
{
return $this->validationerrors;
}
public function validate() {
//do Validation here
if( empty($this->gehaltstyp_kurzbz) )
@@ -13,4 +13,6 @@ interface IValidation
public function getValidationErrors();
public function validate();
public function addValidationError($errormsg);
}
@@ -0,0 +1,111 @@
<?php
namespace vertragsbestandteil;
use vertragsbestandteil\Vertragsbestandteil;
use vertragsbestandteil\VertragsbestandteilFreitext;
/**
* Description of OverlapChecker
*
* @author bambi
*/
class OverlapChecker
{
protected $CI;
/**
* @var Vertragsbestandteil_model
*/
protected $VertragsbestandteilModel;
/**
* @var VertragsbestandteilFreitext_model
*/
protected $VertragsbestandteilFreitextModel;
/**
* @var VertragsbestandteilTyp_model
*/
protected $VertragsbestandteilTypModel;
/**
* @var VertragsbestandteilFreitexttyp_model
*/
protected $VertragsbestandteilFreitexttypModel;
protected static $instance = null;
public static function getInstance()
{
if( null === self::$instance )
{
self::$instance = new OverlapChecker();
}
return self::$instance;
}
private function __construct()
{
$this->CI = get_instance();
$this->CI->load->model('vertragsbestandteil/Vertragsbestandteil_model',
'VertragsbestandteilModel');
$this->VertragsbestandteilModel = $this->CI->VertragsbestandteilModel;
$this->CI->load->model('vertragsbestandteil/VertragsbestandteilFreitext_model',
'VertragsbestandteilFreitextModel');
$this->VertragsbestandteilFreitextModel = $this->CI->VertragsbestandteilFreitextModel;
$this->CI->load->model('vertragsbestandteil/Vertragsbestandteiltyp_model',
'VertragsbestandteilTypModel');
$this->VertragsbestandteilTypModel = $this->CI->VertragsbestandteilTypModel;
$this->CI->load->model('vertragsbestandteil/VertragsbestandteilFreitexttyp_model',
'VertragsbestandteilFreitexttypModel');
$this->VertragsbestandteilFreitexttypModel = $this->CI->VertragsbestandteilFreitexttypModel;
}
public function overlapsVB(Vertragsbestandteil $vb)
{
$result = $this->VertragsbestandteilTypModel->load($vb->getVertragsbestandteiltyp_kurzbz());
if( null === ($vertragsbestandteiltyp = getData($result)) )
{
throw new Exception('vertragsbestandteiltyp: '
. $vb->getVertragsbestandteiltyp_kurzbz() . ' not found.');
}
if( true === $vertragsbestandteiltyp[0]->ueberlappend )
{
// vertragsbestandteiltyp can overlap
return false;
}
if( $this->VertragsbestandteilModel->countOverlappingVBsOfSameType($vb) === 0 )
{
return false;
}
else
{
return true;
}
}
public function overlapsFreitext(VertragsbestandteilFreitext $vbft)
{
$result = $this->VertragsbestandteilFreitexttypModel->load($vbft->getFreitexttypKurzbz());
if( null === ($vertragsbestandteilfreitexttyp = getData($result)) )
{
throw new Exception('vertragsbestandteilfreitexttyp: '
. $vbft->getFreitexttypKurzbz() . ' not found.');
}
if( true === $vertragsbestandteilfreitexttyp[0]->ueberlappend )
{
// freitexttyp can overlap
return false;
}
if( $this->VertragsbestandteilFreitextModel->countOverlappingVBFreitextsOfSameType($vbft) === 0 )
{
return false;
}
else
{
return true;
}
}
private function __clone() {}
}
@@ -8,7 +8,7 @@ use vertragsbestandteil\AbstractBestandteil;
*
* @author bambi
*/
abstract class Vertragsbestandteil extends AbstractBestandteil implements \JsonSerializable, IValidation
abstract class Vertragsbestandteil extends AbstractBestandteil implements \JsonSerializable
{
protected $vertragsbestandteil_id;
protected $dienstverhaeltnis_id;
@@ -21,16 +21,11 @@ abstract class Vertragsbestandteil extends AbstractBestandteil implements \JsonS
protected $updatevon;
protected $gehaltsbestandteile;
protected $isvalid;
protected $validationerrors;
public function __construct()
{
parent::__construct();
$this->gehaltsbestandteile = array();
$this->isvalid = false;
$this->validationerrors = array();
}
public function hydrateByStdClass($data, $fromdb=false)
@@ -237,16 +232,6 @@ EOTXT;
// can be overridden in childs
}
public function isValid()
{
return $this->isvalid;
}
public function getValidationErrors()
{
return $this->validationerrors;
}
public function validate() {
$von = \DateTimeImmutable::createFromFormat('Y-m-d', $this->von);
$bis = \DateTimeImmutable::createFromFormat('Y-m-d', $this->bis);
@@ -129,4 +129,6 @@ EOTXT;
return parent::validate();
}
}
@@ -11,6 +11,7 @@ require_once __DIR__ . '/VertragsbestandteilUrlaubsanspruch.php';
require_once __DIR__ . '/VertragsbestandteilFreitext.php';
require_once __DIR__ . '/VertragsbestandteilKarenz.php';
require_once __DIR__ . '/VertragsbestandteilFactory.php';
require_once __DIR__ . '/OverlapChecker.php';
use vertragsbestandteil\Dienstverhaeltnis;
use vertragsbestandteil\Vertragsbestandteil;