Refactor SetSelected
This commit is contained in:
parent
63234048b4
commit
942faee833
File diff suppressed because one or more lines are too long
@ -54,11 +54,8 @@ class Calc
|
||||
foreach ($this->article->getOptions() as $option) {
|
||||
|
||||
if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) {
|
||||
/** @var Select\Opt $opt */
|
||||
foreach ($option->getOptions() as $opt) {
|
||||
if ($opt->isValid() && $opt->isSelected()) {
|
||||
$gesamt = $this->parseEdgeCollection($gesamt, $option, $opt->getEdgesCollectionContainer(), [$option->getId()]);
|
||||
}
|
||||
if ($option->getSelectedOption() != null && $option->getSelectedOption()->isValid()) {
|
||||
$gesamt = $this->parseEdgeCollection($gesamt, $option, $option->getSelectedOption()->getEdgesCollectionContainer(), [$option->getId()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -55,11 +55,8 @@ class CalcValues
|
||||
foreach ($this->article->getOptions() as $option) {
|
||||
|
||||
if ($option instanceof Select || $option instanceof Checkbox) {
|
||||
/** @var Select\Opt $opt */
|
||||
foreach ($option->getOptions() as $opt) {
|
||||
if ($opt->isValid() && $opt->isSelected()) {
|
||||
$price = $this->parseEdgeCollection($price, $option->getId(), $opt->getEdgesCollectionContainer());
|
||||
}
|
||||
if ($option->getSelectedOption() != null && $option->getSelectedOption()->isValid()) {
|
||||
$price = $this->parseEdgeCollection($price, $option->getId(), $option->getSelectedOption()->getEdgesCollectionContainer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,10 +53,9 @@ class Valid
|
||||
$valid = false;
|
||||
$nextShouldBeValid = false;
|
||||
$isDefaultValid = true;
|
||||
|
||||
$option->setSelectedOption(null);
|
||||
/** @var Select\Opt $opt */
|
||||
foreach ($option->getOptions() as $opt) {
|
||||
$opt->setIsSelected(false);
|
||||
if(count($opt->getEdgesCollectionContainer()) > 0) {
|
||||
$opt->setIsValid(false);
|
||||
}
|
||||
@ -125,16 +124,16 @@ class Valid
|
||||
if(!$opt->isValid()) {
|
||||
$nextShouldBeValid = true;
|
||||
} else {
|
||||
$opt->setIsSelected(true);
|
||||
$option->setSelectedOption($opt);
|
||||
}
|
||||
|
||||
} else {
|
||||
if($nextShouldBeValid && $opt->isValid()) {
|
||||
$this->engine->getVariables()[$option->getId()] = $opt->getId();
|
||||
$opt->setIsSelected(true);
|
||||
$option->setSelectedOption($opt);
|
||||
$nextShouldBeValid = false;
|
||||
} else{
|
||||
$opt->setIsSelected(false);
|
||||
$option->setSelectedOption(null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -148,7 +147,7 @@ class Valid
|
||||
if($nextShouldBeValid) {
|
||||
foreach($option->getOptions() as $opt) {
|
||||
if($opt->isValid()) {
|
||||
$opt->setIsSelected(true);
|
||||
$option->setSelectedOption($opt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -633,12 +633,12 @@ class Engine
|
||||
$count++;
|
||||
}
|
||||
|
||||
$calcValid = new Valid($this, $this->article);
|
||||
$calcValid->perform();
|
||||
// $calcValid = new Valid($this, $this->article);
|
||||
// $calcValid->perform();
|
||||
|
||||
// CALC Values
|
||||
$calcValues = new CalcValues($this, $this->article);
|
||||
$calcValues->calc();
|
||||
// $calcValues = new CalcValues($this, $this->article);
|
||||
// $calcValues->calc();
|
||||
|
||||
// Check if Option is valid
|
||||
// CALC Formel
|
||||
|
||||
@ -9,14 +9,6 @@ class ColorDBSelect extends Select
|
||||
{
|
||||
private string $colorSystem = "";
|
||||
|
||||
public function getSelectedOption()
|
||||
{
|
||||
/** @var Opt $opt */
|
||||
foreach($this->getOptions() as $opt) {
|
||||
if($opt->isSelected()) return $opt;
|
||||
}
|
||||
}
|
||||
|
||||
public function getColorSystem(): string
|
||||
{
|
||||
return $this->colorSystem;
|
||||
|
||||
@ -9,20 +9,19 @@ class PaperDbSelect extends Select
|
||||
{
|
||||
protected $newPaperObject = null;
|
||||
|
||||
public function getSelectedOption()
|
||||
public function getSelectedOption(): ?Opt
|
||||
{
|
||||
/** @var Opt $opt */
|
||||
foreach($this->getOptions() as $opt) {
|
||||
if($opt->isSelected()) return $opt;
|
||||
|
||||
if($this->selectedOption != null) {
|
||||
return $this->selectedOption;
|
||||
}
|
||||
|
||||
if(isset($this->savedCalcValues[$this->getId()]) && $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue()) {
|
||||
$opt = new PaperOpt();
|
||||
$opt->setIsSelected(true);
|
||||
$opt->setId($this->savedCalcValues[$this->getId()]['art_nr']);
|
||||
$opt->setLabel($this->savedCalcValues[$this->getId()]['description_1']);
|
||||
|
||||
|
||||
$this->setSelectedOption($opt);
|
||||
$paper = $this->newPaperObject;
|
||||
$paper->setId($this->savedCalcValues[$this->getId()]['id']);
|
||||
$paper->setArtNr($this->savedCalcValues[$this->getId()]['art_nr']);
|
||||
@ -43,6 +42,8 @@ class PaperDbSelect extends Select
|
||||
|
||||
return $opt;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function parseAdditionalValues($variables)
|
||||
|
||||
@ -17,6 +17,8 @@ class Select extends Base
|
||||
/** @var \ArrayIterator $options */
|
||||
protected $options;
|
||||
|
||||
protected ?Opt $selectedOption = null;
|
||||
|
||||
/** @var String $container */
|
||||
protected $container = '';
|
||||
|
||||
@ -92,12 +94,14 @@ class Select extends Base
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function getSelectedOption()
|
||||
public function getSelectedOption(): ?Opt
|
||||
{
|
||||
/** @var Opt $opt */
|
||||
foreach($this->getOptions() as $opt) {
|
||||
if($opt->isSelected()) return $opt;
|
||||
return $this->selectedOption;
|
||||
}
|
||||
|
||||
public function setSelectedOption(?Opt $opt): void
|
||||
{
|
||||
$this->selectedOption = $opt;
|
||||
}
|
||||
|
||||
public function getValidOptions()
|
||||
|
||||
@ -18,9 +18,6 @@ class Opt
|
||||
/** @var bool */
|
||||
protected $isValid = true;
|
||||
|
||||
/** @var bool */
|
||||
protected $isSelected = false;
|
||||
|
||||
/**
|
||||
* Opt constructor.
|
||||
*/
|
||||
@ -94,22 +91,6 @@ class Opt
|
||||
$this->isValid = $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSelected()
|
||||
{
|
||||
return $this->isSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $isSelected
|
||||
*/
|
||||
public function setIsSelected($isSelected)
|
||||
{
|
||||
$this->isSelected = $isSelected;
|
||||
}
|
||||
|
||||
public function clearEdgesCollectionContainer()
|
||||
{
|
||||
$this->edgesCollectionContainer = new EdgeCollectionContainer();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user