Add block object to layout based on xml node data

@param Varien_Simplexml_Element $node
@param Varien_Simplexml_Element $parent

@return Aoe_Layout_Model_Layout
544745
protected function _generateBlock($node, $parent)
    {
        if ($node instanceof Mage_Core_Model_Layout_Element) {
            if (!$this->checkConditionals($node)) {
                return $this;
            }
        }

        return parent::_generateBlock($node, $parent);
    }
1098357
protected function insertIntoTree(&$node, $existingNode = null)
    {

        $treeOriginTagDef = $node->getNodeRef()->getElement()->getSchema()->getTreeOriginTagDef();

        if(empty($treeOriginTagDef))
            throw new NodeException('Cannot insert a node in tree order mode without a tree origin tag definition');

        if($treeOriginTagDef->isMultiple())
            throw new NodeException('Cannot have more than 1 tree origin tag');

        if($treeOriginTagDef->Direction == 'out')
            $treeOrigin = $node->getOutTag($treeOriginTagDef->Id);
        else
            $treeOrigin = $node->getInTag($treeOriginTagDef->Id);

        if(empty($treeOrigin))
            throw new NodeException('Cannot insert a node into the tree without the tree origin tag');

        $treeOriginPartial = $treeOrigin->toPartial();

        $parentTreeID = '';
        if($node->getTreeParent() != false)
        {
            $parentNode = $this->NodeLookupDAO->getByNodeRef(new NodeRef($node->getNodeRef()->getElement(), $node->getTreeParent()));

            $parentTreeID = $parentNode->TreeID;
        }

        // fetch max tree id (if parentTreeID is blank, return last top-level tree id)
        $maxChildTreeID = $this->fetchMaxChildTreeID($node, $treeOriginTagDef, $treeOriginPartial, $parentTreeID);

        if(!is_null($existingNode) && $maxChildTreeID == $existingNode->TreeID)
        {
            $node->TreeID = $existingNode->TreeID;
            return;
        }

        if(empty($maxChildTreeID))
        {
            $newTreeID = $parentTreeID . '0001';

        // add this to the children
        } else {

            $last4 = substr($maxChildTreeID, -4);
            if(strtolower($last4) == 'ffff')
                throw new NodeException('This tree leaf has reached the limit of its children');

            $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT);
        }

        while(!$this->Locks->getLock('treeid:'.$treeOriginPartial.':'.$newTreeID, 0)) {

            $last4 = substr($newTreeID, -4);
            if(strtolower($last4) == 'ffff')
                throw new NodeException('This tree leaf has reached the limit of its children');

            $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT);

        }

        $node->TreeID = $newTreeID;
    }
159351
public function set_parent(Node_Container $parent=null)
	{
		$this->parent = $parent;

		if($parent instanceof Node_Container_Document)
			$this->root = $parent;
		else
			$this->root = $parent->root();
	}
793197
public function add(AbstractNode $node)
    {
        $node->setParent($this);

        $this->children[] = $node;

        return $this;
    }
244493
public function addNode(Node $node): self
    {
        $this->nodes[] = $node;
        $this->nodesByType[$node::NODE_TYPE][] = $node;
        return $this;
    }
888557
public function parseElement(Node $parent, \DOMElement $element)
    {
        if (AtomPub::NS === $element->namespaceURI) {
            switch ($element->localName) {
                case 'collection':
                    // Node name already checked
                    return new Collection($parent, $element);
                case 'workspace':
                    // Node name already checked
                    return new Workspace($parent, $element);
            }
        }

        return null;
    }
500659
public function generateBlocks($parent = null)
    {
        if ($parent instanceof Mage_Core_Model_Layout_Element) {
            // This prevents processing child blocks if the parent block fails a conditional check
            if (!$this->checkConditionals($parent)) {
                return;
            }

            // This is handled here so it catches 'block' and 'reference' elements
            $this->processOutputAttribute($parent);
        }

        parent::generateBlocks($parent);
    }
1268553
public function addNode(Node $node)
    {
        $node->setNavigation($this);
        $this->nodes[] = $node;

        return $this;
    }
350952
public function createElement(Node $parent, $name)
    {
        if (array_key_exists($name, $this->elementMap)) {
            $class = $this->elementMap[$name];

            return new $class($parent);
        }

        return null;
    }
