renderOneColumn($content_block, $columns_data[0]);
}
return $this->renderMultipleColumns($content_block, $columns_data);
}
private function renderOneColumn($content_block, $content) {
$template = $this->getOneColumnTemplate(
$content_block['styles']['block'],
isset($content_block['image'])?$content_block['image']:null
);
return $template['content_start'] . $content . $template['content_end'];
}
function getOneColumnTemplate($styles, $image) {
$background_css = $this->getBackgroundCss($styles, $image);
$template['content_start'] = '
';
$template['content_end'] = '
|
|
';
return $template;
}
private function renderMultipleColumns($content_block, $columns_data) {
$columns_count = count($content_block['blocks']);
$columns_layout = isset($content_block['columnLayout'])?$content_block['columnLayout']:null;
$widths = ColumnsHelper::columnWidth($columns_count, $columns_layout);
$class = ColumnsHelper::columnClass($columns_count);
$alignment = ColumnsHelper::columnAlignment($columns_count);
$index = 0;
$result = $this->getMultipleColumnsContainerStart($class, $content_block['styles']['block'], isset($content_block['image'])?$content_block['image']:null);
foreach ($columns_data as $content) {
$result .= $this->getMultipleColumnsContentStart($widths[$index++], $alignment, $class);
$result .= $content;
$result .= $this->getMultipleColumnsContentEnd();
}
$result .= $this->getMultipleColumnsContainerEnd();
return $result;
}
private function getMultipleColumnsContainerStart($class, $styles, $image) {
return '
|
';
}
private function getMultipleColumnsContentEnd() {
return '
';
}
private function getBackgroundCss($styles, $image) {
if ($image !== null && $image['src'] !== null) {
$background_color = isset($styles['backgroundColor']) && $styles['backgroundColor'] !== 'transparent' ? $styles['backgroundColor'] : '#ffffff';
$repeat = $image['display'] === 'tile' ? 'repeat' : 'no-repeat';
$size = $image['display'] === 'scale' ? 'cover' : 'contain';
return sprintf(
'background: %s url(%s) %s center/%s;background-color: %s;background-image: url(%s);background-repeat: %s;background-position: center;background-size: %s;',
$background_color, $image['src'], $repeat, $size, $background_color, $image['src'], $repeat, $size
);
} else {
if (!isset($styles['backgroundColor'])) return false;
$background_color = $styles['backgroundColor'];
return ($background_color !== 'transparent') ?
sprintf('background-color:%s!important;" bgcolor="%s', $background_color, $background_color) :
false;
}
}
}