Faster
This commit is contained in:
parent
bb8424cc60
commit
3ab2cbae60
File diff suppressed because one or more lines are too long
@ -54,8 +54,10 @@ class Calc
|
|||||||
foreach ($this->article->getOptions() as $option) {
|
foreach ($this->article->getOptions() as $option) {
|
||||||
|
|
||||||
if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) {
|
if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) {
|
||||||
if ($option->getSelectedOption() != null && $option->getSelectedOption()->isValid()) {
|
foreach($option->getSelectedOptions() as $opt) {
|
||||||
$gesamt = $this->parseEdgeCollection($gesamt, $option, $option->getSelectedOption()->getEdgesCollectionContainer(), [$option->getId()]);
|
if ($opt->isValid()) {
|
||||||
|
$gesamt = $this->parseEdgeCollection($gesamt, $option, $opt->getEdgesCollectionContainer(), [$option->getId()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,8 +55,10 @@ class CalcValues
|
|||||||
foreach ($this->article->getOptions() as $option) {
|
foreach ($this->article->getOptions() as $option) {
|
||||||
|
|
||||||
if ($option instanceof Select || $option instanceof Checkbox) {
|
if ($option instanceof Select || $option instanceof Checkbox) {
|
||||||
if ($option->getSelectedOption() != null && $option->getSelectedOption()->isValid()) {
|
foreach($option->getSelectedOptions() as $opt) {
|
||||||
$price = $this->parseEdgeCollection($price, $option->getId(), $option->getSelectedOption()->getEdgesCollectionContainer());
|
if ($opt->isValid()) {
|
||||||
|
$price = $this->parseEdgeCollection($price, $option->getId(), $opt->getEdgesCollectionContainer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class Valid
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
$nextShouldBeValid = false;
|
$nextShouldBeValid = false;
|
||||||
$isDefaultValid = true;
|
$isDefaultValid = true;
|
||||||
$option->setSelectedOption(null);
|
$option->clearSelected();
|
||||||
/** @var Select\Opt $opt */
|
/** @var Select\Opt $opt */
|
||||||
foreach ($option->getOptions() as $opt) {
|
foreach ($option->getOptions() as $opt) {
|
||||||
if(count($opt->getEdgesCollectionContainer()) > 0) {
|
if(count($opt->getEdgesCollectionContainer()) > 0) {
|
||||||
@ -114,9 +114,9 @@ class Valid
|
|||||||
|
|
||||||
if($option instanceof Checkbox) {
|
if($option instanceof Checkbox) {
|
||||||
if (isset($this->engine->getVariables()[$option->getId()]) && is_array($this->engine->getVariables()[$option->getId()]) && in_array($opt->getId(), $this->engine->getVariables()[$option->getId()])) {
|
if (isset($this->engine->getVariables()[$option->getId()]) && is_array($this->engine->getVariables()[$option->getId()]) && in_array($opt->getId(), $this->engine->getVariables()[$option->getId()])) {
|
||||||
$opt->setIsSelected(true);
|
$option->addSelectedOption($opt);
|
||||||
} else {
|
} else {
|
||||||
$opt->setIsSelected(false);
|
//$opt->setIsSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
@ -124,16 +124,16 @@ class Valid
|
|||||||
if(!$opt->isValid()) {
|
if(!$opt->isValid()) {
|
||||||
$nextShouldBeValid = true;
|
$nextShouldBeValid = true;
|
||||||
} else {
|
} else {
|
||||||
$option->setSelectedOption($opt);
|
$option->addSelectedOption($opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if($nextShouldBeValid && $opt->isValid()) {
|
if($nextShouldBeValid && $opt->isValid()) {
|
||||||
$this->engine->getVariables()[$option->getId()] = $opt->getId();
|
$this->engine->getVariables()[$option->getId()] = $opt->getId();
|
||||||
$option->setSelectedOption($opt);
|
$option->addSelectedOption($opt);
|
||||||
$nextShouldBeValid = false;
|
$nextShouldBeValid = false;
|
||||||
} else{
|
} else{
|
||||||
$option->setSelectedOption(null);
|
// $option->setSelectedOption(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ class Valid
|
|||||||
if($nextShouldBeValid) {
|
if($nextShouldBeValid) {
|
||||||
foreach($option->getOptions() as $opt) {
|
foreach($option->getOptions() as $opt) {
|
||||||
if($opt->isValid()) {
|
if($opt->isValid()) {
|
||||||
$option->setSelectedOption($opt);
|
$option->addSelectedOption($opt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -633,12 +633,12 @@ class Engine
|
|||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $calcValid = new Valid($this, $this->article);
|
$calcValid = new Valid($this, $this->article);
|
||||||
// $calcValid->perform();
|
$calcValid->perform();
|
||||||
|
|
||||||
// CALC Values
|
// CALC Values
|
||||||
// $calcValues = new CalcValues($this, $this->article);
|
$calcValues = new CalcValues($this, $this->article);
|
||||||
// $calcValues->calc();
|
$calcValues->calc();
|
||||||
|
|
||||||
// Check if Option is valid
|
// Check if Option is valid
|
||||||
// CALC Formel
|
// CALC Formel
|
||||||
|
|||||||
@ -3,7 +3,7 @@ namespace PSC\Library\Calc\Option\Parser;
|
|||||||
|
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||||
use PSC\Library\Calc\Option\Parser\Select\Opt;
|
use PSC\Library\Calc\Option\Parser\Radio\Opt;
|
||||||
use PSC\Library\Calc\PaperContainer;
|
use PSC\Library\Calc\PaperContainer;
|
||||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace PSC\Library\Calc\Option\Type;
|
namespace PSC\Library\Calc\Option\Type;
|
||||||
|
|
||||||
use PSC\Library\Calc\Option\Type\Select\Opt;
|
use ArrayIterator;
|
||||||
|
use PSC\Library\Calc\Option\Type\Checkbox\Opt;
|
||||||
|
|
||||||
class Checkbox extends Base
|
class Checkbox extends Base
|
||||||
{
|
{
|
||||||
@ -11,10 +12,13 @@ class Checkbox extends Base
|
|||||||
/** @var \ArrayIterator $options */
|
/** @var \ArrayIterator $options */
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|
||||||
|
protected \ArrayIterator $selectedOptions;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->options = new \ArrayIterator();
|
$this->options = new \ArrayIterator();
|
||||||
|
$this->selectedOptions = new \ArrayIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addOption($option)
|
public function addOption($option)
|
||||||
@ -27,18 +31,19 @@ class Checkbox extends Base
|
|||||||
*/
|
*/
|
||||||
public function processValue()
|
public function processValue()
|
||||||
{
|
{
|
||||||
|
$this->selectedOptions = new \ArrayIterator();
|
||||||
if(is_array($this->rawValue)) {
|
if(is_array($this->rawValue)) {
|
||||||
/** @var \PSC\Library\Calc\Option\Type\Checkbox\Opt $item */
|
/** @var \PSC\Library\Calc\Option\Type\Checkbox\Opt $item */
|
||||||
foreach($this->options as $item) {
|
foreach($this->options as $item) {
|
||||||
if(in_array($item->getId(), $this->rawValue)) {
|
if(in_array($item->getId(), $this->rawValue)) {
|
||||||
$item->setIsSelected(true);
|
$this->selectedOptions->append($item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}elseif($this->rawValue != "") {
|
}elseif($this->rawValue != "") {
|
||||||
/** @var \PSC\Library\Calc\Option\Type\Checkbox\Opt $item */
|
/** @var \PSC\Library\Calc\Option\Type\Checkbox\Opt $item */
|
||||||
foreach($this->options as $item) {
|
foreach($this->options as $item) {
|
||||||
if($item->getId() == $this->rawValue) {
|
if($item->getId() == $this->rawValue) {
|
||||||
$item->setIsSelected(true);
|
$this->selectedOptions->append($item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,22 +57,25 @@ class Checkbox extends Base
|
|||||||
return $this->options;
|
return $this->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSelectedOptions()
|
public function clearSelected(): void
|
||||||
{
|
{
|
||||||
$tmp = [];
|
$this->selectedOptions = new ArrayIterator();
|
||||||
|
}
|
||||||
/** @var Opt $opt */
|
public function addSelectedOption(Opt $opt): void
|
||||||
foreach($this->getOptions() as $opt) {
|
{
|
||||||
if($opt->isSelected()) $tmp[] = $opt;
|
$this->selectedOptions->append($opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tmp;
|
|
||||||
|
public function getSelectedOptions()
|
||||||
|
{
|
||||||
|
return $this->selectedOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue()
|
public function getValue()
|
||||||
{
|
{
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
foreach($this->getSelectedOptions() as $option) {
|
foreach($this->selectedOptions as $option) {
|
||||||
$tmp[] = $option->getLabel();
|
$tmp[] = $option->getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,110 +3,8 @@ namespace PSC\Library\Calc\Option\Type\Checkbox;
|
|||||||
|
|
||||||
use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
|
use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
|
||||||
use PSC\Library\Calc\Option\Type\Base;
|
use PSC\Library\Calc\Option\Type\Base;
|
||||||
|
use PSC\Library\Calc\Option\Type\Select\Opt as PSCOpt;
|
||||||
|
|
||||||
class Opt
|
class Opt extends PSCOpt
|
||||||
{
|
{
|
||||||
/** @var string $id */
|
|
||||||
protected $id;
|
|
||||||
|
|
||||||
/** @var string $label */
|
|
||||||
protected $label;
|
|
||||||
|
|
||||||
/** @var EdgeCollectionContainer */
|
|
||||||
protected $edgesCollectionContainer;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
protected $isValid = true;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
protected $isSelected = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opt constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->edgesCollectionContainer = new EdgeCollectionContainer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $id
|
|
||||||
*/
|
|
||||||
public function setId($id)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getLabel()
|
|
||||||
{
|
|
||||||
return $this->label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $label
|
|
||||||
*/
|
|
||||||
public function setLabel($label)
|
|
||||||
{
|
|
||||||
$this->label = $label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return EdgeCollectionContainer
|
|
||||||
*/
|
|
||||||
public function getEdgesCollectionContainer()
|
|
||||||
{
|
|
||||||
return $this->edgesCollectionContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EdgeCollectionContainer $edgesCollectionContainer
|
|
||||||
*/
|
|
||||||
public function setEdgesCollectionContainer($edgesCollectionContainer)
|
|
||||||
{
|
|
||||||
$this->edgesCollectionContainer = $edgesCollectionContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid()
|
|
||||||
{
|
|
||||||
return $this->isValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $isValid
|
|
||||||
*/
|
|
||||||
public function setIsValid($isValid)
|
|
||||||
{
|
|
||||||
$this->isValid = $isValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isSelected()
|
|
||||||
{
|
|
||||||
return $this->isSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $isSelected
|
|
||||||
*/
|
|
||||||
public function setIsSelected($isSelected)
|
|
||||||
{
|
|
||||||
$this->isSelected = $isSelected;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,18 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace PSC\Library\Calc\Option\Type;
|
namespace PSC\Library\Calc\Option\Type;
|
||||||
|
|
||||||
use PSC\Library\Calc\Option\Type\Select\Opt;
|
|
||||||
use PSC\Library\Calc\Option\Type\Select\PaperOpt;
|
|
||||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
|
||||||
|
|
||||||
class DeliverySelect extends Select
|
class DeliverySelect extends Select
|
||||||
{
|
{
|
||||||
public function getSelectedOption()
|
|
||||||
{
|
|
||||||
/** @var Opt $opt */
|
|
||||||
foreach($this->getOptions() as $opt) {
|
|
||||||
if($opt->isSelected()) return $opt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -12,8 +12,8 @@ class PaperDbSelect extends Select
|
|||||||
public function getSelectedOption(): ?Opt
|
public function getSelectedOption(): ?Opt
|
||||||
{
|
{
|
||||||
|
|
||||||
if($this->selectedOption != null) {
|
if(count($this->selectedOptions) > 0) {
|
||||||
return $this->selectedOption;
|
return $this->selectedOptions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($this->savedCalcValues[$this->getId()]) && $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()) {
|
if(isset($this->savedCalcValues[$this->getId()]) && $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()) {
|
||||||
@ -21,7 +21,7 @@ class PaperDbSelect extends Select
|
|||||||
$opt->setId($this->savedCalcValues[$this->getId()]['art_nr']);
|
$opt->setId($this->savedCalcValues[$this->getId()]['art_nr']);
|
||||||
$opt->setLabel($this->savedCalcValues[$this->getId()]['description_1']);
|
$opt->setLabel($this->savedCalcValues[$this->getId()]['description_1']);
|
||||||
|
|
||||||
$this->setSelectedOption($opt);
|
$this->addSelectedOption($opt);
|
||||||
$paper = $this->newPaperObject;
|
$paper = $this->newPaperObject;
|
||||||
$paper->setId($this->savedCalcValues[$this->getId()]['id']);
|
$paper->setId($this->savedCalcValues[$this->getId()]['id']);
|
||||||
$paper->setArtNr($this->savedCalcValues[$this->getId()]['art_nr']);
|
$paper->setArtNr($this->savedCalcValues[$this->getId()]['art_nr']);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace PSC\Library\Calc\Option\Type;
|
namespace PSC\Library\Calc\Option\Type;
|
||||||
|
|
||||||
use PSC\Library\Calc\Option\Type\Select\Opt;
|
use PSC\Library\Calc\Option\Type\Radio\Opt;
|
||||||
|
|
||||||
class Radio extends Base
|
class Radio extends Base
|
||||||
{
|
{
|
||||||
@ -11,10 +11,13 @@ class Radio extends Base
|
|||||||
/** @var \ArrayIterator $options */
|
/** @var \ArrayIterator $options */
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|
||||||
|
protected \ArrayIterator $selectedOptions;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->options = new \ArrayIterator();
|
$this->options = new \ArrayIterator();
|
||||||
|
$this->selectedOptions = new \ArrayIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addOption($option)
|
public function addOption($option)
|
||||||
@ -27,11 +30,19 @@ class Radio extends Base
|
|||||||
*/
|
*/
|
||||||
public function processValue()
|
public function processValue()
|
||||||
{
|
{
|
||||||
if($this->rawValue != "") {
|
$this->selectedOptions = new \ArrayIterator();
|
||||||
/** @var \PSC\Library\Calc\Option\Type\Radio\Opt $item */
|
if(is_array($this->rawValue)) {
|
||||||
|
/** @var \PSC\Library\Calc\Option\Type\Checkbox\Opt $item */
|
||||||
|
foreach($this->options as $item) {
|
||||||
|
if(in_array($item->getId(), $this->rawValue)) {
|
||||||
|
$this->selectedOptions->append($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}elseif($this->rawValue != "") {
|
||||||
|
/** @var \PSC\Library\Calc\Option\Type\Checkbox\Opt $item */
|
||||||
foreach($this->options as $item) {
|
foreach($this->options as $item) {
|
||||||
if($item->getId() == $this->rawValue) {
|
if($item->getId() == $this->rawValue) {
|
||||||
$item->setIsSelected(true);
|
$this->selectedOptions->append($item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,17 +56,33 @@ class Radio extends Base
|
|||||||
return $this->options;
|
return $this->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSelectedOption()
|
public function clearSelected(): void
|
||||||
{
|
{
|
||||||
/** @var Opt $opt */
|
$this->selectedOptions = new ArrayIterator();
|
||||||
foreach($this->getOptions() as $opt) {
|
|
||||||
if($opt->isSelected()) return $opt;
|
|
||||||
}
|
}
|
||||||
|
public function addSelectedOption(Opt $opt): void
|
||||||
|
{
|
||||||
|
$this->selectedOptions->append($opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSelectedOption(): ?Opt
|
||||||
|
{
|
||||||
|
return $this->selectedOptions[0]?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSelectedOptions()
|
||||||
|
{
|
||||||
|
return $this->selectedOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue()
|
public function getValue()
|
||||||
{
|
{
|
||||||
return $this->getSelectedOption()->getLabel();
|
$tmp = array();
|
||||||
|
foreach($this->selectedOptions as $option) {
|
||||||
|
$tmp[] = $option->getLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(", ", $tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,110 +3,8 @@ namespace PSC\Library\Calc\Option\Type\Radio;
|
|||||||
|
|
||||||
use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
|
use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
|
||||||
use PSC\Library\Calc\Option\Type\Base;
|
use PSC\Library\Calc\Option\Type\Base;
|
||||||
|
use PSC\Library\Calc\Option\Type\Select\Opt as PSCOpt;
|
||||||
|
|
||||||
class Opt
|
class Opt extends PSCOpt
|
||||||
{
|
{
|
||||||
/** @var string $id */
|
|
||||||
protected $id;
|
|
||||||
|
|
||||||
/** @var string $label */
|
|
||||||
protected $label;
|
|
||||||
|
|
||||||
/** @var EdgeCollectionContainer */
|
|
||||||
protected $edgesCollectionContainer;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
protected $isValid = true;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
protected $isSelected = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opt constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->edgesCollectionContainer = new EdgeCollectionContainer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $id
|
|
||||||
*/
|
|
||||||
public function setId($id)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getLabel()
|
|
||||||
{
|
|
||||||
return $this->label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $label
|
|
||||||
*/
|
|
||||||
public function setLabel($label)
|
|
||||||
{
|
|
||||||
$this->label = $label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return EdgeCollectionContainer
|
|
||||||
*/
|
|
||||||
public function getEdgesCollectionContainer()
|
|
||||||
{
|
|
||||||
return $this->edgesCollectionContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EdgeCollectionContainer $edgesCollectionContainer
|
|
||||||
*/
|
|
||||||
public function setEdgesCollectionContainer($edgesCollectionContainer)
|
|
||||||
{
|
|
||||||
$this->edgesCollectionContainer = $edgesCollectionContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid()
|
|
||||||
{
|
|
||||||
return $this->isValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $isValid
|
|
||||||
*/
|
|
||||||
public function setIsValid($isValid)
|
|
||||||
{
|
|
||||||
$this->isValid = $isValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isSelected()
|
|
||||||
{
|
|
||||||
return $this->isSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $isSelected
|
|
||||||
*/
|
|
||||||
public function setIsSelected($isSelected)
|
|
||||||
{
|
|
||||||
$this->isSelected = $isSelected;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -17,7 +17,7 @@ class Select extends Base
|
|||||||
/** @var \ArrayIterator $options */
|
/** @var \ArrayIterator $options */
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|
||||||
protected ?Opt $selectedOption = null;
|
protected \ArrayIterator $selectedOptions;
|
||||||
|
|
||||||
/** @var String $container */
|
/** @var String $container */
|
||||||
protected $container = '';
|
protected $container = '';
|
||||||
@ -29,6 +29,7 @@ class Select extends Base
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->options = new \ArrayIterator();
|
$this->options = new \ArrayIterator();
|
||||||
|
$this->selectedOptions = new \ArrayIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addOption($option)
|
public function addOption($option)
|
||||||
@ -47,7 +48,7 @@ class Select extends Base
|
|||||||
*/
|
*/
|
||||||
public function processValue()
|
public function processValue()
|
||||||
{
|
{
|
||||||
$option = $this->getSelectedOption();
|
$option = $this->getSelectedOptions()[0]??null;
|
||||||
if($option) {
|
if($option) {
|
||||||
$this->setValue($option->getLabel());
|
$this->setValue($option->getLabel());
|
||||||
$this->setRawValue($option->getId());
|
$this->setRawValue($option->getId());
|
||||||
@ -94,14 +95,24 @@ class Select extends Base
|
|||||||
return $this->options;
|
return $this->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSelectedOption(): ?Opt
|
public function clearSelected(): void
|
||||||
{
|
{
|
||||||
return $this->selectedOption;
|
$this->selectedOptions = new \ArrayIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSelectedOption(?Opt $opt): void
|
public function getSelectedOptions(): \ArrayIterator
|
||||||
{
|
{
|
||||||
$this->selectedOption = $opt;
|
return $this->selectedOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSelectedOption(): ?Opt
|
||||||
|
{
|
||||||
|
return $this->selectedOptions[0]?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSelectedOption(?Opt $opt): void
|
||||||
|
{
|
||||||
|
$this->selectedOptions->append($opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValidOptions()
|
public function getValidOptions()
|
||||||
|
|||||||
@ -53,11 +53,10 @@ class CalcTest extends TestCase
|
|||||||
|
|
||||||
public function testOptionCheckbox(): void
|
public function testOptionCheckbox(): void
|
||||||
{
|
{
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen2')->getOptions()[0]->isSelected());
|
self::assertCount(2, $this->engine->getArticle()->getOptionById('checkboxen2')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen2')->getOptions()[1]->isSelected());
|
|
||||||
|
|
||||||
self::assertFalse($this->engine->getArticle()->getOptionById('checkboxen3')->getOptions()[0]->isSelected());
|
self::assertCount(1, $this->engine->getArticle()->getOptionById('checkboxen3')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen3')->getOptions()[1]->isSelected());
|
self::assertSame('2', $this->engine->getArticle()->getOptionById('checkboxen3')->getSelectedOptions()[0]->getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +64,10 @@ class CalcTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->engine->setVariable('checkboxen1', [1,2]);
|
$this->engine->setVariable('checkboxen1', [1,2]);
|
||||||
$this->engine->calc();
|
$this->engine->calc();
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[0]->isSelected());
|
self::assertCount(2, $this->engine->getArticle()->getOptionById('checkboxen1')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[1]->isSelected());
|
|
||||||
$this->engine->setVariable('checkboxen1', [2]);
|
$this->engine->setVariable('checkboxen1', [2]);
|
||||||
self::assertFalse($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[0]->isSelected());
|
self::assertCount(1, $this->engine->getArticle()->getOptionById('checkboxen1')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[1]->isSelected());
|
self::assertSame('2', $this->engine->getArticle()->getOptionById('checkboxen1')->getSelectedOptions()[0]->getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,15 +42,16 @@ class CheckboxTest extends TestCase
|
|||||||
public function testCalcDefault(): void
|
public function testCalcDefault(): void
|
||||||
{
|
{
|
||||||
self::assertSame(26.0, $this->engine->getPrice());
|
self::assertSame(26.0, $this->engine->getPrice());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[0]->isSelected());
|
self::assertCount(2, $this->engine->getArticle()->getOptionById('checkbox')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[1]->isSelected());
|
self::assertSame('1', $this->engine->getArticle()->getOptionById('checkbox')->getSelectedOptions()[0]->getId());
|
||||||
|
self::assertSame('2', $this->engine->getArticle()->getOptionById('checkbox')->getSelectedOptions()[1]->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCalcOnly2(): void
|
public function testCalcOnly2(): void
|
||||||
{
|
{
|
||||||
$this->engine->setVariable('checkbox', [2]);
|
$this->engine->setVariable('checkbox', [2]);
|
||||||
self::assertSame(14.0, $this->engine->getPrice());
|
self::assertSame(14.0, $this->engine->getPrice());
|
||||||
self::assertFalse($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[0]->isSelected());
|
self::assertCount(1, $this->engine->getArticle()->getOptionById('checkbox')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[1]->isSelected());
|
self::assertSame('2', $this->engine->getArticle()->getOptionById('checkbox')->getSelectedOptions()[0]->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,16 +41,16 @@ class RadioboxTest extends TestCase
|
|||||||
|
|
||||||
public function testCalcDefault(): void
|
public function testCalcDefault(): void
|
||||||
{
|
{
|
||||||
$this->assertSame(12.0, $this->engine->getPrice());
|
self::assertSame(12.0, $this->engine->getPrice());
|
||||||
self::assertFalse($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[1]->isSelected());
|
self::assertCount(1, $this->engine->getArticle()->getOptionById('radiobox')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[0]->isSelected());
|
self::assertSame('1', $this->engine->getArticle()->getOptionById('radiobox')->getSelectedOption()->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCalcOnly2(): void
|
public function testCalcOnly2(): void
|
||||||
{
|
{
|
||||||
$this->engine->setVariable('radiobox', 2);
|
$this->engine->setVariable('radiobox', 2);
|
||||||
$this->assertSame(14.0, $this->engine->getPrice());
|
$this->assertSame(14.0, $this->engine->getPrice());
|
||||||
self::assertFalse($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[0]->isSelected());
|
self::assertCount(1, $this->engine->getArticle()->getOptionById('radiobox')->getSelectedOptions());
|
||||||
self::assertTrue($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[1]->isSelected());
|
self::assertSame('2', $this->engine->getArticle()->getOptionById('radiobox')->getSelectedOption()->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ class selectWithGrenzenTest extends TestCase
|
|||||||
|
|
||||||
$this->assertCount(6, $article->getOptionsAsArray());
|
$this->assertCount(6, $article->getOptionsAsArray());
|
||||||
|
|
||||||
$this->assertInstanceOf('\PSC\Library\Calc\Option\Type\Select\Opt', $article->getOptionById('umschlag')->getSelectedOption());
|
$this->assertInstanceOf('\PSC\Library\Calc\Option\Type\Select\Opt', $article->getOptionById('umschlag')->getSelectedOptions()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user