812059
protected function performCreateChildOf(array $attributes, Node $parent)
    {

        $parentIdName = $this->getParentIdName();
        $rootIdName = $this->getRootIdName();

        $child = $this->make($attributes);
        $child[$parentIdName] = $parent->getId();
        $child[$rootIdName] = $parent[$rootIdName];

        $child->save();

        // Set in-memory relations
        $child->setParent($parent);
        $parent->addChild($child);

        return $child;

    }
232635
public static function get_block_parent( \DOMNode $node ) {
		$parent = $node->parentNode;
		if ( ! $parent instanceof \DOMElement ) {
			return null;
		}

		while ( ! self::is_block_tag( $parent ) && $parent->parentNode instanceof \DOMElement ) {
			/**
			 * The parent is sure to be a \DOMElement.
			 *
			 * @var \DOMElement
			 */
			$parent = $parent->parentNode;
		}

		return $parent;
	}
1152512
public static function fromNode($node, $parent) {
        if (is_null($node["value"]))
            return new Feature($node, $parent, $node->children());
        else
            return new ValueFeature($node, $parent, $node->children());
    }
1024431
protected function handleBlocks(Node $node)
    {

        $this->blocks = $node->findArray('block');
        foreach ($this->blocks as $blockNode)
            $this->handleBlock($blockNode);

        return $this;
    }
1278760
public function addNode(ElementtypeStructureNode $node)
    {
        $dsId = $node->getDsId();
        $parentDsId = $node->getParentDsId();

        if (array_key_exists($dsId, $this->dsIdMap)) {
            $msg = "Duplicate node in element structure tree: ds_id=$dsId";
            throw new InvalidArgumentException($msg);
        }

        // add node by node id and ds id to node map
        $this->dsIdMap[$dsId] = $node;
        $this->childrenMap[$parentDsId][] = $dsId;
        $this->parentMap[$dsId] = $parentDsId;

        if (!$this->rootDsId && $node->isRoot()) {
            $this->rootDsId = $dsId;
        }

        return $this;
    }
659372
public function addChild(Node $node)
    {
        if($node instanceof NodeWrapper)
        {
            if($node == $this)
            {
                throw new \InvalidArgumentException('Cannot insert node as a child of itself');
            }

            $node->insertAsLastChildOf($this);
            return $node;
        }

        $node->setLeftValue($this->getRightValue());
        $node->setRightValue($this->getRightValue() + 1);
        if($this->hasManyRoots())
        {
            $node->setRootValue($this->getRootValue());
        }

        $em = $this->getManager()->getEntityManager();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            $this->shiftRLRange($this->getRightValue(), 0, 2, ($this->hasManyRoots() ? $this->getRootValue() : null));

            $em->persist($node);

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction

        return $this->getManager()->wrapNode($node);
    }
1344381
protected function _generateAction($node, $parent)
    {
        if ($node instanceof Mage_Core_Model_Layout_Element) {
            if (!$this->checkConditionals($node)) {
                return $this;
            }
        }

        $method = (string)$node['method'];
        if (!empty($node['block'])) {
            $parentName = (string)$node['block'];
        } else {
            $parentName = $parent->getBlockName();
        }

        $_profilerKey = 'BLOCK ACTION: ' . $parentName . ' -> ' . $method;
        Varien_Profiler::start($_profilerKey);

        if (!empty($parentName)) {
            $block = $this->getBlock($parentName);
        }
        if (!empty($block)) {
            $args = (array)$node->children();

            $jsonArgs = (isset($node['json']) ? explode(' ', (string)$node['json']) : []);
            $jsonHelper = Mage::helper('core');
            $translateArgs = (isset($node['translate']) ? explode(' ', (string)$node['translate']) : []);
            $translateHelper = Mage::helper(isset($node['module']) ? (string)$node['module'] : 'core');
            $args = $this->processActionArgs($args, $jsonArgs, $jsonHelper, $translateArgs, $translateHelper);

            call_user_func_array([$block, $method], $args);
        }

        Varien_Profiler::stop($_profilerKey);

        return $this;
    }
841462
public function add_children(& $node, $parentidnumber) {
        foreach ($this->flat as $competency) {
            if ($competency->parentidnumber == $parentidnumber) {
                $this->progress->increment_progress();
                $node->children[] = $competency;
                $this->add_children($competency, $competency->idnumber);
            }
        }
    }