N°3190 - Edit n:n LinkedSetIndirect in object details using a tagset-like widget

- Add generic set block ui component
- Add model link set (direct and indirect) attribute (display style)
- Add model link set direct allowed values
- Create link set viewer block UI (BlockLinksSetDisplayAsProperty)
- Add set block ui factory for linkset
- Add object factory and create new endpoint in object controller (with data binder)
- Add link set model, link set repository and link set data transformer services
This commit is contained in:
bdalsass
2023-01-24 10:03:10 +01:00
committed by GitHub
parent 9482139b5a
commit fb1ceebaa4
55 changed files with 3948 additions and 234 deletions

View File

@@ -0,0 +1,160 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set\DataProvider;
/**
* Class AbstractDataProvider
*
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider
* @since 3.1.0
*/
abstract class AbstractDataProvider implements iDataProvider
{
/** @var string $sDataValueField Field used for input value */
private string $sDataValueField;
/** @var string $sDataLabelField Field used for label rendering */
private string $sDataLabelField;
/** @var array $aDataSearchFields Fields used for search engine */
private array $aDataSearchFields;
/** @var string|null $sGroupField Field used for grouping options */
private ?string $sGroupField;
/** @var string|null $sTooltipField Field used for item tooltip */
private ?string $sTooltipField;
/**
* Constructor.
*
*/
public function __construct()
{
// Initialization
$this->Init();
}
/**
* Initialization.
*
* @return void
*/
private function Init()
{
$this->sDataLabelField = 'label';
$this->sDataValueField = 'value';
$this->aDataSearchFields = ['search'];
$this->sGroupField = null;
$this->sTooltipField = 'label';
}
/** @inheritDoc */
public function GetDataValueField(): string
{
return $this->sDataValueField;
}
/** @inheritDoc */
public function SetDataValueField(string $sField): AbstractDataProvider
{
$this->sDataValueField = $sField;
return $this;
}
/** @inheritDoc */
public function GetDataLabelField(): string
{
return $this->sDataLabelField;
}
/** @inheritDoc */
public function SetDataLabelField(string $sField): AbstractDataProvider
{
$this->sDataLabelField = $sField;
return $this;
}
/** @inheritDoc */
public function GetDataSearchFields(): array
{
return $this->aDataSearchFields;
}
/** @inheritDoc */
public function SetDataSearchFields(array $aFields): AbstractDataProvider
{
$this->aDataSearchFields = $aFields;
return $this;
}
/** @inheritDoc */
public function GetGroupField(): ?string
{
return $this->sGroupField;
}
/** @inheritDoc */
public function SetGroupField(string $sField): iDataProvider
{
$this->sGroupField = $sField;
return $this;
}
/** @inheritDoc */
public function GetTooltipField(): ?string
{
return $this->sTooltipField;
}
/** @inheritDoc */
public function SetTooltipField(string $sField): iDataProvider
{
$this->sTooltipField = $sField;
return $this;
}
/**
* IsAjaxProviderType.
*
* @return bool
*/
public function IsAjaxProviderType(): bool
{
return $this->GetType() === iDataProvider::TYPE_AJAX_PROVIDER;
}
/**
* IsSimpleProviderType.
*
* @return bool
*/
public function IsSimpleProviderType(): bool
{
return $this->GetType() === iDataProvider::TYPE_SIMPLE_PROVIDER;
}
}

View File

