N°4621 Fix naming inconsistencies in sources/*

This commit is contained in:
Pierre Goiffon
2021-12-31 15:21:08 +01:00
parent 16142bd979
commit 5f575d524a
192 changed files with 384 additions and 380 deletions

View File

@@ -0,0 +1,79 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
abstract class AbstractInput extends UIBlock
{
public const BLOCK_CODE = 'ibo-input';
/** @var string */
protected $sName;
/** @var string */
protected $sValue;
/**@var string */
protected $sPlaceholder;
public function GetName(): string
{
return $this->sName;
}
/**
* @param string $sName
*
* @return $this
*/
public function SetName(string $sName)
{
$this->sName = $sName;
return $this;
}
public function GetValue(): ?string
{
return $this->sValue;
}
/**
* @param string|null $sValue
*
* @return $this
*/
public function SetValue(?string $sValue)
{
$this->sValue = $sValue;
return $this;
}
/**
* @return string
*/
public function GetPlaceholder(): ?string
{
return $this->sPlaceholder;
}
/**
* @param string $sPlaceholder
*
* @return $this
*/
public function SetPlaceholder(string $sPlaceholder)
{
$this->sPlaceholder = $sPlaceholder;
return $this;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\FileSelect;
use Combodo\iTop\Application\UI\Base\UIBlock;
use Dict;
class FileSelect extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-input-file-select';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/file-select/layout';
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/input/file-select/layout';
/** @var string */
private $sName;
/** @var string */
private $sFileName;
/** @var string */
private $sButtonText;
/** @var bool */
private $bShowFilename;
public function __construct(string $sName, string $sId = null)
{
parent::__construct($sId);
$this->sName = $sName;
$this->sFileName = Dict::S('UI:InputFile:NoFileSelected');
$this->sButtonText = Dict::S('UI:InputFile:SelectFile');
$this->bShowFilename = true;
}
/**
* @return string
*/
public function GetFileName(): string
{
return $this->sFileName;
}
/**
* @param mixed $sFileName
*
* @return $this
*/
public function SetFileName($sFileName)
{
$this->sFileName = $sFileName;
return $this;
}
/**
* @return string
*/
public function GetButtonText(): string
{
return $this->sButtonText;
}
/**
* @param string $sButtonText
*
* @return $this
*/
public function SetButtonText(string $sButtonText)
{
$this->sButtonText = $sButtonText;
return $this;
}
/**
* @return string
*/
public function GetName(): string
{
return $this->sName;
}
/**
* @param bool $bShowFilename
*
* @return $this
*/
public function SetShowFilename(bool $bShowFilename)
{
$this->bShowFilename = $bShowFilename;
return $this;
}
/**
* @return bool
*/
public function GetShowFilename(): bool
{
return $this->bShowFilename;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\FileSelect;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
* Class FileSelectUIBlockFactory
*
* @author Eric Espie <eric.espie@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Input\FileSelect
* @since 3.0.0
* @api
*/
class FileSelectUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UIFileSelect';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = FileSelect::class;
/**
* @param string $sName
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\FileSelect\FileSelect A styled file input selector
*/
public static function MakeStandard(string $sName, string $sId = null)
{
return new FileSelect($sName, $sId);
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* Class Input
*
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
class Input extends AbstractInput
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-input';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/layout';
public const INPUT_HIDDEN = 'hidden';
protected $bIsChecked = false;
protected $bIsDisabled = false;
protected $bIsReadonly = false;
protected $sLabel = null;
/** @var string */
protected $sType;
public function GetType(): string
{
return $this->sType;
}
/**
* @param string $sType
*
* @return $this
*/
public function SetType(string $sType)
{
$this->sType = $sType;
return $this;
}
/**
* @param $bChecked
*
* @return $this
*/
public function SetIsChecked($bIsChecked)
{
$this->bIsChecked = $bIsChecked;
return $this;
}
/**
* @return bool
*/
public function IsChecked(): bool
{
return $this->bIsChecked;
}
/**
* @return bool
*/
public function IsDisabled(): bool
{
return $this->bIsDisabled;
}
/**
* @param bool $bIsDisabled
*
* @return $this
*/
public function SetIsDisabled(bool $bIsDisabled)
{
$this->bIsDisabled = $bIsDisabled;
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 string|null
*/
public function GetLabel(): ?string
{
return $this->sLabel;
}
/**
* @param null $sLabel
*
* @return $this
*/
public function SetLabel($sLabel)
{
$this->sLabel = $sLabel;
return $this;
}
public function HasLabel(): bool
{
return !is_null($this->sLabel);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Field\Field;
/**
* Class InputUIBlockFactory
*
* @author Eric Espie <eric.espie@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Input
* @since 3.0.0
* @internal
*/
class InputUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UIInput';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = Input::class;
public static function MakeForHidden(string $sName, string $sValue, ?string $sId = null)
{
$oInput = new Input($sId);
$oInput->SetType(Input::INPUT_HIDDEN)
->SetName($sName)
->SetValue($sValue);
return $oInput;
}
public static function MakeStandard(string $sType, string $sName, string $sValue, ?string $sId = null)
{
$oInput = new Input($sId);
$oInput->SetType($sType)
->SetName($sName)
->SetValue($sValue);
return $oInput;
}
/**
* @see Field component that is better adapter when dealing with a standard iTop form
*
* @param string $sLabel
* @param string $sInputName
* @param string|null $sInputValue
* @param string|null $sInputId
* @param string $sInputType
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\InputWithLabel
*/
public static function MakeForInputWithLabel(
string $sLabel, string $sInputName, ?string $sInputValue = null,
?string $sInputId = null, string $sInputType = 'type'
)
{
$oInput = new Input($sInputId);
$oInput->SetType($sInputType);
$oInput->SetValue($sInputValue);
return static::MakeInputWithLabel($sInputName, $sLabel, $oInput, $sInputId);
}
private static function MakeInputWithLabel(string $sName, string $sLabel, Input $oInput, ?string $sId = null)
{
$oInput->SetName($sName);
if (is_null($sId)) {
$sId = $oInput->GetId();
}
return new InputWithLabel($sLabel, $oInput, $sId);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* You might want to use a {@link \Combodo\iTop\Application\UI\Base\Component\Field\Field} component instead...
*
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
class InputWithLabel extends UIBlock
{
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/inputwithlabel';
/** @var string */
protected $sLabel;
/** @var \Combodo\iTop\Application\UI\Base\UIBlock */
protected $oInput;
/** @var bool Label before input ? */
protected $bBeforeInput;
/**
* @param string $sLabel
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oInput
* @param string|null $sId
*/
public function __construct(string $sLabel, UIBlock $oInput, ?string $sId)
{
parent::__construct($sId);
$this->sLabel = $sLabel;
$this->oInput = $oInput;
$this->bBeforeInput = true;
}
/**
* @return UIBlock
*/
public function GetInput()
{
return $this->oInput;
}
/**
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oInput
*
* @return $this
*/
public function SetInput(UIBlock $oInput)
{
$this->oInput = $oInput;
return $this;
}
/**
* @param bool $bBeforeInput
*
* @return $this
*/
public function SetBeforeInput(bool $bBeforeInput)
{
$this->bBeforeInput = $bBeforeInput;
if ($bBeforeInput) {
$this->oInput->AddCSSClass('ibo-input--label-left');
} else {
$this->oInput->AddCSSClass('ibo-input--label-right');
}
return $this;
}
/**
* @return bool
*/
public function IsLabelBefore(): bool
{
return $this->bBeforeInput;
}
/**
* @return string
*/
public function GetLabel(): string
{
return $this->sLabel;
}
/**
* @param string $sLabel
*
* @return InputWithLabel
*/
public function SetLabel(string $sLabel)
{
$this->sLabel = $sLabel;
return $this;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\RichText;
use Combodo\iTop\Application\UI\Base\UIBlock;
use utils;
/**
* Class RichText
*
* @package Combodo\iTop\Application\UI\Base\Component\RichText
*/
class RichText extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-richtext';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
public const DEFAULT_JS_FILES_REL_PATH = [
'js/ckeditor/ckeditor.js',
'js/ckeditor/adapters/jquery.js',
'js/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js',
'js/ckeditor.on-init.js',
];
public const DEFAULT_CSS_FILES_REL_PATH = [
'js/ckeditor/plugins/codesnippet/lib/highlight/styles/obsidian.css',
];
/** @var string|null */
protected $sValue;
/** @var array Configuration parameters for the CKEditor instance used with Richtext block */
protected $aConfig;
/**
* RichText constructor.
*
* @param string|null $sId
*/
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->sValue = null;
$this->aConfig = utils::GetCkeditorPref();
}
/**
* @see static::$sValue
* @return string|null
*/
public function GetValue(): ?string
{
return $this->sValue;
}
/**
* @param string|null $sValue
* @see static::$sValue
*
* @return $this
*/
public function SetValue(?string $sValue)
{
$this->sValue = $sValue;
return $this;
}
/**
* @param array $aConfig
* @see static::$aConfig
*
* @return $this
*/
public function SetConfig(array $aConfig)
{
$this->aConfig = $aConfig;
return $this;
}
/**
* @see static::$aConfig
* @return array
*/
public function GetConfig(): array
{
return $this->aConfig;
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\Component\Input\tInputLabel;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
class Select extends UIContentBlock
{
use tInputLabel;
// Overloaded constants
public const BLOCK_CODE = 'ibo-select';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/select/select';
/** @var string Input name for the form */
protected $sName;
/** @var bool if true submit the form as soon as a change is detected */
protected $bSubmitOnChange = false;
/** @var bool Allow multiple selection */
protected $bIsMultiple = false;
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->bIsMultiple = false;
}
/**
* @param SelectOption $oOption Select option UIBlock
*/
public function AddOption(SelectOption $oOption)
{
$this->AddSubBlock($oOption);
}
public function GetName(): string
{
return $this->sName;
}
/**
* @param string $sName {@see Select::$sName}
*
* @return $this
*/
public function SetName(string $sName)
{
$this->sName = $sName;
return $this;
}
/**
* @return bool {@see Select::$bSubmitOnChange}
*/
public function GetSubmitOnChange(): bool
{
return $this->bSubmitOnChange;
}
/**
* @param bool $bSubmitOnChange {@see Select::$bSubmitOnChange}
*
* @return $this
*/
public function SetSubmitOnChange(bool $bSubmitOnChange)
{
$this->bSubmitOnChange = $bSubmitOnChange;
return $this;
}
/**
* @return bool {@see Select::$bIsMultiple}
*/
public function IsMultiple(): bool
{
return $this->bIsMultiple;
}
/**
* @param bool $bIsMultiple {@see Select::$bIsMultiple}
*/
public function SetIsMultiple(bool $bIsMultiple)
{
$this->bIsMultiple = $bIsMultiple;
return $this;
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\UIBlock;
class SelectOption extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-select-option';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/select/selectoption';
/** @var string */
protected $sValue;
/** @var string */
protected $sLabel;
/** @var bool */
protected $bSelected;
/** @var bool */
protected $bDisabled;
/**
* @return string
*/
public function GetValue(): string
{
return $this->sValue;
}
/**
* @param string $sValue
*
* @return SelectOption
*/
public function SetValue(string $sValue)
{
$this->sValue = $sValue;
return $this;
}
/**
* @return string
*/
public function GetLabel(): string
{
return $this->sLabel;
}
/**
* @param string $sLabel
*
* @return SelectOption
*/
public function SetLabel(string $sLabel)
{
$this->sLabel = $sLabel;
return $this;
}
/**
* @return bool
*/
public function IsSelected(): bool
{
return $this->bSelected;
}
/**
* @param bool $bSelected
*
* @return SelectOption
*/
public function SetSelected(bool $bSelected)
{
$this->bSelected = $bSelected;
return $this;
}
/**
* @return bool
*/
public function IsDisabled(): bool
{
return $this->bDisabled;
}
/**
* @param bool $bDisabled
*
* @return $this
*/
public function SetDisabled(bool $bDisabled)
{
$this->bDisabled = $bDisabled;
return $this;
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
* Class SelectOptionUIBlockFactory
*
* @author Eric Espie <eric.espie@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Input\Select
* @since 3.0.0
* @internal
*/
class SelectOptionUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UISelectOption';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = SelectOption::class;
public static function MakeForSelectOption(string $sValue, string $sLabel, bool $bSelected, ?string $sId = null)
{
$oInput = new SelectOption($sId);
$oInput->SetValue($sValue)
->SetLabel($sLabel)
->SetSelected($bSelected)
->SetDisabled(false);
return $oInput;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
/**
* Class SelectUIBlockFactory
*
* @author Eric Espie <eric.espie@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Input
* @since 3.0.0
* @internal
*/
class SelectUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UISelect';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = Select::class;
/**
* Create a default Select input
*
* @param string $sName {@see Select::$sName}
* @param string|null $sId {@see UIBlock::$sId}
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Select\Select
*/
public static function MakeForSelect(string $sName, ?string $sId = null)
{
$oInput = new Select($sId);
$oInput->SetName($sName);
return $oInput;
}
/**
* Create a Select input with a label
*
* If you need to have a real field with a label, you might use a {@link Field} component instead
*
* @param string $sName {@see Select::$sName}
* @param string $sLabel {@see Select::$sLabel}
* @param string|null $sId {@see UIBlock::$sId}
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Select\Select
*/
public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null)
{
$oInput = new Select($sId);
$oInput->SetName($sName);
$oInput->SetLabel($sLabel);
return $oInput;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
class TextArea extends AbstractInput
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-textarea';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/input-textarea';
/** @var int */
protected $iCols;
/** @var int */
protected $iRows;
/** @var bool */
protected $bIsDisabled;
public function __construct(string $sName, ?string $sValue, ?string $sId = null, ?int $iCols = null, ?int $iRows = null)
{
parent::__construct($sId);
$this->sName = $sName;
$this->sValue = $sValue;
$this->iCols = $iCols;
$this->iRows = $iRows;
$this->bIsDisabled = false;
}
public function GetCols(): ?int
{
return $this->iCols;
}
/**
* @param int $iCols
*
* @return $this
*/
public function SetCols(int $iCols)
{
$this->iCols = $iCols;
return $this;
}
public function GetRows(): ?int
{
return $this->iRows;
}
/**
* @param int $iRows
*
* @return $this
*/
public function SetRows(int $iRows)
{
$this->iRows = $iRows;
return $this;
}
/**
* @return bool
*/
public function IsDisabled(): bool
{
return $this->bIsDisabled;
}
/**
* @param bool $bIsDisabled
*
* @return $this
*/
public function SetIsDisabled(bool $bIsDisabled)
{
$this->bIsDisabled = $bIsDisabled;
return $this;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* Trait tInputLabel Label for input
*
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
trait tInputLabel
{
/** @var bool If true the label will be positioned before the input */
protected $bIsLabelBefore = true;
/** @var string|null Label to display with the input (null for no label) */
protected $sLabel = null;
/**
* @return bool
*/
public function IsLabelBefore(): bool
{
return $this->bIsLabelBefore;
}
/**
* @param bool $bIsLabelBefore {@see tInputLabel::$bIsLabelBefore}
*
* @return $this
*/
public function SetIsLabelBefore(bool $bIsLabelBefore)
{
$this->bIsLabelBefore = $bIsLabelBefore;
if ($this->bIsLabelBefore) {
$this->AddCSSClass('ibo-input--label-left');
$this->RemoveCSSClass('ibo-input--label-right');
} else {
$this->AddCSSClass('ibo-input--label-right');
$this->RemoveCSSClass('ibo-input--label-left');
}
return $this;
}
/**
* @return string|null
*/
public function GetLabel(): ?string
{
return $this->sLabel;
}
/**
* @param string|null $sLabel {@see tInputLabel::$sLabel}
*
* @return $this
*/
public function SetLabel(?string $sLabel)
{
$this->sLabel = $sLabel;
if (!is_null($sLabel)) {
if ($this->bIsLabelBefore) {
$this->AddCSSClass('ibo-input--label-left');
$this->RemoveCSSClass('ibo-input--label-right');
} else {
$this->AddCSSClass('ibo-input--label-right');
$this->RemoveCSSClass('ibo-input--label-left');
}
} else {
$this->RemoveCSSClass('ibo-input--label-right');
$this->RemoveCSSClass('ibo-input--label-left');
}
return $this;
}
/**
* @return bool
*/
public function HasLabel(): bool
{
return $this->sLabel != null;
}
}