PortableInfobox/services/Parser/Nodes/NodeGroup.php

44 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace Wikia\PortableInfobox\Parser\Nodes;
use Wikia\PortableInfobox\Parser\XmlParser;
class NodeGroup extends Node {
2015-06-10 15:24:49 +00:00
const DATA_LAYOUT_ATTR_NAME = 'layout';
2015-06-10 16:07:28 +00:00
const GROUP_LAYOUT_PREFIX = 'group-layout-';
const DEFAULT_LAYOUT_NAME = 'default';
private $supportedGroupLayouts = [
'default',
'horizontal'
];
public function getData() {
$nodeFactory = new XmlParser( $this->infoboxData );
if ( $this->externalParser ) {
$nodeFactory->setExternalParser( $this->externalParser );
}
2015-06-10 16:07:28 +00:00
$layout = $this->getGroupLayout();
2015-06-09 08:16:47 +00:00
$value = $nodeFactory->getDataFromNodes( $this->xmlNode, $this );
2015-06-10 15:24:49 +00:00
return [ 'value' => $value, 'layout' => $layout ];
}
public function isEmpty( $data ) {
foreach ( $data[ 'value' ] as $elem ) {
if ( $elem[ 'type' ] != 'header' && !( $elem[ 'isEmpty' ] ) ) {
return false;
}
}
return true;
}
2015-06-10 16:07:28 +00:00
private function getGroupLayout() {
$layoutName = $this->getXmlAttribute( $this->xmlNode, self::DATA_LAYOUT_ATTR_NAME );
if ( isset($layoutName) && in_array( $layoutName, $this->supportedGroupLayouts ) ) {
return $layoutName;
}
return self::DEFAULT_LAYOUT_NAME;
}
}