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 {
|
2015-07-03 10:16:18 +00:00
|
|
|
const LAYOUT_ATTR_NAME = 'layout';
|
|
|
|
const SHOW_ATTR_NAME = 'show';
|
|
|
|
const DEFAULT_OPTION = 'default';
|
|
|
|
const SHOW_INCOMPLETE_OPTION = 'incomplete';
|
2015-06-10 16:07:28 +00:00
|
|
|
|
|
|
|
private $supportedGroupLayouts = [
|
2015-07-03 10:16:18 +00:00
|
|
|
self::DEFAULT_OPTION,
|
2015-06-10 16:07:28 +00:00
|
|
|
'horizontal'
|
|
|
|
];
|
2015-04-27 14:05:31 +00:00
|
|
|
|
2015-07-03 10:16:18 +00:00
|
|
|
private $supportedGroupDisplays = [
|
|
|
|
self::DEFAULT_OPTION,
|
|
|
|
self::SHOW_INCOMPLETE_OPTION
|
|
|
|
];
|
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
public function getData() {
|
2015-06-10 09:28:33 +00:00
|
|
|
if ( !isset( $this->data ) ) {
|
2015-06-15 12:57:57 +00:00
|
|
|
$this->data = [ 'value' => $this->getDataForChildren(),
|
2015-06-15 12:58:48 +00:00
|
|
|
'layout' => $this->getLayout() ];
|
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() {
|
2015-07-03 10:16:18 +00:00
|
|
|
$value = $this->showIncomplete() ?
|
|
|
|
array_map(
|
|
|
|
function ( Node $item ) {
|
|
|
|
return $item->getRenderData();
|
|
|
|
},
|
|
|
|
$this->getChildNodes()
|
|
|
|
)
|
|
|
|
: $this->getRenderDataForChildren();
|
|
|
|
|
2015-06-11 09:34:28 +00:00
|
|
|
return [
|
|
|
|
'type' => $this->getType(),
|
2015-07-03 10:16:18 +00:00
|
|
|
'data' => [ 'value' => $value,
|
2015-06-15 12:58:48 +00:00
|
|
|
'layout' => $this->getLayout() ],
|
2015-06-11 09:34:28 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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() {
|
2015-06-11 09:48:32 +00:00
|
|
|
return $this->getSourceForChildren();
|
2015-06-10 15:19:40 +00:00
|
|
|
}
|
2015-06-15 12:58:48 +00:00
|
|
|
|
2015-07-03 10:16:18 +00:00
|
|
|
protected function showIncomplete() {
|
|
|
|
return strcmp( $this->getDisplay(), self::SHOW_INCOMPLETE_OPTION ) === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDisplay() {
|
|
|
|
$show = $this->getXmlAttribute( $this->xmlNode, self::SHOW_ATTR_NAME );
|
|
|
|
|
|
|
|
return ( isset( $show ) && in_array( $show, $this->supportedGroupDisplays ) ) ? $show
|
|
|
|
: self::DEFAULT_OPTION;
|
|
|
|
}
|
|
|
|
|
2015-06-15 12:58:48 +00:00
|
|
|
protected function getLayout() {
|
2015-07-03 10:16:18 +00:00
|
|
|
$layout = $this->getXmlAttribute( $this->xmlNode, self::LAYOUT_ATTR_NAME );
|
2015-06-15 12:58:48 +00:00
|
|
|
|
|
|
|
return ( isset( $layout ) && in_array( $layout, $this->supportedGroupLayouts ) ) ? $layout
|
2015-07-03 10:16:18 +00:00
|
|
|
: self::DEFAULT_OPTION;
|
2015-06-15 12:58:48 +00:00
|
|
|
}
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|