mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°3123 - Refactor Directories
This commit is contained in:
323
sources/application/UI/Base/Layout/PageContent/PageContent.php
Normal file
323
sources/application/UI/Base/Layout/PageContent/PageContent.php
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Layout\PageContent;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tUIContentAreas;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class PageContent
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Layout\PageContent
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class PageContent extends UIBlock implements iUIContentBlock {
|
||||
use tUIContentAreas;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-page-content';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/layouts/page-content/layout';
|
||||
|
||||
/** @var string ENUM_CONTENT_AREA_MAIN The main content area */
|
||||
public const ENUM_CONTENT_AREA_MAIN = 'main';
|
||||
|
||||
/** @var string $sExtraHtmlContent HTML content that do not come from blocks and will be output as-is by the component */
|
||||
protected $sExtraHtmlContent;
|
||||
|
||||
/**
|
||||
* PageContent constructor.
|
||||
*
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(?string $sId = null) {
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->SetMainBlocks([]);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
// Specific content area
|
||||
//----------------------
|
||||
|
||||
/**
|
||||
* Set all main blocks at once.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMainBlocks(array $aBlocks) {
|
||||
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN, $aBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the main blocks
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetMainBlocks() {
|
||||
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oBlock to the main blocks.
|
||||
* Note that if a block with the same ID already exists, it will be replaced.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddMainBlock(iUIBlock $oBlock) {
|
||||
$this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_MAIN, $oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the main block identified by $sBlockId.
|
||||
* Note that if no block with that ID exists, it will proceed silently.
|
||||
*
|
||||
* @param string $sBlockId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveMainBlock(string $sBlockId) {
|
||||
$this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_MAIN, $sBlockId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the extra HTML content
|
||||
*
|
||||
* @param string $sExtraHtmlContent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetExtraHtmlContent(string $sExtraHtmlContent) {
|
||||
$this->sExtraHtmlContent = $sExtraHtmlContent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extra HTML content as-is, no processing is done on it
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetExtraHtmlContent() {
|
||||
return $this->sExtraHtmlContent;
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// iUIContentBlock implementation
|
||||
//-------------------------------
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function AddHtml(string $sHtml) {
|
||||
$oBlock = new Html($sHtml);
|
||||
$this->AddMainBlock($oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oSubBlock directly in the main area
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function AddSubBlock(iUIBlock $oSubBlock) {
|
||||
$this->AddMainBlock($oSubBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specified subBlock from all the areas
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveSubBlock(string $sId) {
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$oContentArea->RemoveSubBlock($sId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified subBlock is within one of all the areas
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function HasSubBlock(string $sId): bool {
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
if ($oContentArea->HasSubBlock($sId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific subBlock within all the areas
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlock(string $sId): ?iUIBlock {
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$oSubBlock = $oContentArea->GetSubBlock($sId);
|
||||
if (!is_null($oSubBlock)) {
|
||||
return $oSubBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAIN AREA subBlocks
|
||||
*
|
||||
* @inheritDoc
|
||||
* @return $this|\Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock
|
||||
*/
|
||||
public function SetSubBlocks(array $aSubBlocks): iUIContentBlock {
|
||||
$this->SetMainBlocks($aSubBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ALL the blocks in all the areas
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$aSubBlocks = array_merge($aSubBlocks, $oContentArea->GetSubBlocks());
|
||||
}
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
|
||||
public function GetDeferredBlocks(): array
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$aSubBlocks = array_merge($aSubBlocks, $oContentArea->GetDeferredBlocks());
|
||||
}
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oDeferredBlock directly in the main area
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function AddDeferredBlock(iUIBlock $oDeferredBlock)
|
||||
{
|
||||
$this->AddDeferredBlockToContentArea(static::ENUM_CONTENT_AREA_MAIN, $oDeferredBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specified subBlock from all the areas
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveDeferredBlock(string $sId)
|
||||
{
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$oContentArea->RemoveDeferredBlock($sId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified subBlock is within one of all the areas
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function HasDeferredBlock(string $sId): bool
|
||||
{
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
if ($oContentArea->HasDeferredBlock($sId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific subBlock within all the areas
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetDeferredBlock(string $sId): ?iUIBlock
|
||||
{
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$oDeferredBlock = $oContentArea->GetDeferredBlock($sId);
|
||||
if (!is_null($oDeferredBlock)) {
|
||||
return $oDeferredBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAIN AREA subBlocks
|
||||
*
|
||||
* @inheritDoc
|
||||
* @return $this|\Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock
|
||||
*/
|
||||
public function SetDeferredBlocks(array $aDeferredBlocks): iUIContentBlock
|
||||
{
|
||||
$this->SetContentAreaDeferredBlocks(self::ENUM_CONTENT_AREA_MAIN, $aDeferredBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Layout\PageContent;
|
||||
|
||||
|
||||
use cmdbAbstractObject;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\ActivityPanel\ActivityPanelFactory;
|
||||
use DBObject;
|
||||
|
||||
/**
|
||||
* Class PageContentFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Layout\PageContent
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class PageContentFactory
|
||||
{
|
||||
/**
|
||||
* Make a standard empty PageContent layout for backoffice pages.
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContent
|
||||
*/
|
||||
public static function MakeStandardEmpty()
|
||||
{
|
||||
return new PageContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a standard object details page with the form in the middle and the logs / activity in the side panel
|
||||
*
|
||||
* @param \DBObject $oObject
|
||||
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
|
||||
*
|
||||
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentWithSideContent
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE)
|
||||
{
|
||||
$oLayout = new PageContentWithSideContent();
|
||||
|
||||
// Add object details layout
|
||||
// TODO 3.0.0
|
||||
|
||||
// Add object activity layout
|
||||
$oActivityPanel = ActivityPanelFactory::MakeForObjectDetails($oObject, $sMode);
|
||||
$oLayout->AddSideBlock($oActivityPanel);
|
||||
|
||||
return $oLayout;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Layout\PageContent;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
|
||||
/**
|
||||
* Class PageContentWithSideContent
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Layout\PageContent
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class PageContentWithSideContent extends PageContent {
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-page-content-with-side-content';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/layouts/page-content/with-side-content';
|
||||
|
||||
// Specific constants
|
||||
public const ENUM_CONTENT_AREA_SIDE = 'side';
|
||||
|
||||
/**
|
||||
* PageContentWithSideContent constructor.
|
||||
*
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(?string $sId = null) {
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->SetSideBlocks([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all side blocks at once.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSideBlocks(array $aBlocks) {
|
||||
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_SIDE, $aBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the side blocks
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetSideBlocks() {
|
||||
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_SIDE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oBlock to the side blocks.
|
||||
* Note that if a block with the same ID already exists, it will be replaced.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddSideBlock(iUIBlock $oBlock) {
|
||||
$this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_SIDE, $oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the side block identified by $sBlockId.
|
||||
* Note that if no block with that ID exists, it will proceed silently.
|
||||
*
|
||||
* @param string $sBlockId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveSideBlock(string $sBlockId) {
|
||||
$this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_SIDE, $sBlockId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user