2015-04-27 14:05:31 +00:00
|
|
|
<?php
|
|
|
|
namespace Wikia\PortableInfobox\Parser\Nodes;
|
2015-05-07 12:37:13 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
class NodeGroup extends Node {
|
|
|
|
|
|
|
|
public function getData() {
|
2015-06-10 09:28:33 +00:00
|
|
|
if ( !isset( $this->data ) ) {
|
2015-06-11 09:34:28 +00:00
|
|
|
$this->data = [ 'value' => $this->getDataForChildren() ];
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|
2015-06-10 09:28:33 +00:00
|
|
|
|
|
|
|
return $this->data;
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 09:34:28 +00:00
|
|
|
public function getRenderData() {
|
|
|
|
return [
|
|
|
|
'type' => $this->getType(),
|
|
|
|
'data' => [ 'value' => $this->getRenderDataForChildren() ],
|
|
|
|
'isEmpty' => $this->isEmpty(),
|
|
|
|
'source' => $this->getSource()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-06-10 09:28:33 +00:00
|
|
|
public function isEmpty() {
|
2015-06-11 09:34:28 +00:00
|
|
|
/** @var Node $item */
|
|
|
|
foreach ( $this->getChildNodes() as $item ) {
|
|
|
|
if ( !$item->isType( 'header' ) && !$item->isEmpty() ) {
|
2015-04-27 14:05:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-10 09:28:33 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-10 15:19:40 +00:00
|
|
|
|
|
|
|
public function getSource() {
|
|
|
|
$data = $this->getData();
|
|
|
|
$result = [ ];
|
|
|
|
foreach ( $data[ 'value' ] as $item ) {
|
|
|
|
if ( isset( $item[ 'source' ] ) ) {
|
|
|
|
$source = !is_array( $item[ 'source' ] ) ? [ $item[ 'source' ] ] : $item[ 'source' ];
|
|
|
|
$result = array_merge( $result, $source );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_unique( $result );
|
|
|
|
}
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|