icingaweb2-module-businessp.../library/Businessprocess/Modification/NodeCreateAction.php

104 lines
2.1 KiB
PHP
Raw Normal View History

2015-03-16 04:08:00 -04:00
<?php
namespace Icinga\Module\Businessprocess\Modification;
2015-03-16 04:08:00 -04:00
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Node;
2015-03-16 04:08:00 -04:00
class NodeCreateAction extends NodeAction
{
/** @var string */
2015-03-16 04:08:00 -04:00
protected $parentName;
/** @var array */
2015-03-16 04:08:00 -04:00
protected $properties = array();
/** @var array */
2015-03-16 04:08:00 -04:00
protected $preserveProperties = array('parentName', 'properties');
/**
* @param Node $name
*/
2015-03-16 04:08:00 -04:00
public function setParent(Node $name)
{
$this->parentName = (string) $name;
2015-03-16 04:08:00 -04:00
}
/**
* @return bool
*/
2015-03-16 04:08:00 -04:00
public function hasParent()
{
return $this->parentName !== null;
}
/**
* @return string
*/
2015-03-16 04:08:00 -04:00
public function getParentName()
{
return $this->parentName;
}
/**
* @param string $name
*/
2015-03-16 04:08:00 -04:00
public function setParentName($name)
{
$this->parentName = $name;
}
/**
* @return array
*/
2015-03-16 04:08:00 -04:00
public function getProperties()
{
return $this->properties;
}
/**
* @param stdClass $properties
* @return $this
*/
public function setProperties(stdClass $properties)
2015-03-16 04:08:00 -04:00
{
$this->properties = $properties;
return $this;
}
/**
* @inheritdoc
*/
2015-03-16 04:08:00 -04:00
public function appliesTo(BusinessProcess $bp)
{
return ! $bp->hasNode($this->getNodeName());
}
/**
* @inheritdoc
*/
2015-03-16 04:08:00 -04:00
public function applyTo(BusinessProcess $bp)
{
$name = $this->getNodeName();
2015-03-16 04:08:00 -04:00
$node = new BpNode($bp, (object) array(
'name' => $name,
'operator' => $this->properties['operator'],
'child_names' => $this->properties['childNames']
2015-03-16 04:08:00 -04:00
));
foreach ($this->getProperties() as $key => $val) {
2015-03-16 04:08:00 -04:00
$func = 'set' . ucfirst($key);
$node->$func($val);
}
$bp->addNode($name, $node);
2015-03-16 04:08:00 -04:00
if ($this->hasParent()) {
$node->addParent($bp->getNode($this->getParentName()));
}
return $node;
}
}