64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
namespace PSC\Library\Calc\Option\Parser\Row;
|
|
|
|
use PSC\Library\Calc\Option\Parser;
|
|
use PSC\Library\Calc\Option\Parser\Base;
|
|
use PSC\Library\Calc\Option\Parser\Row;
|
|
use PSC\Library\Calc\Option\Type\Row\Column as PSCColumn;
|
|
use PSC\Library\Calc\Option\Type\Select;
|
|
use PSC\Library\Calc\Option\Type\Template;
|
|
|
|
class Column extends Base
|
|
{
|
|
private Parser $optionParser;
|
|
|
|
public function __construct(private $paperContainer, private $paperRepository, private $templates)
|
|
|
|
{
|
|
$this->element = new \PSC\Library\Calc\Option\Type\Row\Column();
|
|
$this->optionParser = new \PSC\Library\Calc\Option\Parser($paperContainer, $paperRepository, $templates);
|
|
}
|
|
|
|
public function parseXML(): PSCColumn
|
|
{
|
|
parent::parseXML();
|
|
|
|
foreach ($this->node->children() as $key => $option) {
|
|
if($key == 'option') {
|
|
$obj = $this->optionParser->getOptByType($option['type'], $option['mode']?? null);
|
|
if($obj) {
|
|
$obj->fromXML($option);
|
|
if($obj instanceof Select) {
|
|
$obj->setPaperContainer($this->paperContainer);
|
|
$obj->setPaperRepository($this->paperRepository);
|
|
}
|
|
if($obj instanceof Template) {
|
|
$element = $obj->parseXML();
|
|
|
|
$default = $element->getDefault();
|
|
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
|
|
$obj = $this->optionParser->getOptByType($node[0]['type'], $node[0]['mode']?? null);
|
|
$obj->fromXML($node[0]);
|
|
$element = $obj->parseXML();
|
|
if($default != "") {
|
|
$element->setDefault($default);
|
|
}
|
|
}else{
|
|
$element = $obj->parseXML();
|
|
}
|
|
$this->element->addOption($element);
|
|
}
|
|
}elseif($key == 'row') {
|
|
$obj = new Row($this->paperContainer, $this->paperRepository, $this->templates);
|
|
$obj->fromXML($option);
|
|
$element = $obj->parseXML();
|
|
$this->element->addOption($element);
|
|
}
|
|
}
|
|
|
|
return $this->element;
|
|
}
|
|
|
|
}
|
|
|