Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CargoTreeFormatTree | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| getNodes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getNode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addNode | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class to print query results in a "tree" display, using a field that |
| 5 | * defines a "parent" relationship between rows. |
| 6 | * |
| 7 | * @author Yaron Koren |
| 8 | * @ingroup Cargo |
| 9 | */ |
| 10 | |
| 11 | class CargoTreeFormatTree { |
| 12 | |
| 13 | private $mNodes = []; |
| 14 | |
| 15 | public function getNodes() { |
| 16 | return $this->mNodes; |
| 17 | } |
| 18 | |
| 19 | public function getNode( $nodeName ) { |
| 20 | return $this->mNodes[$nodeName]; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param string $nodeName |
| 25 | * @param string $parentName |
| 26 | * @param array $nodeValues |
| 27 | * @throws MWException |
| 28 | */ |
| 29 | public function addNode( $nodeName, $parentName, $nodeValues ) { |
| 30 | // Add node for child, if it's not already there. |
| 31 | if ( array_key_exists( $nodeName, $this->mNodes ) ) { |
| 32 | // Make sure it doesn't have more than one parent. |
| 33 | $existingParent = $this->mNodes[$nodeName]->getParent(); |
| 34 | if ( $existingParent != null && $existingParent != $parentName ) { |
| 35 | throw new MWException( "The value \"$nodeName\" cannot have more than one parent " |
| 36 | . "defined for it" ); |
| 37 | } |
| 38 | } else { |
| 39 | $this->mNodes[$nodeName] = new CargoTreeFormatNode(); |
| 40 | } |
| 41 | $this->mNodes[$nodeName]->setParent( $parentName ); |
| 42 | $this->mNodes[$nodeName]->setValues( $nodeValues ); |
| 43 | |
| 44 | // Add node for parent, if it's not already there |
| 45 | if ( !array_key_exists( $parentName, $this->mNodes ) ) { |
| 46 | $this->mNodes[$parentName] = new CargoTreeFormatNode(); |
| 47 | } |
| 48 | $this->mNodes[$parentName]->addChild( $nodeName ); |
| 49 | } |
| 50 | } |