page_tester-1.0.x-dev/src/NodeService.php
src/NodeService.php
<?php
class OrgNode {
public $name;
public $add_to_org_chart;
public $children = [];
public function __construct($name, $add_to_org_chart = false) {
$this->name = $name;
$this->add_to_org_chart = $add_to_org_chart;
}
public function addChild(OrgNode $child) {
$this->children[] = $child;
}
public function printNode($depth = 0) {
echo str_repeat(" ", $depth) . "{$this->name} (Enabled: " . ($this->add_to_org_chart ? 'Yes' : 'No') . ")\n";
foreach ($this->children as $child) {
$child->printNode($depth + 1);
}
}
}
// Create root node
$root = new OrgNode("Root");
// Add 4 children
for ($i = 1; $i <= 4; $i++) {
$child = new OrgNode("Child $i");
// Add 4 children to each child (grandchildren)
for ($j = 1; $j <= 4; $j++) {
$grandchild = new OrgNode("Grandchild $i.$j");
$child->addChild($grandchild);
}
$root->addChild($child);
}
// Optionally enable/disable nodes (here we randomly set them)
function toggleAllNodes(OrgNode $node, &$counter = 0, $bitmask = 0) {
$node->add_to_org_chart = ($bitmask >> $counter) & 1;
$counter++;
foreach ($node->children as $child) {
toggleAllNodes($child, $counter, $bitmask);
}
}
// Example: simulate one specific combination using bitmask
$combinationIndex = 123456; // Change this to try other combinations (0 to 2097151)
$counter = 0;
toggleAllNodes($root, $counter, $combinationIndex);
// Print the structure
$root->printNode();
