N°3123 - Refactor Directories

This commit is contained in:
Eric
2020-12-02 13:18:01 +01:00
parent d1b12ee04b
commit 15aa9e508c
259 changed files with 862 additions and 869 deletions

View File

@@ -0,0 +1,91 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Title;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* Class Title
*
* @package Combodo\iTop\Application\UI\Base\Component\Title
*/
class Title extends UIBlock
{
// Overloaded constants
/** @inheritDoc */
public const BLOCK_CODE = 'ibo-title';
/** @inheritDoc */
public const HTML_TEMPLATE_REL_PATH = 'base/components/title/layout';
/** @var string Icon should cover all the space, best for icons with filled background */
public const ENUM_ICON_COVER_METHOD_COVER = 'cover';
/** @var string Icon should be a litte zoomed out to cover almost all space, best for icons with transparent background and no margin around (eg. class icons) */
public const ENUM_ICON_COVER_METHOD_ZOOMOUT = 'zoomout';
/** @var string */
public const DEFAULT_ICON_COVER_METHOD = self::ENUM_ICON_COVER_METHOD_COVER;
/** @var string */
protected $sTitle;
/** @var int */
protected $iLevel;
/** @var string */
protected $sIconUrl;
/** @var string How the icon should cover the medallion, see static::ENUM_ICON_COVER_METHOD_COVER, static::ENUM_ICON_COVER_METHOD_ZOOMOUT */
protected $sIconCoverMethod;
/**
* @inheritDoc
*/
public function __construct(string $sTitle = '', int $iLevel = 1, ?string $sId = null)
{
parent::__construct($sId);
$this->sTitle = $sTitle;
$this->iLevel = $iLevel;
$this->sIconUrl = null;
$this->sIconCoverMethod = static::DEFAULT_ICON_COVER_METHOD;
}
/**
* @return string
*/
public function GetTitle(): string
{
return $this->sTitle;
}
/**
* @return int
*/
public function GetLevel(): int
{
return $this->iLevel;
}
public function SetIcon(string $sIconUrl, string $sIconCoverMethod = self::DEFAULT_ICON_COVER_METHOD)
{
$this->sIconUrl = $sIconUrl;
$this->sIconCoverMethod = $sIconCoverMethod;
return $this;
}
public function GetIconUrl(): string
{
return $this->sIconUrl;
}
public function GetIconCoverMethod(): string
{
return $this->sIconCoverMethod;
}
public function HasIcon(): string
{
return !is_null($this->sIconUrl);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Title;
use Combodo\iTop\Application\UI\Helper\UIHelper;
use DBObject;
use MetaModel;
class TitleFactory
{
public static function MakeForPage(string $sTitle, ?string $sId = null)
{
return new Title($sTitle, 1, $sId);
}
public static function MakeForObjectDetails(DBObject $oObject, ?string $sId = null)
{
// TODO 3.0.0: Refactor all of this
$sObjClass = get_class($oObject);
$sObjClassName = MetaModel::GetName($sObjClass);
$sObjName = $oObject->GetName();
// Object icon
// - Default icon is the class icon
$sObjIconUrl = $oObject->GetIcon(false);
// Note: Class icons are a square image with no margin around, so they need to be zoomed out in the medallion
$sIconCoverMethod = Title::ENUM_ICON_COVER_METHOD_ZOOMOUT;
// - Use object image from semantic attribute only if it's not the default image
if(!$oObject->IsNew() && MetaModel::HasImageAttributeCode($sObjClass)){
$sImageAttCode = MetaModel::GetImageAttributeCode($sObjClass);
if(!empty($sImageAttCode)){
/** @var \ormDocument $oImage */
$oImage = $oObject->Get($sImageAttCode);
if(!$oImage->IsEmpty()){
$sObjIconUrl = $oImage->GetDisplayURL($sObjClass, $oObject->GetKey(), $sImageAttCode);
$sIconCoverMethod = Title::ENUM_ICON_COVER_METHOD_COVER;
}
}
}
$oTitle = new TitleForObjectDetails($sObjClassName, $sObjName, $sId);
if(!empty($sObjIconUrl)) {
$oTitle->SetIcon($sObjIconUrl, $sIconCoverMethod);
}
if (MetaModel::HasStateAttributeCode($sObjClass)) {
$sStateCode = $oObject->GetState();
// Protection against classes with no default state (in which case we don't display the status)
if(!empty($sStateCode)) {
$sStatusAttCode = MetaModel::GetStateAttributeCode($sObjClass);
$sStatusLabel = $oObject->GetStateLabel();
$sStatusColor = UIHelper::GetColorFromStatus(get_class($oObject), $sStateCode);
$oTitle->SetStatus($sStatusAttCode, $sStatusLabel, $sStatusColor);
}
}
return $oTitle;
}
public static function MakeNeutral(string $sTitle, int $iLevel = 1, ?string $sId = null)
{
return new Title($sTitle, $iLevel, $sId);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Title;
class TitleForObjectDetails extends Title
{
public const HTML_TEMPLATE_REL_PATH = 'base/components/title/titleforobjectdetails';
/** @var string */
protected $sClassName;
/** @var string */
protected $sObjectName;
protected $sStatusCode;
protected $sStatusLabel;
protected $sStatusColor;
public function __construct(string $sClassName, string $sObjectName, ?string $sId = null)
{
parent::__construct('', 2, $sId);
$this->sClassName = $sClassName;
$this->sObjectName = $sObjectName;
$this->sStatusCode = null;
$this->sStatusLabel = null;
$this->sStatusColor = null;
}
/**
* @return string
*/
public function GetClassName(): string
{
return $this->sClassName;
}
/**
* @return string
*/
public function GetObjectName(): string
{
return $this->sObjectName;
}
public function SetStatus($sCode, $sLabel, $sColor)
{
$this->sStatusCode = $sColor;
$this->sStatusLabel = $sLabel;
$this->sStatusColor = $sColor;
return $this;
}
public function GetStatusCode()
{
return $this->sStatusCode;
}
public function GetStatusLabel()
{
return $this->sStatusLabel;
}
public function GetStatusColor()
{
return $this->sStatusColor;
}
}