231 lines
7.9 KiB
PHP
231 lines
7.9 KiB
PHP
<?php
|
|
namespace PSC\Library\Calc\Option\Parser;
|
|
|
|
use Color\System\HKS;
|
|
use Color\System\PANTONE;
|
|
use Doctrine\Persistence\ObjectRepository;
|
|
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
|
use PSC\Library\Calc\Option\Parser\Select\Opt;
|
|
use PSC\Library\Calc\Option\Parser\Select\DeliveryOpt;
|
|
use PSC\Library\Calc\Option\Type\Select as PSCSelect;
|
|
use PSC\Library\Calc\PaperContainer;
|
|
use PSC\Library\Calc\Tests\Mock\Paper;
|
|
use Symfony\Contracts\Cache\ItemInterface;
|
|
|
|
class Select extends Base
|
|
{
|
|
protected $element;
|
|
|
|
/** @var PaperContainer */
|
|
protected $paperContainer;
|
|
|
|
/** @var ObjectRepository */
|
|
protected $paperRepository;
|
|
|
|
public function __construct(?string $mode = null)
|
|
{
|
|
parent::__construct();
|
|
|
|
if($mode != null && $mode == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
|
$this->element = new \PSC\Library\Calc\Option\Type\PaperDbSelect();
|
|
}elseif($mode != null && $mode == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
|
$this->element = new \PSC\Library\Calc\Option\Type\DeliverySelect();
|
|
}elseif($mode != null && $mode == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
|
$this->element = new \PSC\Library\Calc\Option\Type\ColorDBSelect();
|
|
}else{
|
|
$this->element = new \PSC\Library\Calc\Option\Type\Select();
|
|
}
|
|
|
|
}
|
|
public function parseJson(): PSCSelect
|
|
{
|
|
parent::parseJson();
|
|
|
|
if(isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) {
|
|
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
|
$edgeCollectionContainerParser->fromJson($this->json['dependencys']);
|
|
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseJson());
|
|
}
|
|
|
|
if(isset($this->json['mode']) && (string)$this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
|
$this->parseModePapierDbJson();
|
|
}elseif(isset($this->json['mode']) && (string)$this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
|
$this->parseModeDeliveryJson();
|
|
}elseif(isset($this->json['mode']) && (string)$this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
|
$this->parseModeColorDbJson();
|
|
}else{
|
|
$this->parseModeNormalJson();
|
|
}
|
|
|
|
|
|
return $this->element;
|
|
}
|
|
|
|
public function parseXML(): PSCSelect
|
|
{
|
|
parent::parseXML();
|
|
|
|
if(isset($this->node->grenzen) && $this->node->grenzen->children()) {
|
|
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
|
$edgeCollectionContainerParser->fromXML($this->node->grenzen);
|
|
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
|
}
|
|
|
|
if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
|
$this->parseModePapierDbXML();
|
|
}elseif(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
|
$this->parseModeDeliveryXML();
|
|
}elseif(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
|
$this->parseModeColorDbXML();
|
|
}else{
|
|
$this->parseModeNormalXML();
|
|
}
|
|
|
|
return $this->element;
|
|
}
|
|
|
|
private function parseModeDeliveryXML()
|
|
{
|
|
foreach ($this->node->opt as $opt) {
|
|
$optParser = new DeliveryOpt();
|
|
$optParser->fromXML($opt);
|
|
$this->element->addOption($optParser->parseXML());
|
|
}
|
|
|
|
}
|
|
|
|
private function parseModeDeliveryJson()
|
|
{
|
|
foreach ($this->json['options'] as $opt) {
|
|
$optParser = new DeliveryOpt();
|
|
$optParser->fromJson($opt);
|
|
$this->element->addOption($optParser->parseJson());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private function parseModePapierDbXML()
|
|
{
|
|
if($this->getPaperRepository()) {
|
|
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
|
|
/** @var PaperContainer\Container $container */
|
|
$container = $this->getPaperContainer()->getContainerById((string)$this->node['container']);
|
|
|
|
if($container) {
|
|
/** @var PaperContainer\Item $papier */
|
|
|
|
foreach ($container->getItems() as $papier) {
|
|
/** @var Paper $paper */
|
|
$paper = $this->getPaperRepository()->findOneBy(array('artNr' => $papier->getId()));
|
|
|
|
if($paper) {
|
|
$optPapier = new \PSC\Library\Calc\Option\Type\Select\PaperOpt();
|
|
$optPapier->setId($paper->getArtNr());
|
|
$optPapier->setLabel($paper->getDescription1());
|
|
$optPapier->setPaper($paper);
|
|
$optPapier->setValue($papier->getValue());
|
|
$optPapier->setEdgesCollectionContainer($papier->getEdgesCollectionContainer());
|
|
$this->element->addOption($optPapier);
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
$this->element->setContainer((string)$this->node['container']);
|
|
}
|
|
}
|
|
|
|
private function parseModeColorDbXML(): void
|
|
{
|
|
$colorSystem = (string)$this->node['container'];
|
|
|
|
$value = $this->cache->get($colorSystem, function (ItemInterface $item) use ($colorSystem): array {
|
|
$item->expiresAfter(3600);
|
|
|
|
$temp=[];
|
|
|
|
if(str_contains($colorSystem, "panton")) {
|
|
$system = new PANTONE(\Color\System\Enum\PANTONE::from($colorSystem));
|
|
}
|
|
if(str_contains($colorSystem, "hks")) {
|
|
$system = new HKS(\Color\System\Enum\HKS::from($colorSystem));
|
|
}
|
|
|
|
if($system) {
|
|
|
|
foreach ($system->getAllColors() as $color) {
|
|
$optColor = new \PSC\Library\Calc\Option\Type\Select\ColorOpt();
|
|
$optColor->setId($color->getName());
|
|
$optColor->setLabel($color->getValue("name"));
|
|
$optColor->setPrefix($system->getColorSystemPrefix());
|
|
$optColor->setSuffix($system->getColorSystemSuffix());
|
|
$optColor->setColorHex((string)$color->getHex());
|
|
$optColor->setColorCMYK((string)$color->getCMYK());
|
|
$optColor->setColorRGB((string)$color->getRGB());
|
|
$optColor->setValue((string)$color->getHEX());
|
|
$temp[] = $optColor;
|
|
}
|
|
}
|
|
|
|
return $temp;
|
|
});
|
|
|
|
$this->element->setColorSystem($colorSystem);
|
|
|
|
$this->element->addOptions($value);
|
|
}
|
|
|
|
private function parseModeNormalXML()
|
|
{
|
|
foreach ($this->node->opt as $opt) {
|
|
$optParser = new Opt();
|
|
$optParser->fromXML($opt);
|
|
$this->element->addOption($optParser->parseXML());
|
|
}
|
|
}
|
|
|
|
private function parseModeNormalJson()
|
|
{
|
|
foreach ($this->json['options'] as $opt) {
|
|
$optParser = new Opt();
|
|
$optParser->fromJson($opt);
|
|
$this->element->addOption($optParser->parseJson());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @return PaperContainer
|
|
*/
|
|
public function getPaperContainer()
|
|
{
|
|
return $this->paperContainer;
|
|
}
|
|
|
|
/**
|
|
* @param PaperContainer $paperContainer
|
|
*/
|
|
public function setPaperContainer($paperContainer)
|
|
{
|
|
$this->paperContainer = $paperContainer;
|
|
}
|
|
|
|
/**
|
|
* @param ObjectRepository $repostory
|
|
*/
|
|
public function setPaperRepository($repository)
|
|
{
|
|
$this->paperRepository = $repository;
|
|
}
|
|
|
|
/**
|
|
* @return ObjectRepository
|
|
*/
|
|
public function getPaperRepository()
|
|
{
|
|
return $this->paperRepository;
|
|
}
|
|
|
|
}
|