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) {
|
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) {
|
||||||
/** @var Select\Opt $opt */
|
if ($option->getSelectedOption() != null && $option->getSelectedOption()->isValid()) {
|
||||||
foreach ($option->getOptions() as $opt) {
|
$gesamt = $this->parseEdgeCollection($gesamt, $option, $option->getSelectedOption()->getEdgesCollectionContainer(), [$option->getId()]);
|
||||||
if ($opt->isValid() && $opt->isSelected()) {
|
|
||||||
$gesamt = $this->parseEdgeCollection($gesamt, $option, $opt->getEdgesCollectionContainer(), [$option->getId()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,12 +55,9 @@ 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) {
|
||||||
/** @var Select\Opt $opt */
|
if ($option->getSelectedOption() != null && $option->getSelectedOption()->isValid()) {
|
||||||
foreach ($option->getOptions() as $opt) {
|
$price = $this->parseEdgeCollection($price, $option->getId(), $option->getSelectedOption()->getEdgesCollectionContainer());
|
||||||
if ($opt->isValid() && $opt->isSelected()) {
|
|
||||||
$price = $this->parseEdgeCollection($price, $option->getId(), $opt->getEdgesCollectionContainer());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parseEdgeCollection($price, $option->getId(), $option->getEdgesCollectionContainer());
|
$this->parseEdgeCollection($price, $option->getId(), $option->getEdgesCollectionContainer());
|
||||||
|
|||||||
@ -53,10 +53,9 @@ class Valid
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
$nextShouldBeValid = false;
|
$nextShouldBeValid = false;
|
||||||
$isDefaultValid = true;
|
$isDefaultValid = true;
|
||||||
|
$option->setSelectedOption(null);
|
||||||
/** @var Select\Opt $opt */
|
/** @var Select\Opt $opt */
|
||||||
foreach ($option->getOptions() as $opt) {
|
foreach ($option->getOptions() as $opt) {
|
||||||
$opt->setIsSelected(false);
|
|
||||||
if(count($opt->getEdgesCollectionContainer()) > 0) {
|
if(count($opt->getEdgesCollectionContainer()) > 0) {
|
||||||
$opt->setIsValid(false);
|
$opt->setIsValid(false);
|
||||||
}
|
}
|
||||||
@ -125,16 +124,16 @@ class Valid
|
|||||||
if(!$opt->isValid()) {
|
if(!$opt->isValid()) {
|
||||||
$nextShouldBeValid = true;
|
$nextShouldBeValid = true;
|
||||||
} else {
|
} else {
|
||||||
$opt->setIsSelected(true);
|
$option->setSelectedOption($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();
|
||||||
$opt->setIsSelected(true);
|
$option->setSelectedOption($opt);
|
||||||
$nextShouldBeValid = false;
|
$nextShouldBeValid = false;
|
||||||
} else{
|
} else{
|
||||||
$opt->setIsSelected(false);
|
$option->setSelectedOption(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -148,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()) {
|
||||||
$opt->setIsSelected(true);
|
$option->setSelectedOption($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
|
||||||
|
|||||||
@ -9,14 +9,6 @@ class ColorDBSelect extends Select
|
|||||||
{
|
{
|
||||||
private string $colorSystem = "";
|
private string $colorSystem = "";
|
||||||
|
|
||||||
public function getSelectedOption()
|
|
||||||
{
|
|
||||||
/** @var Opt $opt */
|
|
||||||
foreach($this->getOptions() as $opt) {
|
|
||||||
if($opt->isSelected()) return $opt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColorSystem(): string
|
public function getColorSystem(): string
|
||||||
{
|
{
|
||||||
return $this->colorSystem;
|
return $this->colorSystem;
|
||||||
|
|||||||
@ -9,20 +9,19 @@ class PaperDbSelect extends Select
|
|||||||
{
|
{
|
||||||
protected $newPaperObject = null;
|
protected $newPaperObject = null;
|
||||||
|
|
||||||
public function getSelectedOption()
|
public function getSelectedOption(): ?Opt
|
||||||
{
|
{
|
||||||
/** @var Opt $opt */
|
|
||||||
foreach($this->getOptions() as $opt) {
|
if($this->selectedOption != null) {
|
||||||
if($opt->isSelected()) return $opt;
|
return $this->selectedOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()) {
|
||||||
$opt = new PaperOpt();
|
$opt = new PaperOpt();
|
||||||
$opt->setIsSelected(true);
|
|
||||||
$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);
|
||||||
$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']);
|
||||||
@ -43,6 +42,8 @@ class PaperDbSelect extends Select
|
|||||||
|
|
||||||
return $opt;
|
return $opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseAdditionalValues($variables)
|
public function parseAdditionalValues($variables)
|
||||||
|
|||||||
@ -17,6 +17,8 @@ class Select extends Base
|
|||||||
/** @var \ArrayIterator $options */
|
/** @var \ArrayIterator $options */
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|
||||||
|
protected ?Opt $selectedOption = null;
|
||||||
|
|
||||||
/** @var String $container */
|
/** @var String $container */
|
||||||
protected $container = '';
|
protected $container = '';
|
||||||
|
|
||||||
@ -92,12 +94,14 @@ class Select extends Base
|
|||||||
return $this->options;
|
return $this->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSelectedOption()
|
public function getSelectedOption(): ?Opt
|
||||||
{
|
{
|
||||||
/** @var Opt $opt */
|
return $this->selectedOption;
|
||||||
foreach($this->getOptions() as $opt) {
|
}
|
||||||
if($opt->isSelected()) return $opt;
|
|
||||||
}
|
public function setSelectedOption(?Opt $opt): void
|
||||||
|
{
|
||||||
|
$this->selectedOption = $opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValidOptions()
|
public function getValidOptions()
|
||||||
|
|||||||
@ -18,9 +18,6 @@ class Opt
|
|||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $isValid = true;
|
protected $isValid = true;
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
protected $isSelected = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opt constructor.
|
* Opt constructor.
|
||||||
*/
|
*/
|
||||||
@ -94,22 +91,6 @@ class Opt
|
|||||||
$this->isValid = $isValid;
|
$this->isValid = $isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isSelected()
|
|
||||||
{
|
|
||||||
return $this->isSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $isSelected
|
|
||||||
*/
|
|
||||||
public function setIsSelected($isSelected)
|
|
||||||
{
|
|
||||||
$this->isSelected = $isSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clearEdgesCollectionContainer()
|
public function clearEdgesCollectionContainer()
|
||||||
{
|
{
|
||||||
$this->edgesCollectionContainer = new EdgeCollectionContainer();
|
$this->edgesCollectionContainer = new EdgeCollectionContainer();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user