Fix Edges
This commit is contained in:
parent
e47ec43c1c
commit
a9b3a17518
@ -78,12 +78,27 @@ class Article
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getValidOptions()
|
||||
{
|
||||
$temp = array();
|
||||
|
||||
foreach ($this->options as $option) {
|
||||
if($option->isValid()) {
|
||||
$temp[] = $option;
|
||||
}
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
|
||||
public function getOptionsAsArray()
|
||||
{
|
||||
$temp = array();
|
||||
/** @var Option\Type\Base $option */
|
||||
foreach ($this->options as $option) {
|
||||
if($option->getValue() == '' && $option->getRawValue() == '') {
|
||||
if(($option->getValue() == '' && $option->getRawValue() == '') || !$option->isValid()) {
|
||||
continue;
|
||||
}
|
||||
$temp[$option->getId()] = array(
|
||||
|
||||
@ -48,6 +48,8 @@ class Valid
|
||||
|
||||
if($option instanceof Select) {
|
||||
|
||||
$valid = false;
|
||||
|
||||
/** @var Select\Opt $opt */
|
||||
foreach ($option->getOptions() as $opt) {
|
||||
if(count($opt->getEdgesCollectionContainer()) > 0) {
|
||||
@ -66,8 +68,13 @@ class Valid
|
||||
if($this->engine->getVariables()[$option->getId()] == $opt->getId()) {
|
||||
$opt->setIsSelected(true);
|
||||
}
|
||||
|
||||
if($opt->isValid() && !$valid) {
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
$option->setIsValid($valid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Parser\Select\Opt;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||
@ -35,6 +36,11 @@ class Select extends Base
|
||||
{
|
||||
parent::parse();
|
||||
|
||||
if(isset($this->node->grenzen) && $this->node->grenzen->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node->grenzen);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
}
|
||||
|
||||
if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||
$this->parseModePapierDb();
|
||||
}else{
|
||||
|
||||
55
tests/Legacy/selectWithGrenzenTest.php
Normal file
55
tests/Legacy/selectWithGrenzenTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Article;
|
||||
|
||||
|
||||
|
||||
use PSC\Library\Calc\Article;
|
||||
use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||
|
||||
class selectWithGrenzenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var Engine */
|
||||
protected $engine = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$repository = new PaperRepostory();
|
||||
|
||||
$paperContainer = new PaperContainer();
|
||||
$paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/Option/Select/papierContainer.xml')));
|
||||
|
||||
$this->engine = new Engine();
|
||||
$this->engine->setPaperContainer($paperContainer);
|
||||
$this->engine->setPaperRepository($repository);
|
||||
|
||||
$this->engine->loadString(file_get_contents(__DIR__ . '/../TestFiles/Legacy/testSelectWithGrenzen.xml'));
|
||||
|
||||
}
|
||||
|
||||
public function testSelectWithGrenzen()
|
||||
{
|
||||
$this->engine->calc("Test25");
|
||||
/** @var Article $article */
|
||||
$article = $this->engine->getArticle();
|
||||
|
||||
$this->assertCount(3, $article->getValidOptions());
|
||||
|
||||
$this->assertCount(3, $article->getOptionsAsArray());
|
||||
}
|
||||
|
||||
public function testSelectWithGrenzenParams()
|
||||
{
|
||||
$this->engine->setVariable('umschlag', 4);
|
||||
$this->engine->calc("Test25");
|
||||
/** @var Article $article */
|
||||
$article = $this->engine->getArticle();
|
||||
|
||||
$this->assertCount(6, $article->getValidOptions());
|
||||
|
||||
$this->assertCount(6, $article->getOptionsAsArray());
|
||||
}
|
||||
|
||||
}
|
||||
66
tests/TestFiles/Legacy/testSelectWithGrenzen.xml
Normal file
66
tests/TestFiles/Legacy/testSelectWithGrenzen.xml
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Test25</name>
|
||||
<kommentar>kein</kommentar>
|
||||
|
||||
<option id="auflage" name="Auflage" type="Input" width="3" require="true" default="1"/>
|
||||
|
||||
<option id="umschlag" name="Umschlag" type="Select" default="1">
|
||||
<opt id="1" name="ohne Umschlag"></opt>
|
||||
<opt id="4" name="+ 4 Seiten Umschlag"></opt>
|
||||
</option>
|
||||
|
||||
|
||||
<option id="papierum" name="Papier Umschlag" type="Select" mode="papierdb" container="test1" default="bdg135">
|
||||
<grenzen>
|
||||
<umschlag>
|
||||
<grenze>2-4</grenze>
|
||||
</umschlag>
|
||||
</grenzen>
|
||||
<opt>
|
||||
<umschlag>
|
||||
<grenze>2-4</grenze>
|
||||
</umschlag>
|
||||
</opt>
|
||||
</option>
|
||||
|
||||
<option id="druckum" name="Druck Umschlag" type="Select" default="44f">
|
||||
<grenzen>
|
||||
<umschlag>
|
||||
<grenze>2-4</grenze>
|
||||
</umschlag>
|
||||
</grenzen>
|
||||
<opt id="44f" name="4/4-farbig">
|
||||
<umschlag>
|
||||
<grenze>4</grenze>
|
||||
</umschlag>
|
||||
</opt>
|
||||
<opt id="40f" name="4/0-farbig">
|
||||
<umschlag>
|
||||
<grenze>4</grenze>
|
||||
</umschlag>
|
||||
</opt>
|
||||
</option>
|
||||
|
||||
<option id="druckumtest" name="Druck Umschlag TEST" type="Select" default="44f">
|
||||
<opt id="44f" name="4/4-farbig">
|
||||
<umschlag>
|
||||
<grenze>4</grenze>
|
||||
</umschlag>
|
||||
</opt>
|
||||
<opt id="40f" name="4/0-farbig">
|
||||
<umschlag>
|
||||
<grenze>4</grenze>
|
||||
</umschlag>
|
||||
</opt>
|
||||
</option>
|
||||
|
||||
<option id="auflagetest" name="AuflageTEST" type="Input" width="3" require="true" default="1">
|
||||
<umschlag>
|
||||
<grenze>2-4</grenze>
|
||||
</umschlag>
|
||||
</option>
|
||||
|
||||
</artikel>
|
||||
</kalkulation>
|
||||
Loading…
Reference in New Issue
Block a user