mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°4621 Fix naming inconsistencies in sources/*
This commit is contained in:
357
sources/Application/UI/Base/Component/Field/Field.php
Normal file
357
sources/Application/UI/Base/Component/Field/Field.php
Normal file
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Field;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Field extends UIContentBlock
|
||||
{
|
||||
/** @inheritdoc */
|
||||
public const BLOCK_CODE = 'ibo-field';
|
||||
/** @inheritdoc */
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/field/layout';
|
||||
|
||||
public const ENUM_FIELD_LAYOUT_SMALL = 'small';
|
||||
public const ENUM_FIELD_LAYOUT_LARGE = 'large';
|
||||
|
||||
/** @var string */
|
||||
protected $sLayout;
|
||||
/** @var string */
|
||||
protected $sAttCode;
|
||||
/** @var string */
|
||||
protected $sAttType;
|
||||
/** @var string */
|
||||
protected $sAttLabel;
|
||||
/** @var bool */
|
||||
protected $bIsReadOnly = false;
|
||||
/** @var bool */
|
||||
protected $bIsMandatory = false;
|
||||
/** @var bool */
|
||||
protected $bMustChange = false;
|
||||
/** @var bool */
|
||||
protected $bMustPrompt = false;
|
||||
/** @var bool */
|
||||
protected $bIsSlave = false;
|
||||
/** @var string */
|
||||
protected $sValueRaw;
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var string */
|
||||
protected $sValueId;
|
||||
|
||||
/** @var string */
|
||||
protected $sComments;
|
||||
|
||||
public function __construct(string $sLabel, UIBlock $oValue = null, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sLabel = $sLabel;
|
||||
$this->sValueId = null;
|
||||
if (!is_null($oValue)) {
|
||||
$this->AddSubBlock($oValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLayout(): ?string
|
||||
{
|
||||
return $this->sLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLayout
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLayout(string $sLayout)
|
||||
{
|
||||
$this->sLayout = $sLayout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttCode(): ?string
|
||||
{
|
||||
return $this->sAttCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttCode(string $sAttCode)
|
||||
{
|
||||
$this->sAttCode = $sAttCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttType(): ?string
|
||||
{
|
||||
return $this->sAttType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttType(string $sAttType)
|
||||
{
|
||||
$this->sAttType = $sAttType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttLabel(): ?string
|
||||
{
|
||||
return $this->sAttLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttLabel(string $sAttLabel)
|
||||
{
|
||||
$this->sAttLabel = $sAttLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsReadOnly(): bool
|
||||
{
|
||||
return $this->bIsReadOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsReadOnly
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsReadOnly(bool $bIsReadOnly)
|
||||
{
|
||||
$this->bIsReadOnly = $bIsReadOnly;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMandatory(): bool
|
||||
{
|
||||
return $this->bIsMandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMandatory
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsMandatory(bool $bIsMandatory)
|
||||
{
|
||||
$this->bIsMandatory = $bIsMandatory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMustChange(): bool
|
||||
{
|
||||
return $this->bMustChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMustChange
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMustChange(bool $bIsMustChange)
|
||||
{
|
||||
$this->bMustChange = $bIsMustChange;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMustPrompt(): bool
|
||||
{
|
||||
return $this->bMustPrompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMustPrompt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMustPrompt(bool $bIsMustPrompt)
|
||||
{
|
||||
$this->bMustPrompt = $bIsMustPrompt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSlave(): bool
|
||||
{
|
||||
return $this->bIsSlave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsSlave
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsSlave(bool $bIsSlave)
|
||||
{
|
||||
$this->bIsSlave = $bIsSlave;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValueRaw(): ?string
|
||||
{
|
||||
return $this->sValueRaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValueRaw
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValueRaw(string $sValueRaw)
|
||||
{
|
||||
$this->sValueRaw = $sValueRaw;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel(string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\UIBlock
|
||||
*/
|
||||
public function GetValue()
|
||||
{
|
||||
return $this->oValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oValue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValue(UIBlock $oValue)
|
||||
{
|
||||
$this->oValue = $oValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetComments(): ?string
|
||||
{
|
||||
return $this->sComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sComments
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetComments(string $sComments)
|
||||
{
|
||||
$this->sComments = $sComments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValueId(): ?string
|
||||
{
|
||||
return $this->sValueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sValueId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValueId(?string $sValueId)
|
||||
{
|
||||
$this->sValueId = $sValueId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function SetInputId(string $sInputId)
|
||||
{
|
||||
$this->AddDataAttribute('input-id', $sInputId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function SetInputType(string $sInputType)
|
||||
{
|
||||
$this->AddDataAttribute('input-type', $sInputType);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Field;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class FieldUIBlockFactory
|
||||
*
|
||||
* Use it to make a "field" which is composed of a label and a value (which can be read-only or editable)
|
||||
*
|
||||
* @author Pierre Goiffon <pierre.goiffon@combodo.com>
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class FieldUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIField';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Field::class;
|
||||
|
||||
public static function MakeFromParams($aParams)
|
||||
{
|
||||
$oValue = new Html($aParams['value']);
|
||||
$oField = new Field($aParams['label'], $oValue);
|
||||
|
||||
$aParamsMapping = [
|
||||
'layout' => 'SetLayout',
|
||||
'attcode' => 'SetAttCode',
|
||||
'atttype' => 'SetAttType',
|
||||
'attlabel' => 'SetAttLabel',
|
||||
'value_raw' => 'SetValueRaw',
|
||||
'comments' => 'SetComments',
|
||||
'input_id' => 'SetInputId',
|
||||
'input_type' => 'SetInputType',
|
||||
];
|
||||
foreach ($aParamsMapping as $sParamKey => $sFieldMethod) {
|
||||
self::UpdateFieldFromParams($oField, $sFieldMethod, $aParams, $sParamKey);
|
||||
}
|
||||
|
||||
if (isset($aParams['attflags'])) {
|
||||
$aParamsFlagsMapping = [
|
||||
OPT_ATT_HIDDEN => 'SetIsHidden',
|
||||
OPT_ATT_READONLY => 'SetIsReadOnly',
|
||||
OPT_ATT_MANDATORY => 'SetIsMandatory',
|
||||
OPT_ATT_MUSTCHANGE => 'SetMustChange',
|
||||
OPT_ATT_MUSTPROMPT => 'SetMustPrompt',
|
||||
OPT_ATT_SLAVE => 'SetIsSlave',
|
||||
];
|
||||
foreach ($aParamsFlagsMapping as $sConstant => $sFieldMethod) {
|
||||
self::UpdateFlagsFieldFromParams($oField, $sFieldMethod, $aParams['attflags'], $sConstant);
|
||||
}
|
||||
}
|
||||
|
||||
return $oField;
|
||||
}
|
||||
|
||||
private static function UpdateFieldFromParams($oField, $sMethodName, $aParams, $sKey): void
|
||||
{
|
||||
if (isset($aParams[$sKey])) {
|
||||
$oField->$sMethodName($aParams[$sKey]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function UpdateFlagsFieldFromParams($oField, $sMethodName, $iParamsFlags, $iConstant): void
|
||||
{
|
||||
$oField->$sMethodName((($iParamsFlags & $iConstant) === $iConstant));
|
||||
}
|
||||
|
||||
public static function MakeFromObject(string $sLabel, UIBlock $oInput, ?string $sLayout = null)
|
||||
{
|
||||
$oField = new Field($sLabel, $oInput);
|
||||
|
||||
if (!is_null($sLayout)) {
|
||||
$oField->SetLayout($sLayout);
|
||||
}
|
||||
|
||||
return $oField;
|
||||
}
|
||||
|
||||
public static function MakeLarge(string $sLabel, string $sValueHtml = '')
|
||||
{
|
||||
$oField = new Field($sLabel, new Html($sValueHtml));
|
||||
$oField->SetLayout(Field::ENUM_FIELD_LAYOUT_LARGE);
|
||||
return $oField;
|
||||
}
|
||||
|
||||
public static function MakeSmall(string $sLabel, string $sValueHtml = '')
|
||||
{
|
||||
$oField = new Field($sLabel, new Html($sValueHtml));
|
||||
$oField->SetLayout(Field::ENUM_FIELD_LAYOUT_SMALL);
|
||||
return $oField;
|
||||
}
|
||||
|
||||
public static function MakeStandard(string $sLabel = '', string $sLayout = Field::ENUM_FIELD_LAYOUT_SMALL, ?string $sId = null)
|
||||
{
|
||||
$oField = new Field($sLabel, null, $sId);
|
||||
$oField->SetLayout($sLayout);
|
||||
return $oField;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user