@@ -0,0 +1,169 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set\DataProvider;
/**
* Class AjaxDataProvider
*
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider
* @since 3.1.0
*/
class AjaxDataProvider extends SimpleDataProvider
{
/** @var int DEFAULT_MAX_RESULTS maximum results fetched */
const DEFAULT_MAX_RESULTS = 25;
/**
* @see \Combodo\iTop\Router\Router
* @var string $sAjaxRoute Router route name
*/
private string $sRoute;
/** @var array $aParams Query string params */
private array $aParams = [];
/** @var array $aPostParams Post params */
private array $aPostParams = [];
/** @var int $iMaxResults Maximum entries */
private int $iMaxResults = AjaxDataProvider::DEFAULT_MAX_RESULTS;
/**
* Constructor.
*
* @param string $sRoute Router route name
* @param array $aParams Query string params
* @param array $aPostParams Post params
*/
public function __construct(string $sRoute, array $aParams = [], array $aPostParams = [])
{
parent::__construct();
// Retrieve parameters
$this->sRoute = $sRoute;
$this->aParams = $aParams;
$this->aPostParams = $aPostParams;
}
/** @inheritDoc */
public function GetType(): string
{
return iDataProvider::TYPE_AJAX_PROVIDER;
}
/**
* SetParam.
*
* @param string $sName
* @param string $sValue
*
* @return $this
*/
public function SetParam(string $sName, string $sValue): AjaxDataProvider
{
$this->aParams[$sName] = $sValue;
return $this;
}
/**
* GetParam.
*
* @param string $sName
*
* @return string
*/
public function GetParam(string $sName): string
{
return $this->aParams[$sName];
}
/**
* GetParams.
*
* @return array
*/
public function GetParams(): array
{
return $this->aParams;
}
/**
* GetParamsAsQueryString.
*
* @return string
*/
public function GetParamsAsQueryString(): string
{
$aFlattened = $this->aParams;
array_walk($aFlattened, function (&$sValue, $key) {
$sValue = "{$key}={$sValue}";
});
return '&'.implode('&', $aFlattened);
}
/**
* GetPostParamsAsJsonString.
*
* @return string
*/
public function GetPostParamsAsJsonString(): string
{
return json_encode($this->aPostParams);
}
/**
* SetPostParam.
*
* @param string $sName
* @param $oValue
*
* @return $this
*/
public function SetPostParam(string $sName, $oValue): AjaxDataProvider
{
$this->aPostParams[$sName] = $oValue;
return $this;
}
/**
* GetRoute.
*
* @return void
*/
public function GetRoute(): string
{
return $this->sRoute;
}
/**
* Return maximum results count.
*
* @return int
*/
public function GetMaxResults(): int
{
return $this->iMaxResults;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set\DataProvider;
/**
* Class AjaxDataProviderForOQL
*
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider
* @since 3.1.0
*/
class AjaxDataProviderForOQL extends AjaxDataProvider
{
/**
* Constructor.
*
* @param string $sObjectClass Db Object class
* @param string $sOql Oql
* @param string|null $sWizardHelperJsVarName Wizard helper name
* @param array $aFieldsToLoad Array of fields to load
*/
public function __construct(string $sObjectClass, string $sOql, string $sWizardHelperJsVarName = null, array $aFieldsToLoad = [])
{
parent::__construct('object.search', [
'object_class' => $sObjectClass,
'oql' => $sOql,
'fields_to_load' => json_encode($aFieldsToLoad),
], [
'this_object_data' => $sWizardHelperJsVarName != null ? "EVAL_JAVASCRIPT{{$sWizardHelperJsVarName}.UpdateWizardToJSON();}" : "",
]);
// Initialization
$this->Init();
}
/**
* Initialization.
*
* @return void
*/
private function Init()
{
$this->SetDataLabelField('friendlyname')
->SetDataValueField('key')
->SetDataSearchFields(['friendlyname', 'additional_field']);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set\DataProvider;
/**
* Class SimpleDataProvider
*
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider
* @since 3.1.0
*/
class SimpleDataProvider extends AbstractDataProvider
{
/** @var array $aOptions */
private array $aOptions;
/**
* Constructor.
*
* @param array $aOptions
*/
public function __construct(array $aOptions = [])
{
parent::__construct();
// retrieve parameters
$this->SetOptions($aOptions);
}
/** @inheritDoc */
public function GetType(): string
{
return iDataProvider::TYPE_SIMPLE_PROVIDER;
}
/** @inheritDoc */
public function SetOptions(array $aOptions): SimpleDataProvider
{
$this->aOptions = $aOptions;
return $this;
}
/** @inheritDoc */
public function SetOption(string $sKey, string $sValue): SimpleDataProvider
{
$this->aOptions[$sKey] = $sValue;
return $this;
}
/** @inheritDoc */
public function GetOptions(): array
{
return $this->aOptions;
}
/**
* GetOptionsGroups.
*
* @return array
*/
public function GetOptionsGroups(): array
{
$aGroups = [];
if ($this->GetGroupField() != null) {
foreach ($this->GetOptions() as $aOption) {
if (array_key_exists($this->GetGroupField(), $aOption)) {
$aGroups[$aOption[$this->GetGroupField()]] = [
'label' => $aOption[$this->GetGroupField()],
'value' => $aOption[$this->GetGroupField()],
];
}
}
}
return array_values($aGroups);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set\DataProvider;
/**
* Interface iDataProvider
*
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider
* @since 3.1.0
*/
interface iDataProvider
{
public const TYPE_AJAX_PROVIDER = "AJAX_PROVIDER";
public const TYPE_SIMPLE_PROVIDER = "SIMPLE_PROVIDER";
/**
* GetType.
*
* @return string
*/
public function GetType(): string;
/**
* SetOptions.
*
* @param array $aOptions
*
* @return $this
*/
public function SetOptions(array $aOptions): iDataProvider;
/**
* SetOption.
*
* @param string $sKey
* @param string $sValue
*
* @return $this
*/
public function SetOption(string $sKey, string $sValue): iDataProvider;
/**
* GetOptions.
*
* @return array
*/
public function GetOptions(): array;
/**
* GetDataValueField.
*
* @return string
*/
public function GetDataValueField(): string;
/**
* SetDataValueField.
*
* @param string $sField
*
* @return $this
*/
public function SetDataValueField(string $sField): iDataProvider;
/**
* GetDataLabelField.
*
* @return string
*/
public function GetDataLabelField(): string;
/**
* SetDataLabelField.
*
* @param string $sField
*
* @return $this
*/
public function SetDataLabelField(string $sField): iDataProvider;
/**
* GetDataSearchFields.
*
* @return array
*/
public function GetDataSearchFields(): array;
/**
* SetDataSearchFields.
*
* @param array $aFields
*
* @return $this
*/
public function SetDataSearchFields(array $aFields): iDataProvider;
/**
* GetGroupField.
*
* @return string|null
*/
public function GetGroupField(): ?string;
/**
* SetGroupField.
*
* @param string $sField
*
* @return $this
*/
public function SetGroupField(string $sField): iDataProvider;
/**
* GetTooltipField.
*
* @return string|null
*/
public function GetTooltipField(): ?string;
/**
* SetTooltipField.
*
* @param string $sField
*
* @return $this
*/
public function SetTooltipField(string $sField): iDataProvider;
}

View File

@@ -0,0 +1,397 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set;
use Combodo\iTop\Application\UI\Base\Component\Input\AbstractInput;
use Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider\iDataProvider;
use Dict;
/**
* Class Set
*
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set
* @since 3.1.0
*/
class Set extends AbstractInput
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-set';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/set/layout';
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/input/set/layout';
public const DEFAULT_JS_FILES_REL_PATH = [
'js/selectize/plugin_combodo_add_button.js',
'js/selectize/plugin_combodo_auto_position.js',
'js/selectize/plugin_combodo_update_operations.js',
'js/selectize/plugin_combodo_multi_values_synthesis.js',
];
/** @var int|null $iMaxItems Maximum number of items selectable */
private ?int $iMaxItems;
/** @var int|null $iMaxItem Maximum number of displayed options */
private ?int $iMaxOptions;
/** @var bool $bHasRemoveItemButton Enable remove item button */
private bool $bHasRemoveItemButton;
/** @var bool $bHasAddOptionButton Enable add option button */
private bool $bHasAddOptionButton;
/** @var string $sAddButtonTitle Add button title */
private string $sAddButtonTitle;
/** @var bool $bIsPreloadEnabled Load data at initialization (ajax data provider only) */
private bool $bIsPreloadEnabled;
/** @var string|null $sTemplateOptions Template for rendering options in dropdown (twig) */
private ?string $sTemplateOptions;
/** @var string|null $sTemplateItems Template for rendering items in input (twig) */
private ?string $sTemplateItems;
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider\iDataProvider $oDataProvider Set data provider */
private iDataProvider $oDataProvider;
/** @var bool $bIsMultiValuesSynthesis Used for bulk modify for example */
private bool $bIsMultiValuesSynthesis;
/** @var bool $bHasError Error flag */
private bool $bHasError;
/**
* Constructor.
*
* @param string|null $sId Block identifier
*/
public function __construct(string $sId = null)
{
parent::__construct($sId);
// Initialization
$this->Init();
}
/**
* Initialization.
*
* @return void
*/
private function Init()
{
$this->SetValue('[]');
// @todo BDA placeholder depending on autocomplete activation (search...., click to add...)
$this->SetPlaceholder(Dict::S('Core:AttributeSet:placeholder'));
$this->iMaxItems = null;
$this->iMaxOptions = null;
$this->bHasRemoveItemButton = true;
$this->bHasAddOptionButton = false;
$this->sAddButtonTitle = Dict::S('UI:Button:Create');
$this->bIsPreloadEnabled = false;
$this->sTemplateOptions = null;
$this->sTemplateItems = null;
$this->bIsMultiValuesSynthesis = false;
$this->bHasError = false;
}
/**
* SetMaxItems.
*
* @param int|null $iMaxItems
*
* @return $this
*/
public function SetMaxItems(?int $iMaxItems): Set
{
$this->iMaxItems = $iMaxItems;
return $this;
}
/**
* GetMaxItems.
*
* @return int|null
*/
public function GetMaxItems(): ?int
{
return $this->iMaxItems;
}
/**
* SetMaxOptions.
*
* @param int|null $iMaxOptions
*
* @return $this
*/
public function SetMaxOptions(?int $iMaxOptions): Set
{
$this->iMaxOptions = $iMaxOptions;
return $this;
}
/**
* GetMaxOptions.
*
* @return int|null
*/
public function GetMaxOptions(): ?int
{
return $this->iMaxOptions;
}
/**
* SetHasRemoveItemButton.
*
* @param bool $bHasRemoveItemButton
*
* @return $this
*/
public function SetHasRemoveItemButton(bool $bHasRemoveItemButton): Set
{
$this->bHasRemoveItemButton = $bHasRemoveItemButton;
return $this;
}
/**
* HasRemoveItemButton.
*
* @return bool
*/
public function HasRemoveItemButton(): bool
{
return $this->bHasRemoveItemButton;
}
/**
* SetHasAddOptionButton.
*
* @param bool $bHasAddOptionButton
*
* @return $this
*/
public function SetHasAddOptionButton(bool $bHasAddOptionButton): Set
{
$this->bHasAddOptionButton = $bHasAddOptionButton;
return $this;
}
/**
* HasAddOptionButton.
*
* @return bool
*/
public function HasAddOptionButton(): bool
{
return $this->bHasAddOptionButton;
}
/**
* GetAddButtonTitle.
*
* @return string
*/
public function GetAddButtonTitle(): string
{
return $this->sAddButtonTitle;
}
/**
* SetAddButtonTitle.
*
* @param string $sTitle
*
* @return $this
*/
public function SetAddButtonTitle(string $sTitle): Set
{
$this->sAddButtonTitle = $sTitle;
return $this;
}
/**
* SetPreloadEnabled.
*
* @param bool $bEnabled
*
* @return $this
*/
public function SetPreloadEnabled(bool $bEnabled): Set
{
$this->bIsPreloadEnabled = $bEnabled;
return $this;
}
/**
* IsPreloadEnabled.
*
* @return bool
*/
public function IsPreloadEnabled(): bool
{
return $this->bIsPreloadEnabled;
}
/**
* SetOptionsTemplate.
*
* @param string $sTemplate
*
* @return $this
*/
public function SetOptionsTemplate(string $sTemplate): Set
{
$this->sTemplateOptions = $sTemplate;
return $this;
}
/**
* Return options template.
*
* @return string
*/
public function GetOptionsTemplate(): ?string
{
return $this->sTemplateOptions;
}
/**
* HasOptionsTemplate.
*
* @return bool
*/
public function HasOptionsTemplate(): bool
{
return $this->sTemplateOptions != null;
}
/**
* SetItemsTemplate.
*
* @param string $sTemplate
*
* @return $this
*/
public function SetItemsTemplate(string $sTemplate): Set
{
$this->sTemplateItems = $sTemplate;
return $this;
}
/**
* Return items template.
*
* @return string
*/
public function GetItemsTemplate(): ?string
{
return $this->sTemplateItems;
}
/**
* HasItemsTemplate.
*
* @return bool
*/
public function HasItemsTemplate(): bool
{
return $this->sTemplateItems != null;
}
/**
* SetDataProvider.
*
* @param \Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider\iDataProvider $oDataProvider
*
* @return $this
*/
public function SetDataProvider(iDataProvider $oDataProvider): Set
{
$this->oDataProvider = $oDataProvider;
return $this;
}
/**
* Get data provider.
*
* @return iDataProvider
*/
public function GetDataProvider(): iDataProvider
{
return $this->oDataProvider;
}
/**
* SetIsMultiValuesSynthesis.
*
* @param bool $bIsMultiValuesSynthesis
*
* @return $this
*/
public function SetIsMultiValuesSynthesis(bool $bIsMultiValuesSynthesis): Set
{
$this->bIsMultiValuesSynthesis = $bIsMultiValuesSynthesis;
return $this;
}
/**
* IsMultiValuesSynthesis.
*
* @return bool
*/
public function IsMultiValuesSynthesis(): bool
{
return $this->bIsMultiValuesSynthesis;
}
/**
* SetHasError.
*
* @param $bHasError
*
* @return $this
*/
public function SetHasError($bHasError): Set
{
$this->bHasError = $bHasError;
return $this;
}
/**
* HasError.
*
* @return bool
*/
public function HasError(): bool
{
return $this->bHasError;
}
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* Copyright (C) 2013-2022 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\Component\Input\Set;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider\AjaxDataProvider;
use Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider\AjaxDataProviderForOQL;
use Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider\SimpleDataProvider;
/**
* Class SetUIBlockFactory
*
* @api
*
* @since 3.1.0
* @package Combodo\iTop\Application\UI\Base\Component\Input\Set
*/
class SetUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UISet';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = Set::class;
/**
* MakeForSimple.
*
* Create a simple set base on a static array of options.
* Options array must contain label, value and search string for each option.
* Keys for each entry must be provided but can be the same.
* If a group field is provided, options will be grouped according to this setting.
*
* @param string $sId Block identifier
* @param array $aOptions Array containing options
* @param string $sLabelFields Field used for label rendering
* @param string $sValueField Field used for option value
* @param array $aSearchFields Fields used for searching
* @param string|null $sGroupField Field used for grouping
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Set\Set
*/
public static function MakeForSimple(string $sId, array $aOptions, string $sLabelFields, string $sValueField, array $aSearchFields, ?string $sGroupField = null): Set
{
// Create set ui block
$oSetUIBlock = new Set($sId);
// Simple data provider
$oDataProvider = new SimpleDataProvider($aOptions);
$oDataProvider
->SetDataLabelField($sLabelFields)
->SetDataValueField($sValueField)
->SetDataSearchFields($aSearchFields)
->SetTooltipField($sLabelFields);
if ($sGroupField != null) {
$oDataProvider->SetGroupField($sGroupField);
}
$oSetUIBlock->SetDataProvider($oDataProvider);
return $oSetUIBlock;
}
/**
* MakeForAjax.
*
* Create a dynamic set base on options provided by ajax call.
* Options array must contain label, value and search string for each option.
* Keys for each entry must be provided but can be the same.
* If a group field is provided, options will be grouped according to this setting.
*
* @param string $sId Block identifier
* @param string $sAjaxRoute Ajax route @see \Combodo\iTop\Router\Router
* @param array $aAjaxRouteParams Url query parameters
* @param string $sLabelFields Field used for label
* @param string $sValueField Field used for value
* @param array $aSearchFields Fields used for search
* @param string|null $sGroupField Field used for grouping
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Set\Set
*/
public static function MakeForAjax(string $sId, string $sAjaxRoute, array $aAjaxRouteParams, string $sLabelFields, string $sValueField, array $aSearchFields, ?string $sGroupField = null): Set
{
// Create set ui block
$oSetUIBlock = new Set($sId);
// Ajax data provider
$oDataProvider = new AjaxDataProvider($sAjaxRoute, $aAjaxRouteParams);
$oDataProvider
->SetDataLabelField($sLabelFields)
->SetDataValueField($sValueField)
->SetDataSearchFields($aSearchFields)
->SetTooltipField($sLabelFields);
if ($sGroupField != null) {
$oDataProvider->SetGroupField($sGroupField);
}
$oSetUIBlock->SetDataProvider($oDataProvider);
return $oSetUIBlock;
}
/**
* MakeForOQL.
*
* Create a oql set base on options provided by OQL call.
* Options array must contain label, value and search string for each option.
* Keys for each entry must be provided but can be the same.
* If a group field is provided, options will be grouped according to this setting.
* Default fields are loaded but you can request more.
*
* @param string $sId Block identifier
* @param string $sObjectClass Object class
* @param string $sOql OQL to query objects
* @param string|null $sWizardHelperJsVarName Wizard helper name
* @param array $aFieldsToLoad Additional fields to load on objects
* @param string|null $sGroupField Field used for grouping
*
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Set\Set
*/
public static function MakeForOQL(string $sId, string $sObjectClass, string $sOql, string $sWizardHelperJsVarName = null, array $aFieldsToLoad = [], ?string $sGroupField = null): Set
{
// Create set ui block
$oSetUIBlock = new Set($sId);
// Renderers
$oSetUIBlock->SetOptionsTemplate('application/object/set/option_renderer.html.twig');
$oSetUIBlock->SetItemsTemplate('application/object/set/item_renderer.html.twig');
// OQL data provider
$oDataProvider = new AjaxDataProviderForOQL($sObjectClass, $sOql, $sWizardHelperJsVarName, $aFieldsToLoad);
if ($sGroupField != null) {
$oDataProvider->SetGroupField($sGroupField);
}
$oDataProvider->SetTooltipField('full_description');
$oSetUIBlock->SetDataProvider($oDataProvider);
return $oSetUIBlock;
}
}