Reformat code

This commit is contained in:
Molkobain
2020-09-30 15:33:15 +02:00
parent ce001a8097
commit 57fda98981
6 changed files with 126 additions and 176 deletions

View File

@@ -29,13 +29,12 @@ use Combodo\iTop\Application\UI\UIBlock;
/**
* Class PageContent
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Layout\PageContent
* @internal
* @since 2.8.0
* @since 2.8.0
*/
class PageContent extends UIBlock implements iUIContentBlock
{
class PageContent extends UIBlock implements iUIContentBlock {
use tUIContentAreas;
// Overloaded constants
@@ -53,8 +52,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @param string|null $sId
*/
public function __construct(?string $sId = null)
{
public function __construct(?string $sId = null) {
parent::__construct($sId);
$this->SetMainBlocks([]);
@@ -71,8 +69,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return $this
*/
public function SetMainBlocks(array $aBlocks)
{
public function SetMainBlocks(array $aBlocks) {
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN, $aBlocks);
return $this;
@@ -84,8 +81,7 @@ class PageContent extends UIBlock implements iUIContentBlock
* @return \Combodo\iTop\Application\UI\iUIBlock[]
* @throws \Exception
*/
public function GetMainBlocks()
{
public function GetMainBlocks() {
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN);
}
@@ -97,9 +93,9 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return $this
*/
public function AddMainBlock(iUIBlock $oBlock)
{
public function AddMainBlock(iUIBlock $oBlock) {
$this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_MAIN, $oBlock);
return $this;
}
@@ -111,8 +107,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return $this
*/
public function RemoveMainBlock(string $sBlockId)
{
public function RemoveMainBlock(string $sBlockId) {
$this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_MAIN, $sBlockId);
return $this;
@@ -125,8 +120,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return $this
*/
public function SetExtraHtmlContent(string $sExtraHtmlContent)
{
public function SetExtraHtmlContent(string $sExtraHtmlContent) {
$this->sExtraHtmlContent = $sExtraHtmlContent;
return $this;
@@ -137,8 +131,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return string
*/
public function GetExtraHtmlContent()
{
public function GetExtraHtmlContent() {
return $this->sExtraHtmlContent;
}
@@ -149,8 +142,7 @@ class PageContent extends UIBlock implements iUIContentBlock
/**
* @inheritDoc
*/
public function AddHtml(string $sHtml)
{
public function AddHtml(string $sHtml) {
$oBlock = new Html($sHtml);
$this->AddMainBlock($oBlock);
@@ -162,8 +154,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @inheritDoc
*/
public function AddSubBlock(iUIBlock $oSubBlock)
{
public function AddSubBlock(iUIBlock $oSubBlock) {
$this->AddMainBlock($oSubBlock);
return $this;
@@ -176,11 +167,11 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return $this
*/
public function RemoveSubBlock(string $sId)
{
public function RemoveSubBlock(string $sId) {
foreach ($this->GetContentAreas() as $oContentArea) {
$oContentArea->RemoveSubBlock($sId);
}
return $this;
}
@@ -191,8 +182,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @return bool
*/
public function HasSubBlock(string $sId): bool
{
public function HasSubBlock(string $sId): bool {
foreach ($this->GetContentAreas() as $oContentArea) {
if ($oContentArea->HasSubBlock($sId)) {
return true;
@@ -207,8 +197,7 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @inheritDoc
*/
public function GetSubBlock(string $sId): ?iUIBlock
{
public function GetSubBlock(string $sId): ?iUIBlock {
foreach ($this->GetContentAreas() as $oContentArea) {
$oSubBlock = $oContentArea->GetSubBlock($sId);
if (!is_null($oSubBlock)) {
@@ -225,9 +214,9 @@ class PageContent extends UIBlock implements iUIContentBlock
* @inheritDoc
* @return $this|\Combodo\iTop\Application\UI\Layout\iUIContentBlock
*/
public function SetSubBlocks(array $aSubBlocks): iUIContentBlock
{
public function SetSubBlocks(array $aSubBlocks): iUIContentBlock {
$this->SetMainBlocks($aSubBlocks);
return $this;
}
@@ -236,12 +225,12 @@ class PageContent extends UIBlock implements iUIContentBlock
*
* @inheritDoc
*/
public function GetSubBlocks(): array
{
public function GetSubBlocks(): array {
$aSubBlocks = [];
foreach ($this->GetContentAreas() as $oContentArea) {
$aSubBlocks = array_merge($aSubBlocks, $oContentArea->GetSubBlocks());
}
return $aSubBlocks;
}
}

View File

@@ -25,13 +25,12 @@ use Combodo\iTop\Application\UI\iUIBlock;
/**
* Class PageContentWithSideContent
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Layout\PageContent
* @internal
* @since 2.8.0
* @since 2.8.0
*/
class PageContentWithSideContent extends PageContent
{
class PageContentWithSideContent extends PageContent {
// Overloaded constants
public const BLOCK_CODE = 'ibo-page-content-with-side-content';
public const HTML_TEMPLATE_REL_PATH = 'layouts/page-content/with-side-content';
@@ -44,8 +43,7 @@ class PageContentWithSideContent extends PageContent
*
* @param string|null $sId
*/
public function __construct(?string $sId = null)
{
public function __construct(?string $sId = null) {
parent::__construct($sId);
$this->SetSideBlocks([]);
@@ -58,8 +56,7 @@ class PageContentWithSideContent extends PageContent
*
* @return $this
*/
public function SetSideBlocks(array $aBlocks)
{
public function SetSideBlocks(array $aBlocks) {
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_SIDE, $aBlocks);
return $this;
@@ -71,8 +68,7 @@ class PageContentWithSideContent extends PageContent
* @return \Combodo\iTop\Application\UI\iUIBlock[]
* @throws \Exception
*/
public function GetSideBlocks()
{
public function GetSideBlocks() {
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_SIDE);
}
@@ -84,9 +80,9 @@ class PageContentWithSideContent extends PageContent
*
* @return $this
*/
public function AddSideBlock(iUIBlock $oBlock)
{
public function AddSideBlock(iUIBlock $oBlock) {
$this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_SIDE, $oBlock);
return $this;
}
@@ -98,8 +94,7 @@ class PageContentWithSideContent extends PageContent
*
* @return $this
*/
public function RemoveSideBlock(string $sBlockId)
{
public function RemoveSideBlock(string $sBlockId) {
$this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_SIDE, $sBlockId);
return $this;

View File

@@ -16,13 +16,12 @@ use Combodo\iTop\Application\UI\UIBlock;
* Class UIContentBlock
*
* @package Combodo\iTop\Application\UI\Layout
* @author Eric Espie <eric.espie@combodo.com>
* @author Anne-Catherine Cognet <anne-catherine.cognet@combodo.com>
* @author Eric Espie <eric.espie@combodo.com>
* @author Anne-Catherine Cognet <anne-catherine.cognet@combodo.com>
* @internal
* @since 2.8.0
* @since 2.8.0
*/
class UIContentBlock extends UIBlock implements iUIContentBlock
{
class UIContentBlock extends UIBlock implements iUIContentBlock {
// Overloaded constants
public const BLOCK_CODE = 'ibo-contentblock';
public const HTML_TEMPLATE_REL_PATH = 'layouts/contentblock/layout';
@@ -38,10 +37,9 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
* UIContentBlock constructor.
*
* @param string|null $sName
* @param string $sContainerClass
* @param string $sContainerClass
*/
public function __construct(string $sName = null, string $sContainerClass = '')
{
public function __construct(string $sName = null, string $sContainerClass = '') {
parent::__construct($sName);
$this->aSubBlocks = [];
@@ -52,8 +50,7 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
/**
* @inheritDoc
*/
public function AddHtml(string $sHtml)
{
public function AddHtml(string $sHtml) {
$oBlock = new Html($sHtml);
$this->AddSubBlock($oBlock);
@@ -63,8 +60,7 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
/**
* @inheritDoc
*/
public function AddSubBlock(iUIBlock $oSubBlock)
{
public function AddSubBlock(iUIBlock $oSubBlock) {
$this->aSubBlocks[$oSubBlock->GetId()] = $oSubBlock;
return $this;
@@ -73,8 +69,7 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
/**
* @inheritDoc
*/
public function RemoveSubBlock(string $sId)
{
public function RemoveSubBlock(string $sId) {
if ($this->HasSubBlock($sId)) {
unset($this->aSubBlocks[$sId]);
}
@@ -85,32 +80,28 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
/**
* @inheritDoc
*/
public function HasSubBlock(string $sId): bool
{
public function HasSubBlock(string $sId): bool {
return array_key_exists($sId, $this->aSubBlocks);
}
/**
* @inheritDoc
*/
public function GetSubBlock(string $sId): ?iUIBlock
{
public function GetSubBlock(string $sId): ?iUIBlock {
return isset($this->aSubBlocks[$sId]) ? $this->aSubBlocks[$sId] : null;
}
/**
* @inheritDoc
*/
public function GetSubBlocks(): array
{
public function GetSubBlocks(): array {
return $this->aSubBlocks;
}
/**
* @inheritDoc
*/
public function SetSubBlocks(array $aSubBlocks)
{
public function SetSubBlocks(array $aSubBlocks) {
foreach ($aSubBlocks as $oSubBlock) {
$this->AddSubBlock($oSubBlock);
}
@@ -121,8 +112,7 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
/**
* @return string
*/
public function GetCSSClasses(): string
{
public function GetCSSClasses(): string {
return implode(' ', $this->aCSSClasses);
}
@@ -131,10 +121,10 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
*
* @return UIContentBlock
*/
public function SetCSSClasses(string $sCSSClasses)
{
public function SetCSSClasses(string $sCSSClasses) {
$this->aCSSClasses = [];
$this->AddCSSClasses($sCSSClasses);
return $this;
}
@@ -143,13 +133,13 @@ class UIContentBlock extends UIBlock implements iUIContentBlock
*
* @return $this
*/
public function AddCSSClasses(string $sCSSClasses)
{
public function AddCSSClasses(string $sCSSClasses) {
foreach (explode(' ', $sCSSClasses) as $sCSSClass) {
if (!empty($sCSSClass)) {
$this->aCSSClasses[$sCSSClass] = $sCSSClass;
}
}
return $this;
}

View File

@@ -12,13 +12,12 @@ use Combodo\iTop\Application\UI\iUIBlock;
* Interface iUIContentBlock
*
* @package Combodo\iTop\Application\UI\Layout
* @author Eric Espie <eric.espie@combodo.com>
* @author Anne-Catherine Cognet <anne-catherine.cognet@combodo.com>
* @author Eric Espie <eric.espie@combodo.com>
* @author Anne-Catherine Cognet <anne-catherine.cognet@combodo.com>
* @internal
* @since 2.8.0
* @since 2.8.0
*/
interface iUIContentBlock
{
interface iUIContentBlock {
/**
* Add raw HTML to the block
*

View File

@@ -26,11 +26,11 @@ use utils;
* Class UIBlock
*
* @package Combodo\iTop\Application\UI
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @internal
* @since 2.8.0
* @since 2.8.0
*/
abstract class UIBlock implements iUIBlock
{
abstract class UIBlock implements iUIBlock {
/** @var string BLOCK_CODE The block code to use to generate the identifier, the CSS/JS prefixes, ...
*
* Should start "ibo-" for the iTop backoffice blocks, followed by the name of the block in lower case (eg. for a MyCustomBlock class,
@@ -60,56 +60,6 @@ abstract class UIBlock implements iUIBlock
/** @var string ENUM_BLOCK_FILES_TYPE_TEMPLATE */
public const ENUM_BLOCK_FILES_TYPE_TEMPLATE = 'template';
/**
* @inheritDoc
*/
public static function GetGlobalTemplateRelPath()
{
return static::GLOBAL_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetHtmlTemplateRelPath()
{
return static::HTML_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetJsTemplateRelPath()
{
return static::JS_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetJsFilesRelPaths()
{
return static::JS_FILES_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetCssTemplateRelPath()
{
return static::CSS_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetCssFilesRelPaths()
{
return static::CSS_FILES_REL_PATH;
}
/** @var string $sId */
protected $sId;
@@ -118,37 +68,66 @@ abstract class UIBlock implements iUIBlock
*
* @param string|null $sId
*/
public function __construct(?string $sId = null)
{
public function __construct(?string $sId = null) {
$this->sId = ($sId !== null) ? $sId : $this->GenerateId();
}
/**
* Return a unique ID for the block
*
* @return string
* @inheritDoc
*/
protected function GenerateId()
{
return uniqid(static::BLOCK_CODE.'-');
public static function GetGlobalTemplateRelPath() {
return static::GLOBAL_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetHtmlTemplateRelPath() {
return static::HTML_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetJsTemplateRelPath() {
return static::JS_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetJsFilesRelPaths() {
return static::JS_FILES_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetCssTemplateRelPath() {
return static::CSS_TEMPLATE_REL_PATH;
}
/**
* @inheritDoc
*/
public static function GetCssFilesRelPaths() {
return static::CSS_FILES_REL_PATH;
}
/**
* Return the block code of the object instance
*
* @see static::BLOCK_CODE
* @return string
* @see static::BLOCK_CODE
*/
public function GetBlockCode()
{
public function GetBlockCode() {
return static::BLOCK_CODE;
}
/**
* @inheritDoc
*/
public function GetId()
{
public function GetId() {
return $this->sId;
}
@@ -156,8 +135,7 @@ abstract class UIBlock implements iUIBlock
* @inheritDoc
* @return \Combodo\iTop\Application\UI\iUIBlock[]
*/
public function GetSubBlocks()
{
public function GetSubBlocks() {
return [];
}
@@ -165,8 +143,7 @@ abstract class UIBlock implements iUIBlock
* @inheritDoc
* @throws \Exception
*/
public function GetJsFilesUrlRecursively(bool $bAbsoluteUrl = false)
{
public function GetJsFilesUrlRecursively(bool $bAbsoluteUrl = false) {
return $this->GetFilesUrlRecursively(static::ENUM_BLOCK_FILES_TYPE_JS, $bAbsoluteUrl);
}
@@ -174,8 +151,7 @@ abstract class UIBlock implements iUIBlock
* @inheritDoc
* @throws \Exception
*/
public function GetCssFilesUrlRecursively(bool $bAbsoluteUrl = false)
{
public function GetCssFilesUrlRecursively(bool $bAbsoluteUrl = false) {
return $this->GetFilesUrlRecursively(static::ENUM_BLOCK_FILES_TYPE_CSS, $bAbsoluteUrl);
}
@@ -183,8 +159,7 @@ abstract class UIBlock implements iUIBlock
* @return array
* @throws \Exception
*/
public function GetJsTemplateRelPathRecursively(): array
{
public function GetJsTemplateRelPathRecursively(): array {
return $this->GetUrlRecursively(static::ENUM_BLOCK_FILES_TYPE_JS, static::ENUM_BLOCK_FILES_TYPE_TEMPLATE, false);
}
@@ -192,23 +167,39 @@ abstract class UIBlock implements iUIBlock
* @return array
* @throws \Exception
*/
public function GetCssTemplateRelPathRecursively(): array
{
public function GetCssTemplateRelPathRecursively(): array {
return $this->GetUrlRecursively(static::ENUM_BLOCK_FILES_TYPE_CSS, static::ENUM_BLOCK_FILES_TYPE_TEMPLATE, false);
}
public function AddHtml(string $sHTML) {
// By default this does nothing
return $this;
}
public function GetParameters(): array {
return [];
}
/**
* Return a unique ID for the block
*
* @return string
*/
protected function GenerateId() {
return uniqid(static::BLOCK_CODE.'-');
}
/**
* Return an array of the URL of the block $sFilesType and its sub blocks.
* URL is relative unless the $bAbsoluteUrl is set to true.
*
* @param string $sFileType (see static::ENUM_BLOCK_FILES_TYPE_JS, static::ENUM_BLOCK_FILES_TYPE_CSS)
* @param bool $bAbsoluteUrl
* @param bool $bAbsoluteUrl
*
* @return array
* @throws \Exception
*/
protected function GetFilesUrlRecursively(string $sFileType, bool $bAbsoluteUrl = false)
{
protected function GetFilesUrlRecursively(string $sFileType, bool $bAbsoluteUrl = false) {
$aFiles = [];
$sFilesRelPathMethodName = 'Get'.ucfirst($sFileType).'FilesRelPaths';
@@ -228,7 +219,6 @@ abstract class UIBlock implements iUIBlock
return $aFiles;
}
/**
* Return an array of the URL of the block $sFilesType and its sub blocks.
* URL is relative unless the $bAbsoluteUrl is set to true.
@@ -238,8 +228,7 @@ abstract class UIBlock implements iUIBlock
* @return array
* @throws \Exception
*/
protected function GetTemplateRelPathRecursively(string $sExtensionFileType)
{
protected function GetTemplateRelPathRecursively(string $sExtensionFileType) {
$aFiles = [];
$sFilesRelPathMethodName = 'Get'.ucfirst($sExtensionFileType).'TemplateRelPath';
@@ -255,16 +244,4 @@ abstract class UIBlock implements iUIBlock
return $aFiles;
}
public function AddHtml(string $sHTML)
{
// By default this does nothing
return $this;
}
public function GetParameters(): array
{
return [];
}
}

View File

@@ -24,11 +24,11 @@ namespace Combodo\iTop\Application\UI;
* Interface iUIBlock
*
* @package Combodo\iTop\Application\UI
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @internal
* @since 2.8.0
* @since 2.8.0
*/
interface iUIBlock
{
interface iUIBlock {
/**
* Return the relative path (from <ITOP>/templates/) of the global template (HTML, JS, CSS) to use or null if it's not provided. Should not be used to often as JS/CSS files would be duplicated making the browser parsing time way longer.
*