This commit is contained in:
DESKTOP-E17406D\boonkerz 2023-06-22 16:42:10 +02:00
parent 65e6e9699d
commit fbac716321
14 changed files with 228 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
}
},
"require": {
"php": ">=7.1",
"php": ">=8.1",
"doctrine/orm": "^2.5",
"azuyalabs/yasumi": "^2.5"
},

View File

@ -112,17 +112,21 @@ class Article
}
}
/**
* @return \ArrayIterator
*/
public function getOptions()
{
return $this->options;
}
/**
* @return array
*/
public function clearOptions(): void
{
$this->options = new \ArrayIterator();
}
public function setOptions(array $options): void
{
$this->options = new \ArrayIterator($options);
}
public function getValidOptions()
{
$temp = array();

View File

@ -100,7 +100,7 @@ class Valid
}
}else {
if ($this->engine->getVariables()[$option->getId()] == $opt->getId()) {
if (isset($this->engine->getVariables()[$option->getId()]) && $this->engine->getVariables()[$option->getId()] == $opt->getId()) {
if(!$opt->isValid()) {
$nextShouldBeValid = true;
} else {

View File

@ -283,29 +283,27 @@ class Engine
}
}
// Check if Option is valid
$calcValid = new Valid($this, $this->article);
$calcValid->perform();
$this->processCalc();
// CALC Values
$calcValues = new CalcValues($this, $this->article);
$calcValues->calc();
$switchedOptions = $this->checkDoubleOptions();
if(count($switchedOptions) > 0) {
foreach($switchedOptions as $option) {
if($option->getDefault() !== null && !$option instanceof Text) {
if($option instanceof Checkbox) {
$this->variables[$option->getId()] = explode(",", $option->getDefault());
}else{
$this->variables[$option->getId()] = $option->getDefault();
}
}
// Check if Option is valid
$calcValid = new Valid($this, $this->article);
$calcValid->perform();
if(isset($this->variables[$option->getId()])) {
$option->setRawValue($this->variables[$option->getId()]);
$option->processValue();
}
}
// CALC Values
$calcValues = new CalcValues($this, $this->article);
$calcValues->calc();
// Check if Option is valid
$calcValid = new Valid($this, $this->article);
$calcValid->perform(true);
// CALC Formel
$calcFormel = new Calc($this, $this->article);
$this->price = $calcFormel->calc();
$this->processCalc();
}
$this->dirty = false;
return true;
@ -578,4 +576,59 @@ class Engine
}
return $this->weightSingle;
}
private function checkDoubleOptions(): array
{
$options = [];
$switchedOptions = [];
/** @var Base $option */
foreach($this->article->getOptions() as $option) {
if($option->isValid()) {
$options[] = $option;
}else{
$foundValid = array_filter($this->article->getOptions()->getArrayCopy(), function(Base $elm) use ($option) {
if($elm->getId() == $option->getId() && $elm->isValid()) {
return $elm;
}
});
if(count($foundValid) == 0) {
$options[] = $option;
}else{
$switchedOptions[] = array_shift($foundValid);
}
}
}
$this->article->setOptions($options);
return $switchedOptions;
}
private function processCalc(): void
{
// Check if Option is valid
$calcValid = new Valid($this, $this->article);
$calcValid->perform();
// CALC Values
$calcValues = new CalcValues($this, $this->article);
$calcValues->calc();
// Check if Option is valid
$calcValid = new Valid($this, $this->article);
$calcValid->perform();
// CALC Values
$calcValues = new CalcValues($this, $this->article);
$calcValues->calc();
// Check if Option is valid
$calcValid = new Valid($this, $this->article);
$calcValid->perform(true);
// CALC Formel
$calcFormel = new Calc($this, $this->article);
$this->price = $calcFormel->calc();
}
}

View File

@ -25,6 +25,9 @@ class Base
if(isset($this->node['require'])) {
$this->element->setRequire($this->getBoolean($this->node['require']));
}
if(isset($this->node['required'])) {
$this->element->setRequire($this->getBoolean($this->node['required']));
}
if(isset($this->node['help'])) {
$this->element->setHelp((string)$this->node['help']);
}

View File

