Add CalcValues1-10

This commit is contained in:
Thomas Peterson 2020-05-28 15:17:40 +02:00
parent 1bfb9cbd6f
commit b2c015a3b2
5 changed files with 395 additions and 45 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: thomas * User: thomas
@ -50,19 +51,18 @@ class CalcValues
$price = 0; $price = 0;
/** @var Base $option */ /** @var Base $option */
foreach($this->article->getOptions() as $option) { foreach ($this->article->getOptions() as $option) {
if($option instanceof Select) { if ($option instanceof Select) {
/** @var Select\Opt $opt */ /** @var Select\Opt $opt */
foreach($option->getOptions() as $opt) { foreach ($option->getOptions() as $opt) {
if($opt->isValid() && $opt->isSelected()) { if ($opt->isValid() && $opt->isSelected()) {
$price = $this->parseEdgeCollection($price, $option->getId(), $opt->getEdgesCollectionContainer()); $price = $this->parseEdgeCollection($price, $option->getId(), $opt->getEdgesCollectionContainer());
} }
} }
} }
$this->parseEdgeCollection($price, $option->getId(), $option->getEdgesCollectionContainer()); $this->parseEdgeCollection($price, $option->getId(), $option->getEdgesCollectionContainer());
} }
return $price; return $price;
@ -86,30 +86,29 @@ class CalcValues
eval($this->engine->getFormulas()); eval($this->engine->getFormulas());
/** @var EdgeCollection $collection */ /** @var EdgeCollection $collection */
foreach($container as $collection) { foreach ($container as $collection) {
if($collection->getName() == "opt") continue; if ($collection->getName() == "opt") continue;
if($collection->getFormel() != "") { if ($collection->getFormel() != "") {
$formel = $this->formelCalc->parse($collection->getFormel()); $formel = $this->formelCalc->parse($collection->getFormel());
if(preg_match("/^[a-z](.*)/", $formel)) { if (preg_match("/^[a-z](.*)/", $formel)) {
eval('$var = "' . $formel . '";'); eval('$var = "' . $formel . '";');
}else{ } else {
eval('$var = ' . $formel . ';'); eval('$var = ' . $formel . ';');
} }
} else {
}else{ if (!isset($this->engine->getVariables()[$collection->getName()])) {
if(!isset($this->engine->getVariables()[$collection->getName()])) {
$var = 'XXXXXXXX'; $var = 'XXXXXXXX';
}else{ } else {
$var = $this->engine->getVariables()[$collection->getName()]; $var = $this->engine->getVariables()[$collection->getName()];
} }
} }
/** @var Edge $edge */ /** @var Edge $edge */
foreach($collection as $edge) { foreach ($collection as $edge) {
if($edge->isValid($var)) { if ($edge->isValid($var)) {
if($edge->getCalcValue() != "") { if ($edge->getCalcValue() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue()); $cv = $this->formelCalc->parse($edge->getCalcValue());
eval('$cv = ' . $cv . ';'); eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL; //echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
@ -117,18 +116,104 @@ class CalcValues
$this->engine->addCalcVariable($id, $cv); $this->engine->addCalcVariable($id, $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName(), $cv); $this->engine->addCalcVariable($id . '_' . $collection->getName(), $cv);
} }
if($edge->getEdgesCollectionContainer()->count() > 0) { if ($edge->getCalcValue1() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue1());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_1', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_1', $cv);
}
if ($edge->getCalcValue2() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue2());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_2', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_2', $cv);
}
if ($edge->getCalcValue3() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue3());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_3', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_3', $cv);
}
if ($edge->getCalcValue4() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue4());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_4', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_4', $cv);
}
if ($edge->getCalcValue5() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue5());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_5', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_5', $cv);
}
if ($edge->getCalcValue6() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue6());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_6', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_6', $cv);
}
if ($edge->getCalcValue7() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue7());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_7', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_7', $cv);
}
if ($edge->getCalcValue8() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue8());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_8', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_8', $cv);
}
if ($edge->getCalcValue9() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue9());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_9', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_9', $cv);
}
if ($edge->getCalcValue10() != "") {
$cv = $this->formelCalc->parse($edge->getCalcValue10());
eval('$cv = ' . $cv . ';');
//echo $id . ' '. $this->formelCalc->parse($edge->getCalcValue()) . ' ' . $cv . ' '. PHP_EOL.PHP_EOL;
$this->engine->addCalcVariable($id . '_10', $cv);
$this->engine->addCalcVariable($id . '_' . $collection->getName() . '_10', $cv);
}
if ($edge->getEdgesCollectionContainer()->count() > 0) {
$this->parseEdgeCollection($price, $id . '_' . $collection->getName(), $edge->getEdgesCollectionContainer(), true); $this->parseEdgeCollection($price, $id . '_' . $collection->getName(), $edge->getEdgesCollectionContainer(), true);
} }
} }
} }
} }
return $price; return $price;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: thomas * User: thomas
@ -25,28 +26,58 @@ class Edge
public function parse() public function parse()
{ {
$edge = new \PSC\Library\Calc\General\Type\Edge(); $edge = new \PSC\Library\Calc\General\Type\Edge();
if(isset($this->node->attributes()->formel)) { if (isset($this->node->attributes()->formel)) {
$edge->setFormel((string)$this->node->attributes()->formel); $edge->setFormel((string) $this->node->attributes()->formel);
} }
if(isset($this->node->attributes()->calc_value)) { if (isset($this->node->attributes()->calc_value)) {
$edge->setCalcValue((string)$this->node->attributes()->calc_value); $edge->setCalcValue((string) $this->node->attributes()->calc_value);
} }
if(isset($this->node->attributes()->preis)) { if (isset($this->node->attributes()->calc_value_1)) {
$edge->setCalcValue1((string) $this->node->attributes()->calc_value_1);
}
if (isset($this->node->attributes()->calc_value_2)) {
$edge->setCalcValue2((string) $this->node->attributes()->calc_value_2);
}
if (isset($this->node->attributes()->calc_value_3)) {
$edge->setCalcValue3((string) $this->node->attributes()->calc_value_3);
}
if (isset($this->node->attributes()->calc_value_4)) {
$edge->setCalcValue4((string) $this->node->attributes()->calc_value_4);
}
if (isset($this->node->attributes()->calc_value_5)) {
$edge->setCalcValue5((string) $this->node->attributes()->calc_value_5);
}
if (isset($this->node->attributes()->calc_value_6)) {
$edge->setCalcValue6((string) $this->node->attributes()->calc_value_6);
}
if (isset($this->node->attributes()->calc_value_7)) {
$edge->setCalcValue7((string) $this->node->attributes()->calc_value_7);
}
if (isset($this->node->attributes()->calc_value_8)) {
$edge->setCalcValue8((string) $this->node->attributes()->calc_value_8);
}
if (isset($this->node->attributes()->calc_value_9)) {
$edge->setCalcValue9((string) $this->node->attributes()->calc_value_9);
}
if (isset($this->node->attributes()->calc_value_10)) {
$edge->setCalcValue10((string) $this->node->attributes()->calc_value_10);
}
if (isset($this->node->attributes()->preis)) {
$edge->setPreis(floatval($this->node->attributes()->preis)); $edge->setPreis(floatval($this->node->attributes()->preis));
} }
if(isset($this->node->attributes()->pauschale)) { if (isset($this->node->attributes()->pauschale)) {
$edge->setPauschale(floatval($this->node->attributes()->pauschale)); $edge->setPauschale(floatval($this->node->attributes()->pauschale));
} }
if(isset($this->node->attributes()->value) && $this->node->children()) { if (isset($this->node->attributes()->value) && $this->node->children()) {
$edge->setValues(explode(",", trim((string)$this->node->attributes()->value))); $edge->setValues(explode(",", trim((string) $this->node->attributes()->value)));
if($this->node->children()) { if ($this->node->children()) {
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node); $edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
$edge->setEdgesCollectionContainer($edgeCollectionContainerParser->parse()); $edge->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
} }
}else { } else {
$value = (string)$this->node; $value = (string) $this->node;
if (preg_match("/^([0-9a-zA-Z_]+)$/", trim($value), $regs)) { if (preg_match("/^([0-9a-zA-Z_]+)$/", trim($value), $regs)) {
$edge->setValues([$regs[1]]); $edge->setValues([$regs[1]]);
} elseif (preg_match("/^([0-9]+)-([0-9]+)$/", trim($value), $regs)) { } elseif (preg_match("/^([0-9]+)-([0-9]+)$/", trim($value), $regs)) {
@ -65,4 +96,3 @@ class Edge
return $edge; return $edge;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace PSC\Library\Calc\General\Type; namespace PSC\Library\Calc\General\Type;
class Edge class Edge
@ -8,6 +9,17 @@ class Edge
protected $preis = 0; protected $preis = 0;
protected $calcValue = ''; protected $calcValue = '';
protected $calcValue1 = '';
protected $calcValue2 = '';
protected $calcValue3 = '';
protected $calcValue4 = '';
protected $calcValue5 = '';
protected $calcValue6 = '';
protected $calcValue7 = '';
protected $calcValue8 = '';
protected $calcValue9 = '';
protected $calcValue10 = '';
protected $from = 0; protected $from = 0;
protected $to = 0; protected $to = 0;
protected $values = []; protected $values = [];
@ -86,6 +98,166 @@ class Edge
$this->calcValue = $calcValue; $this->calcValue = $calcValue;
} }
/**
* @return string
*/
public function getCalcValue1()
{
return $this->calcValue1;
}
/**
* @param string $calcValue1
*/
public function setCalcValue1($calcValue1)
{
$this->calcValue1 = $calcValue1;
}
/**
* @return string
*/
public function getCalcValue2()
{
return $this->calcValue2;
}
/**
* @param string $calcValue2
*/
public function setCalcValue2($calcValue2)
{
$this->calcValue2 = $calcValue2;
}
/**
* @return string
*/
public function getCalcValue3()
{
return $this->calcValue3;
}
/**
* @param string $calcValue3
*/
public function setCalcValue3($calcValue3)
{
$this->calcValue3 = $calcValue3;
}
/**
* @return string
*/
public function getCalcValue4()
{
return $this->calcValue4;
}
/**
* @param string $calcValue4
*/
public function setCalcValue4($calcValue4)
{
$this->calcValue4 = $calcValue4;
}
/**
* @return string
*/
public function getCalcValue5()
{
return $this->calcValue5;
}
/**
* @param string $calcValue5
*/
public function setCalcValue5($calcValue5)
{
$this->calcValue5 = $calcValue5;
}
/**
* @return string
*/
public function getCalcValue6()
{
return $this->calcValue6;
}
/**
* @param string $calcValue6
*/
public function setCalcValue6($calcValue6)
{
$this->calcValue6 = $calcValue6;
}
/**
* @return string
*/
public function getCalcValue7()
{
return $this->calcValue7;
}
/**
* @param string $calcValue7
*/
public function setCalcValue7($calcValue7)
{
$this->calcValue7 = $calcValue7;
}
/**
* @return string
*/
public function getCalcValue8()
{
return $this->calcValue8;
}
/**
* @param string $calcValue8
*/
public function setCalcValue8($calcValue8)
{
$this->calcValue8 = $calcValue8;
}
/**
* @return string
*/
public function getCalcValue9()
{
return $this->calcValue9;
}
/**
* @param string $calcValue9
*/
public function setCalcValue9($calcValue9)
{
$this->calcValue9 = $calcValue9;
}
/**
* @return string
*/
public function getCalcValue10()
{
return $this->calcValue10;
}
/**
* @param string $calcValue10
*/
public function setCalcValue10($calcValue10)
{
$this->calcValue10 = $calcValue10;
}
/** /**
* @return int * @return int
*/ */
@ -158,30 +330,33 @@ class Edge
public function isValid($value) public function isValid($value)
{ {
if($this->isRegion() && if (
$this->isRegion() &&
$this->getFrom() <= $value && $this->getFrom() <= $value &&
$this->getTo() >= $value) { $this->getTo() >= $value
) {
return true; return true;
} }
if($this->isRegion() && if (
$this->isRegion() &&
$this->getFrom() <= $value && $this->getFrom() <= $value &&
$this->getTo() == 0) { $this->getTo() == 0
) {
return true; return true;
} }
if(!$this->isRegion() && in_array($value, $this->getValues())) { if (!$this->isRegion() && in_array($value, $this->getValues())) {
return true; return true;
} }
$values = $this->getValues(); $values = $this->getValues();
if(is_array($values)) { if (is_array($values)) {
foreach($values as $val) { foreach ($values as $val) {
if (( if ((
(preg_match("/^([0-9]+)-([0-9]+)$/", trim($val), $regs) && ($value >= $regs [1] && $value <= $regs [2])) || (preg_match("/^([0-9]+)-([0-9]+)$/", trim($val), $regs) && ($value >= $regs[1] && $value <= $regs[2])) ||
(preg_match("/^([0-9]+)-$/", trim($val), $regs) && $value >= $regs [1])) (preg_match("/^([0-9]+)-$/", trim($val), $regs) && $value >= $regs[1]))) {
) {
return true; return true;
} }
} }
@ -205,4 +380,5 @@ class Edge
{ {
$this->edgesCollectionContainer = $edgesCollectionContainer; $this->edgesCollectionContainer = $edgesCollectionContainer;
} }
} }

View File

@ -0,0 +1,29 @@
<?php
namespace PSC\Library\Calc\Tests\CalcValue;
use PSC\Library\Calc\Engine;
use PSC\Library\Calc\PaperContainer\Container;
class AddCalcValuesTest extends \PHPUnit_Framework_TestCase
{
/** @var Engine */
protected $engine = null;
public function setUp()
{
$this->engine = new Engine(new Container());
$this->engine->loadString(file_get_contents(__DIR__ . '/../TestFiles/CalcValue/addcalcvalues.xml'));
}
public function tearDown()
{
$this->engine = null;
}
public function testIfParseValue()
{
$this->assertEquals(85, $this->engine->getPrice());
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<kalkulation>
<artikel>
<name>simple</name>
<kommentar>simple</kommentar>
<option id="auflage" name="Auflagenhöhe" type="Input" default="100" min="1" max="4000" require="true" />
<option id="gebyn" name="Benutzen Sie ein eigenes Gebäude?" type="Select" default="1">
<opt id="1" name="Ja">
<auflage>
<grenze calc_value="(20)" calc_value_1="(2)" calc_value_2="(3)" calc_value_3="(4)" calc_value_4="(5)" calc_value_5="(6)" calc_value_6="(7)" calc_value_7="(8)" calc_value_8="(9)" calc_value_9="(10)" calc_value_10="(11)">1-</grenze>
</auflage>
</opt>
<opt id="2" name="Nein">
<auflage>
<grenze calc_value="(1)" calc_value_1="(2)" calc_value_2="(3)" calc_value_3="(4)" calc_value_4="(5)" calc_value_5="(6)" calc_value_6="(7)" calc_value_7="(8)" calc_value_8="(9)" calc_value_9="(10)" calc_value_10="(11)">1-</grenze>
</auflage>
</opt>
</option>
<option id="calc" name="calc" type="Hidden" default="1">
<auflage>
<grenze formel="$CVgebyn_auflage$CV+$CVgebyn_auflage_1$CV+$CVgebyn_auflage_2$CV+$CVgebyn_auflage_3$CV+$CVgebyn_auflage_4$CV+$CVgebyn_auflage_5$CV+$CVgebyn_auflage_6$CV+$CVgebyn_auflage_7$CV+$CVgebyn_auflage_8$CV+$CVgebyn_auflage_9$CV+$CVgebyn_auflage_10$CV">1-</grenze>
</auflage>
</option>
</artikel>
</kalkulation>