Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 20 |
CargoTreeFormatTree | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 20 |
getNodes | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getNode | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
addNode | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 16 |
<?php | |
/** | |
* Class to print query results in a "tree" display, using a field that | |
* defines a "parent" relationship between rows. | |
* | |
* @author Yaron Koren | |
* @ingroup Cargo | |
*/ | |
class CargoTreeFormatTree { | |
private $mNodes = []; | |
public function getNodes() { | |
return $this->mNodes; | |
} | |
public function getNode( $nodeName ) { | |
return $this->mNodes[$nodeName]; | |
} | |
/** | |
* @param string $nodeName | |
* @param string $parentName | |
* @param array $nodeValues | |
* @throws MWException | |
*/ | |
public function addNode( $nodeName, $parentName, $nodeValues ) { | |
// Add node for child, if it's not already there. | |
if ( array_key_exists( $nodeName, $this->mNodes ) ) { | |
// Make sure it doesn't have more than one parent. | |
$existingParent = $this->mNodes[$nodeName]->getParent(); | |
if ( $existingParent != null && $existingParent != $parentName ) { | |
throw new MWException( "The value \"$nodeName\" cannot have more than one parent " | |
. "defined for it" ); | |
} | |
} else { | |
$this->mNodes[$nodeName] = new CargoTreeFormatNode(); | |
} | |
$this->mNodes[$nodeName]->setParent( $parentName ); | |
$this->mNodes[$nodeName]->setValues( $nodeValues ); | |
// Add node for parent, if it's not already there | |
if ( !array_key_exists( $parentName, $this->mNodes ) ) { | |
$this->mNodes[$parentName] = new CargoTreeFormatNode(); | |
} | |
$this->mNodes[$parentName]->addChild( $nodeName ); | |
} | |
} |