@ -26,6 +26,13 @@ class Input extends Base
$this->element->setMaxValue((int)$this->node['max']);
}
if(isset($this->node['pattern'])) {
$this->element->setPattern((string)$this->node['pattern']);
}
if(isset($this->node['placeholder'])) {
$this->element->setPlaceHolder((string)$this->node['placeholder']);
}
if($this->node->children()) {
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());

View File

@ -7,6 +7,10 @@ class Input extends Base
private ?int $maxValue = null;
private string $pattern = "";
private string $placeHolder = "";
public $type = 'input';
public function setMinValue(?int $min): void
@ -28,4 +32,24 @@ class Input extends Base
{
return $this->maxValue;
}
public function getPattern(): string
{
return $this->pattern;
}
public function setPattern(string $pattern): void
{
$this->pattern = $pattern;
}
public function getPlaceHolder(): string
{
return $this->placeHolder;
}
public function setPlaceHolder(string $placeHolder): void
{
$this->placeHolder = $placeHolder;
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace PSC\Library\Calc\Tests\Customer\BB;
use PHPUnit\Framework\TestCase;
use PSC\Library\Calc\Article;
use PSC\Library\Calc\Engine;
use PSC\Library\Calc\Option\Type\Select;
use PSC\Library\Calc\PaperContainer;
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
class CalcTest extends TestCase
{
/** @var Engine */
protected $engine = null;
public function setUp(): void
{
$repository = new PaperRepostory();
$paperContainer = new PaperContainer();
$paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ . '/papierContainer.xml')));
$this->engine = new Engine();
$this->engine->setPaperContainer($paperContainer);
$this->engine->setPaperRepository($repository);
$this->engine->setFormulas(file_get_contents(__DIR__ . '/formels.txt'));
$this->engine->setParameters(file_get_contents(__DIR__ . '/parameters.txt'));
$this->engine->setTemplates(file_get_contents(__DIR__ . '/calcTemplates.xml'));
$this->engine->loadString(file_get_contents(__DIR__ . '/calc.xml'));
}
public function tearDown(): void
{
$this->engine = null;
}
public function testPattern(): void
{
$this->engine->calc();
$this->assertEquals("[0-9]+", $this->engine->getArticle()->getOptionById('format1')->getPattern());
}
public function testPlaceHolder(): void
{
$this->engine->calc();
$this->assertEquals("Platzhalter", $this->engine->getArticle()->getOptionById('betreff')->getPlaceHolder());
$this->assertTrue($this->engine->getArticle()->getOptionById('betreff')->isRequire());
}
public function testFormat1(): void
{
$this->engine->calc();
$this->assertEquals(5 , $this->engine->getArticle()->getOptionById('format1')->getRawValue());
$this->assertTrue($this->engine->getArticle()->getOptionById('format1')->isValid());
}
public function testFormat2(): void
{
$this->engine->setVariable('auflage', 210);
$this->engine->calc();
$this->assertTrue($this->engine->getArticle()->getOptionById('format1')->isValid());
$this->assertEquals(50, $this->engine->getArticle()->getOptionById('format1')->getRawValue());
$this->assertEquals("format2" , $this->engine->getArticle()->getOptionById('format1')->getName());
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<kalkulation>
<artikel>
<name>Drahtspiralbindung</name>
<kommentar></kommentar>
<option id="auflage" name="Auflage" type="Input" default="100"></option>
<option id="betreff" name="Betreff" type="Input" required="1" placeholder="Platzhalter"></option>
<option id="test_select_req" name="Test Select Req" type="Select" required="1" empty_text="Bitte auswählen">
<opt id="2" label="Auswahl 2"></opt>
<opt id="3" label="Value 3"></opt>
</option>
<option id="format1" name="format1" type="Input" default="5" pattern="[0-9]+">
<auflage>
<grenze>1-200</grenze>
</auflage>
</option>
<option id="format1" name="format2" type="Input" default="50">
<auflage>
<grenze>201-</grenze>
</auflage>
</option>
</artikel>
<!-- Weitere Kalkulationselemente hier einfügen -->
</kalkulation>

View File

@ -0,0 +1,3 @@
<root>
</root>

View File

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<container>
</container>

View File