N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -117,7 +118,7 @@ class Branding
*/
public static function GetLogoAbsoluteUrl($sType = self::DEFAULT_LOGO_TYPE)
{
return self::GetLogoPath($sType, utils::GetAbsoluteUrlAppRoot(), utils::GetAbsoluteUrlModulesRoot()).'?t='.utils::GetCacheBusterTimestamp();
return self::GetLogoPath($sType, utils::GetAbsoluteUrlAppRoot(), utils::GetAbsoluteUrlModulesRoot()).'?t='.utils::GetCacheBusterTimestamp();
}
/**
@@ -215,4 +216,4 @@ class Branding
{
return static::GetLogoAbsoluteUrl(static::ENUM_LOGO_TYPE_LOGIN_FAVICON);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -20,7 +21,7 @@ use Combodo\iTop\Service\Events\iEventServiceSetup;
class ApplicationEvents implements iEventServiceSetup
{
// Startup events
const APPLICATION_EVENT_METAMODEL_STARTED = 'APPLICATION_EVENT_METAMODEL_STARTED';
public const APPLICATION_EVENT_METAMODEL_STARTED = 'APPLICATION_EVENT_METAMODEL_STARTED';
/**
* @inheritDoc
@@ -33,6 +34,7 @@ class ApplicationEvents implements iEventServiceSetup
'The MetaModel is fully started',
'',
[],
'application'));
'application'
));
}
}
}

View File

@@ -37,7 +37,7 @@ class CKEditorHelper
*
* @return array
*/
public static function GetCkeditorConfiguration(bool $bWithMentions, ?string $sInitialValue, array $aOverloadConfiguration = []) : array
public static function GetCkeditorConfiguration(bool $bWithMentions, ?string $sInitialValue, array $aOverloadConfiguration = []): array
{
// Extract language from user preferences
$sLanguageCountry = trim(UserRights::GetUserLanguage());
@@ -45,25 +45,24 @@ class CKEditorHelper
$aSanitizerConfiguration = self::GetDOMSanitizerForCKEditor();
// configuration
$aConfiguration = array(
$aConfiguration = [
'language' => $sLanguage,
'maximize' => [],
'detectChanges' => [
'initialValue' => $sInitialValue
'initialValue' => $sInitialValue,
],
'objectShortcut' => [
'buttonLabel' => Dict::S('UI:ObjectShortcutInsert')
'buttonLabel' => Dict::S('UI:ObjectShortcutInsert'),
],
'htmlSupport' => $aSanitizerConfiguration,
);
];
// Mentions
if($bWithMentions){
try{
if ($bWithMentions) {
try {
$aMentionConfiguration = self::GetMentionConfiguration();
$aConfiguration['mention'] = $aMentionConfiguration;
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -78,7 +77,7 @@ class CKEditorHelper
* @return array|array[]
* @throws \Exception
*/
private static function GetMentionConfiguration() : array
private static function GetMentionConfiguration(): array
{
// initialize feeds
$aMentionConfiguration = ['feeds' => []];
@@ -87,7 +86,7 @@ class CKEditorHelper
$aMentionsAllowedClasses = MetaModel::GetConfig()->Get('mentions.allowed_classes');
// iterate throw classes...
foreach($aMentionsAllowedClasses as $sMentionMarker => $sMentionScope) {
foreach ($aMentionsAllowedClasses as $sMentionMarker => $sMentionScope) {
// Retrieve mention class
// - First test if the conf is a simple data model class
@@ -108,7 +107,7 @@ class CKEditorHelper
'minimumCharacters' => MetaModel::GetConfig()->Get('min_autocomplete_chars'),
'feed_type' => 'ajax',
'feed_ajax_options' => [
'url' => utils::GetAbsoluteUrlAppRoot(). "pages/ajax.render.php?route=object.search_for_mentions&marker=".urlencode($sMentionMarker)."&needle=",
'url' => utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?route=object.search_for_mentions&marker=".urlencode($sMentionMarker)."&needle=",
'throttle' => 500,
'marker' => $sMentionMarker,
],
@@ -127,12 +126,12 @@ class CKEditorHelper
*
* @return string|null
*/
public static function PrepareCKEditorValueTextEncodingForTextarea(string $sValue = null) : ?string
public static function PrepareCKEditorValueTextEncodingForTextarea(string $sValue = null): ?string
{
if($sValue === null){
if ($sValue === null) {
return null;
}
return str_replace( '&', '&amp;', $sValue );
return str_replace('&', '&amp;', $sValue);
}
/**
@@ -150,10 +149,9 @@ class CKEditorHelper
{
// link CKEditor JS files
foreach (static::GetJSFilesRelPathsForCKEditor() as $sFile) {
try{
try {
$oPage->LinkScriptFromAppRoot($sFile);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -166,12 +164,11 @@ class CKEditorHelper
$oPage->add_ready_script("CombodoCKEditorHandler.CreateInstance('#$sInputElementId', $sConfigJS)");
// handle mentions template
if($bWithMentions){
try{
if ($bWithMentions) {
try {
$sMentionTemplate = self::GetMentionsTemplate($sInputElementId);
$oPage->add($sMentionTemplate);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -193,12 +190,11 @@ class CKEditorHelper
public static function ConfigureCKEditorElementForRenderingOutput(RenderingOutput $oOutput, string $sInputElementId, string $sInitialValue = null, bool $bWithMentions = false, bool $bAddJSFiles = true, array $aOverloadConfiguration = []): void
{
// link CKEditor JS files
if($bAddJSFiles){
if ($bAddJSFiles) {
foreach (static::GetJSFilesRelPathsForCKEditor() as $sFile) {
try{
try {
$oOutput->AddJsFile($sFile);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -212,12 +208,11 @@ class CKEditorHelper
$oOutput->AddJs("CombodoCKEditorHandler.CreateInstance('#$sInputElementId', $sConfigJS)");
// mentions template
if($bWithMentions){
try{
if ($bWithMentions) {
try {
$sMentionTemplate = self::GetMentionsTemplate($sInputElementId);
$oOutput->add($sMentionTemplate);
}
catch(Exception $e){
} catch (Exception $e) {
ExceptionLog::LogException($e);
}
}
@@ -256,7 +251,7 @@ HTML;
'node_modules/ckeditor5-itop-build/build/ckeditor.js',
'js/highlight/highlight.min.js',
'js/ckeditor.handler.js',
'js/ckeditor.feeds.js'
'js/ckeditor.feeds.js',
];
// add CKEditor translations resource
@@ -267,13 +262,12 @@ HTML;
// add corresponding ckeditor language file
// P1 language + country
// P2 language
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/' . $sLanguage . '-' . $sCountry . '.js';
if(file_exists(APPROOT . $sLanguageFileRelPath)){
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/'.$sLanguage.'-'.$sCountry.'.js';
if (file_exists(APPROOT.$sLanguageFileRelPath)) {
$aJSRelPaths[] = $sLanguageFileRelPath;
}
else {
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/' . $sLanguage . '.js';
if(file_exists(APPROOT . $sLanguageFileRelPath)){
} else {
$sLanguageFileRelPath = 'node_modules/ckeditor5-itop-build/build/translations/'.$sLanguage.'.js';
if (file_exists(APPROOT.$sLanguageFileRelPath)) {
$aJSRelPaths[] = $sLanguageFileRelPath;
}
}
@@ -288,26 +282,26 @@ HTML;
* @throws \ConfigException
* @throws \CoreException
*/
public static function GetDOMSanitizerForCKEditor(DOMSanitizer $oSanitizer = null) : array
public static function GetDOMSanitizerForCKEditor(DOMSanitizer $oSanitizer = null): array
{
if($oSanitizer === null) {
if ($oSanitizer === null) {
/* @var $oSanitizer DOMSanitizer */
$sSanitizerClass = utils::GetConfig()->Get('html_sanitizer');
$oSanitizer = new $sSanitizerClass();
}
$aWhitelist = [
'allow' => [],
'disallow' => []
'disallow' => [],
];
// Build the allow list
foreach ($oSanitizer->GetTagsWhiteList() as $sTag => $aAttributes) {
$aAllowedItem = [
'name' => $sTag,
'attributes' => [],
'classes' => false,
'styles' => false
'styles' => false,
];
foreach ($aAttributes as $aAttr) {
@@ -317,7 +311,7 @@ HTML;
$aAllowedItem['classes'] = true;
} elseif (isset($oSanitizer->GetAttrsWhiteList()[$aAttr])) {
$aAllowedItem['attributes'][$aAttr] = [
'pattern' => $oSanitizer->GetAttrsWhiteList()[$aAttr]
'pattern' => $oSanitizer->GetAttrsWhiteList()[$aAttr],
];
} else {
$aAllowedItem['attributes'][$aAttr] = true;
@@ -339,7 +333,7 @@ HTML;
];
foreach ($oSanitizer->GetAttrsBlackList() as $aAttr) {
$aDisallowedItem['attributes'][$aAttr] = true;
$aDisallowedItem['attributes'][$aAttr] = true;
}
if (empty($aDisallowedItem['attributes'])) {
@@ -348,7 +342,7 @@ HTML;
$aWhitelist['disallow'][] = $aDisallowedItem;
}
return $aWhitelist;
}
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Combodo\iTop\Application\Helper;
use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory;
use Dict;
use utils;
@@ -24,4 +25,4 @@ class ExportHelper
->SetIsClosable(false);
return $oAlert;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -41,7 +42,6 @@ class FormHelper
*/
public const ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED = 'Modify:Filled';
/**
* DisableAttributeBlobInputs.
*
@@ -69,7 +69,7 @@ class FormHelper
// Set attribute blobs in read only
if ($oAttDef instanceof AttributeBlob) {
$aExtraParams['fieldsFlags'][$sAttCode] = OPT_ATT_READONLY;
$aExtraParams['fieldsComments'][$sAttCode] = '&nbsp;<img src="' . $sAppRootUrl . 'images/transp-lock.png" style="vertical-align:middle" title="'.utils::EscapeHtml(Dict::S('UI:UploadNotSupportedInThisMode')).'"/>';
$aExtraParams['fieldsComments'][$sAttCode] = '&nbsp;<img src="'.$sAppRootUrl.'images/transp-lock.png" style="vertical-align:middle" title="'.utils::EscapeHtml(Dict::S('UI:UploadNotSupportedInThisMode')).'"/>';
}
}
}
@@ -93,12 +93,12 @@ class FormHelper
}
return null;
}
/**
* Returns true if the object has a mandatory attribute blob
*
*
* @see N°6861 - Display warning when creating/editing a mandatory blob in modal
*
*
* @param \DBObject $oObject
*
* @return bool
@@ -111,7 +111,7 @@ class FormHelper
/**
* Returns an Alert explaining what will happen when a mandatory attribute blob is displayed in a form
*
*
* @see N°6861 - Display warning when creating/editing a mandatory blob in modal
* @see self::ENUM_MANDATORY_BLOB_MODE_XXX
*
@@ -122,19 +122,19 @@ class FormHelper
public static function GetAlertForMandatoryAttributeBlobInputsInModal(string $sMode = self::ENUM_MANDATORY_BLOB_MODE_MODIFY_EMPTY): Alert
{
$sMessage = Dict::S('UI:Object:Modal:'.$sMode.':MandatoryAttributeBlobInputs:Warning:Text');
// If the mandatory attribute is already filled, there's no risk to make an object incomplete so we display an information level alert
if($sMode === self::ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED){
if ($sMode === self::ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED) {
return AlertUIBlockFactory::MakeForInformation('', $sMessage);
}
return AlertUIBlockFactory::MakeForWarning('', $sMessage);
}
/**
* Update flags to be sent to form with url parameters
* For now only supports "readonly" param
*
*
* @param \DBObject $oObject
* @param array $aExtraParams
*
@@ -145,21 +145,21 @@ class FormHelper
{
$aRawValues = utils::ReadParam('readonly', [], '', 'raw_data');
$sObjectClass = get_class($oObject);
if(array_key_exists('fieldsFlags', $aExtraParams) === false ) {
if (array_key_exists('fieldsFlags', $aExtraParams) === false) {
$aExtraParams['fieldsFlags'] = [];
}
if(array_key_exists('forceFieldsSubmission', $aExtraParams) === false ) {
}
if (array_key_exists('forceFieldsSubmission', $aExtraParams) === false) {
$aExtraParams['forceFieldsSubmission'] = [];
}
// - For each attribute present in readonly array in url, add a flag and mark them as to be submitted with their default value
foreach($aRawValues as $sAttCode => $sValue) {
if(MetaModel::IsValidAttCode($sObjectClass, $sAttCode)) {
foreach ($aRawValues as $sAttCode => $sValue) {
if (MetaModel::IsValidAttCode($sObjectClass, $sAttCode)) {
$aExtraParams['fieldsFlags'][$sAttCode] = array_key_exists($sAttCode, $aExtraParams['fieldsFlags']) ?
$aExtraParams['fieldsFlags'][$sAttCode] & OPT_ATT_READONLY :
OPT_ATT_READONLY;
$aExtraParams['forceFieldsSubmission'][] = $sAttCode;
}
}
@@ -167,14 +167,15 @@ class FormHelper
/**
* Get attribute flag for an object allowing to cross-check with extra flags present in a form
*
*
* @param \DBObject $oObject
* @param string $sAttCode
* @param array $aExtraFlags
*
* @return int
*/
public static function GetAttributeFlagsForObject(DBObject $oObject, string $sAttCode, array $aExtraFlags = []): int {
public static function GetAttributeFlagsForObject(DBObject $oObject, string $sAttCode, array $aExtraFlags = []): int
{
$iFlags = $oObject->GetFormAttributeFlags($sAttCode);
if (array_key_exists($sAttCode, $aExtraFlags)) {
// the caller may override some flags if needed
@@ -182,4 +183,4 @@ class FormHelper
}
return $iFlags;
}
}
}

View File

@@ -1,10 +1,10 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\Helper;
use Combodo\iTop\SessionTracker\SessionHandler;

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -74,7 +75,6 @@ class WebResourcesHelper
return CKEditorHelper::GetJSFilesRelPathsForCKEditor();
}
//---------------------------------
// D3/C3.js
//---------------------------------
@@ -140,4 +140,4 @@ class WebResourcesHelper
$oPage->LinkScriptFromAppRoot('js/jquery.mousewheel.js');
$oPage->LinkScriptFromAppRoot('js/simple_graph.js');
}
}
}

View File

@@ -16,9 +16,10 @@ use User;
* @package Combodo\iTop\Application\Newsroom
* @since 3.2.0
*/
class iTopNewsroomProvider extends NewsroomProviderBase {
public function IsApplicable(User $oUser = null){
class iTopNewsroomProvider extends NewsroomProviderBase
{
public function IsApplicable(User $oUser = null)
{
return true;
}
public function GetLabel()
@@ -43,11 +44,11 @@ class iTopNewsroomProvider extends NewsroomProviderBase {
private static function MakeURL($sRouteCode)
{
return Router::GetInstance()->GenerateUrl(iTopNewsroomController::ROUTE_NAMESPACE . '.' . $sRouteCode);
return Router::GetInstance()->GenerateUrl(iTopNewsroomController::ROUTE_NAMESPACE.'.'.$sRouteCode);
}
public function GetTTL()
{
return MetaModel::GetConfig()->Get('notifications.itop.newsroom_cache_time') * 60;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -19,10 +20,8 @@
*
*/
namespace Combodo\iTop\Application\Search\CriterionConversion;
use AttributeDate;
use AttributeDateTime;
use AttributeDefinition;
@@ -39,32 +38,26 @@ use utils;
class CriterionToOQL extends CriterionConversionAbstract
{
public static function Convert($oSearch, $aCriteria)
{
if (!empty($aCriteria['oql']))
{
if (!empty($aCriteria['oql'])) {
return $aCriteria['oql'];
}
$aRef = explode('.', $aCriteria['ref']);
$aCriteria['code'] = $aRef[1];
for($i = 0; $i < count($aRef); $i++)
{
for ($i = 0; $i < count($aRef); $i++) {
$aRef[$i] = '`'.$aRef[$i].'`';
}
$sRef = implode('.', $aRef);
if (isset($aCriteria['operator']))
{
if (isset($aCriteria['operator'])) {
$sOperator = $aCriteria['operator'];
}
else
{
} else {
$sOperator = self::OP_ALL;
}
$aMappedOperators = array(
$aMappedOperators = [
self::OP_CONTAINS => 'ContainsToOql',
self::OP_EQUALS => 'EqualsToOql',
self::OP_STARTS_WITH => 'StartsWithToOql',
@@ -77,10 +70,9 @@ class CriterionToOQL extends CriterionConversionAbstract
self::OP_IN => 'InToOql',
self::OP_MATCHES => 'MatchesToOql',
self::OP_ALL => 'AllToOql',
);
];
if (array_key_exists($sOperator, $aMappedOperators))
{
if (array_key_exists($sOperator, $aMappedOperators)) {
$sFct = $aMappedOperators[$sOperator];
return self::$sFct($oSearch, $sRef, $aCriteria);
@@ -93,9 +85,8 @@ class CriterionToOQL extends CriterionConversionAbstract
private static function GetValues($aCriteria)
{
if (!array_key_exists('values', $aCriteria))
{
return array();
if (!array_key_exists('values', $aCriteria)) {
return [];
}
return $aCriteria['values'];
@@ -103,12 +94,10 @@ class CriterionToOQL extends CriterionConversionAbstract
private static function GetValue($aValues, $iIndex)
{
if (!array_key_exists($iIndex, $aValues))
{
if (!array_key_exists($iIndex, $aValues)) {
return null;
}
if (!array_key_exists('value', $aValues[$iIndex]))
{
if (!array_key_exists('value', $aValues[$iIndex])) {
return null;
}
@@ -155,8 +144,7 @@ class CriterionToOQL extends CriterionConversionAbstract
{
$aValues = self::GetValues($aCriteria);
$sValue = self::GetValue($aValues, 0);
if (($aCriteria['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC) && ($sValue === '0'))
{
if (($aCriteria['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC) && ($sValue === '0')) {
return "({$sRef} = '0')";
}
@@ -182,10 +170,9 @@ class CriterionToOQL extends CriterionConversionAbstract
protected static function MatchesToOql($oSearch, $sRef, $aCriteria)
{
$aValues = self::GetValues($aCriteria);
$aRawValues = array();
$aRawValues = [];
$bHasUnDefined = isset($aCriteria['has_undefined']) ? $aCriteria['has_undefined'] : false;
for($i = 0; $i < count($aValues); $i++)
{
for ($i = 0; $i < count($aValues); $i++) {
$sRawValue = self::GetValue($aValues, $i);
if (!utils::StrLen($sRawValue)) {
$bHasUnDefined = true;
@@ -194,21 +181,16 @@ class CriterionToOQL extends CriterionConversionAbstract
}
}
// This allow to search for complete words
if (!empty($aRawValues))
{
if (!empty($aRawValues)) {
$sValue = implode(' ', $aRawValues).' _';
}
else
{
if ($bHasUnDefined)
{
} else {
if ($bHasUnDefined) {
return "({$sRef} = '')";
}
return "1";
}
if ($bHasUnDefined)
{
if ($bHasUnDefined) {
return "((({$sRef} MATCHES '{$sValue}') OR ({$sRef} = '')) AND 1)";
}
return "({$sRef} MATCHES '{$sValue}')";
@@ -216,10 +198,8 @@ class CriterionToOQL extends CriterionConversionAbstract
protected static function EmptyToOql($oSearch, $sRef, $aCriteria)
{
if (isset($aCriteria['widget']))
{
switch ($aCriteria['widget'])
{
if (isset($aCriteria['widget'])) {
switch ($aCriteria['widget']) {
case AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC:
case AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_FIELD:
case AttributeDefinition::SEARCH_WIDGET_TYPE_DATE:
@@ -233,10 +213,8 @@ class CriterionToOQL extends CriterionConversionAbstract
protected static function NotEmptyToOql($oSearch, $sRef, $aCriteria)
{
if (isset($aCriteria['widget']))
{
switch ($aCriteria['widget'])
{
if (isset($aCriteria['widget'])) {
switch ($aCriteria['widget']) {
case AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC:
case AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_FIELD:
case AttributeDefinition::SEARCH_WIDGET_TYPE_DATE:
@@ -266,71 +244,54 @@ class CriterionToOQL extends CriterionConversionAbstract
$sClass = $aCriteria['class'];
$aValues = self::GetValues($aCriteria);
if (count($aValues) == 0)
{
if (count($aValues) == 0) {
// Ignore when nothing is selected
return "1";
}
$oAttDef = null;
try
{
try {
$aAttributeDefs = MetaModel::ListAttributeDefs($sClass);
} catch (\CoreException $e)
{
} catch (\CoreException $e) {
return "1";
}
if (array_key_exists($sAttCode, $aAttributeDefs))
{
if (array_key_exists($sAttCode, $aAttributeDefs)) {
$oAttDef = $aAttributeDefs[$sAttCode];
}
// Hierarchical keys
$sHierarchicalKeyCode = false;
$sTargetClass = '';
if (isset($oAttDef) && $oAttDef->IsExternalKey() && ($aCriteria['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY))
{
if ($oAttDef instanceof AttributeExternalKey)
{
if (isset($oAttDef) && $oAttDef->IsExternalKey() && ($aCriteria['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY)) {
if ($oAttDef instanceof AttributeExternalKey) {
$sTargetClass = $oAttDef->GetTargetClass();
}
else
{
} else {
/** @var AttributeExternalKey $oFinalAttDef */
$oFinalAttDef = $oAttDef->GetFinalAttDef();
$sTargetClass = $oFinalAttDef->GetTargetClass();
}
try
{
try {
$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($sTargetClass);
} catch (\CoreException $e)
{
} catch (\CoreException $e) {
}
}
$sFilterOnUndefined = '';
if ($oAttDef instanceof AttributeEnum)
{
if ($oAttDef instanceof AttributeEnum) {
$aAllowedValues = SearchForm::GetFieldAllowedValues($oAttDef);
if (array_key_exists('values', $aAllowedValues))
{
if (array_key_exists('values', $aAllowedValues)) {
// Can't invert the test if NULL is allowed
if (!$oAttDef->IsNullAllowed())
{
if (!$oAttDef->IsNullAllowed()) {
$aAllowedValues = $aAllowedValues['values'];
if (count($aValues) == count($aAllowedValues))
{
if (count($aValues) == count($aAllowedValues)) {
// All entries are selected
return "1";
}
// more selected values than remaining so use NOT IN
else
{
if (count($aValues) > (count($aAllowedValues) / 2))
{
foreach($aValues as $aValue)
{
else {
if (count($aValues) > (count($aAllowedValues) / 2)) {
foreach ($aValues as $aValue) {
unset($aAllowedValues[$aValue['value']]);
}
$sInList = implode("','", array_keys($aAllowedValues));
@@ -340,11 +301,9 @@ class CriterionToOQL extends CriterionConversionAbstract
}
}
// search for "undefined"
for($i = 0; $i < count($aValues); $i++)
{
for ($i = 0; $i < count($aValues); $i++) {
$aValue = $aValues[$i];
if (isset($aValue['value']) && ($aValue['value'] === 'null'))
{
if (isset($aValue['value']) && ($aValue['value'] === 'null')) {
$sFilterOnUndefined = "ISNULL({$sRef})";
unset($aValues[$i]);
break;
@@ -353,14 +312,11 @@ class CriterionToOQL extends CriterionConversionAbstract
}
}
if ($sHierarchicalKeyCode !== false)
{
if ($sHierarchicalKeyCode !== false) {
// search for "undefined"
for($i = 0; $i < count($aValues); $i++)
{
for ($i = 0; $i < count($aValues); $i++) {
$aValue = $aValues[$i];
if (isset($aValue['value']) && ($aValue['value'] === '0'))
{
if (isset($aValue['value']) && ($aValue['value'] === '0')) {
$sFilterOnUndefined = "({$sRef} = '0')";
unset($aValues[$i]);
break;
@@ -368,28 +324,22 @@ class CriterionToOQL extends CriterionConversionAbstract
}
}
$aInValues = array();
foreach($aValues as $aValue)
{
$aInValues = [];
foreach ($aValues as $aValue) {
$aInValues[] = $aValue['value'];
}
$sInList = implode("','", $aInValues);
$sCondition = '1';
if (count($aInValues) == 1)
{
if (count($aInValues) == 1) {
$sCondition = "({$sRef} = '$sInList')";
}
elseif (count($aInValues) > 1)
{
} elseif (count($aInValues) > 1) {
$sCondition = "({$sRef} IN ('$sInList'))";
}
// Hierarchical keys
try
{
if (($sHierarchicalKeyCode !== false) && ($oSearch instanceof DBObjectSearch))
{
try {
if (($sHierarchicalKeyCode !== false) && ($oSearch instanceof DBObjectSearch)) {
// NOTE: The hierarchy does not work for unions for now. It'll be done with the full support of unions in search.
// Add all the joins for hierarchical key
$oFilter = new DBObjectSearch($sTargetClass);
@@ -404,22 +354,17 @@ class CriterionToOQL extends CriterionConversionAbstract
// Use the 'below' operator by default
$oSearch->AddCondition_PointingTo($oHKFilter, $sAttCode);
$oCriteria = $oSearch->GetCriteria();
$aArgs = MetaModel::PrepareQueryArguments(array(), $oSearch->GetInternalParams(), $oSearch->GetExpectedArguments() );
$aArgs = MetaModel::PrepareQueryArguments([], $oSearch->GetInternalParams(), $oSearch->GetExpectedArguments());
$oSearch->ResetCondition();
$sCondition = $oCriteria->RenderExpression(false, $aArgs);
}
} catch (Exception $e)
{
} catch (Exception $e) {
}
if (!empty($sFilterOnUndefined))
{
if (count($aValues) === 0)
{
if (!empty($sFilterOnUndefined)) {
if (count($aValues) === 0) {
$sCondition = $sFilterOnUndefined;
}
else
{
} else {
// Add 'AND 1' to group the 'OR' inside an AND list for OQL parsing
$sCondition = "(({$sCondition} OR {$sFilterOnUndefined}) AND 1)";
}
@@ -430,55 +375,44 @@ class CriterionToOQL extends CriterionConversionAbstract
protected static function BetweenDatesToOql($oSearch, $sRef, $aCriteria)
{
$aOQL = array();
$aOQL = [];
$aValues = self::GetValues($aCriteria);
if (count($aValues) != 2)
{
if (count($aValues) != 2) {
return "1";
}
$sWidget = $aCriteria['widget'];
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME)
{
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME) {
$sAttributeClass = AttributeDateTime::class;
}
else
{
} else {
$sAttributeClass = AttributeDate::class;
}
$oFormat = $sAttributeClass::GetFormat();
$sStartDate = $aValues[0]['value'];
if (!empty($sStartDate))
{
try
{
if (!empty($sStartDate)) {
try {
$oDate = $oFormat->parse($sStartDate);
$sStartDate = $oDate->format($sAttributeClass::GetSQLFormat());
$aOQL[] = "({$sRef} >= '$sStartDate')";
} catch (Exception $e)
{
} catch (Exception $e) {
}
}
$sEndDate = $aValues[1]['value'];
if (!empty($sEndDate))
{
try
{
if (!empty($sEndDate)) {
try {
$oDate = $oFormat->parse($sEndDate);
$sEndDate = $oDate->format($sAttributeClass::GetSQLFormat());
$aOQL[] = "({$sRef} <= '$sEndDate')";
} catch (Exception $e)
{
} catch (Exception $e) {
}
}
$sOQL = implode(' AND ', $aOQL);
if (empty($sOQL))
{
if (empty($sOQL)) {
$sOQL = "1";
}
@@ -495,41 +429,30 @@ class CriterionToOQL extends CriterionConversionAbstract
*/
protected static function BetweenToOql($oSearch, $sRef, $aCriteria)
{
$aOQL = array();
$aOQL = [];
$aValues = self::GetValues($aCriteria);
if (count($aValues) != 2)
{
if (count($aValues) != 2) {
return "1";
}
if (isset($aValues[0]['value']))
{
if (isset($aValues[0]['value'])) {
$sStartNum = trim($aValues[0]['value']);
if (is_numeric($sStartNum))
{
if (is_numeric($sStartNum)) {
$aOQL[] = "({$sRef} >= '$sStartNum')";
}
else
{
if (!empty($sStartNum))
{
} else {
if (!empty($sStartNum)) {
throw new AjaxSearchException("'$sStartNum' is not a numeric value", 400);
}
}
}
if (isset($aValues[1]['value']))
{
if (isset($aValues[1]['value'])) {
$sEndNum = trim($aValues[1]['value']);
if (is_numeric($sEndNum))
{
if (is_numeric($sEndNum)) {
$aOQL[] = "({$sRef} <= '$sEndNum')";
}
else
{
if (!empty($sEndNum))
{
} else {
if (!empty($sEndNum)) {
throw new AjaxSearchException("'$sEndNum' is not a numeric value", 400);
}
}
@@ -537,15 +460,13 @@ class CriterionToOQL extends CriterionConversionAbstract
$sOQL = implode(' AND ', $aOQL);
if (empty($sOQL))
{
if (empty($sOQL)) {
$sOQL = "1";
}
return $sOQL;
}
protected static function AllToOql($oSearch, $sRef, $aCriteria)
{
return "1";

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -25,7 +26,6 @@
namespace Combodo\iTop\Application\Search\CriterionConversion;
use AttributeDate;
use AttributeDateTime;
use AttributeDefinition;
@@ -38,7 +38,6 @@ use MetaModel;
class CriterionToSearchForm extends CriterionConversionAbstract
{
/**
* @param array $aAndCriterionRaw
* @param array $aFieldsByCategory
@@ -51,22 +50,19 @@ class CriterionToSearchForm extends CriterionConversionAbstract
*/
public static function Convert($aAndCriterionRaw, $aFieldsByCategory, $aClasses, $bIsRemovable = true)
{
$aAllFields = array();
foreach($aFieldsByCategory as $aFields)
{
if (!is_array($aFields))
{
$aAllFields = [];
foreach ($aFieldsByCategory as $aFields) {
if (!is_array($aFields)) {
continue;
}
foreach($aFields as $aField)
{
foreach ($aFields as $aField) {
$sAlias = $aField['class_alias'];
$sCode = $aField['code'];
$aAllFields["$sAlias.$sCode"] = $aField;
}
}
$aAndCriterion = array();
$aMappingOperatorToFunction = array(
$aAndCriterion = [];
$aMappingOperatorToFunction = [
AttributeDefinition::SEARCH_WIDGET_TYPE_STRING => 'TextToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_FIELD => 'ExternalFieldToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE => 'DateTimeToSearchForm',
@@ -77,112 +73,87 @@ class CriterionToSearchForm extends CriterionConversionAbstract
AttributeDefinition::SEARCH_WIDGET_TYPE_ENUM => 'EnumToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_SET => 'SetToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET => 'TagSetToSearchForm',
);
];
foreach($aAndCriterionRaw as $aCriteria)
{
if (isset($aCriteria['label']))
{
foreach ($aAndCriterionRaw as $aCriteria) {
if (isset($aCriteria['label'])) {
$aCriteria['label'] = preg_replace("@\)$@", '', $aCriteria['label']);
$aCriteria['label'] = preg_replace("@^\(@", '', $aCriteria['label']);
}
$aCriteria['is_removable'] = $bIsRemovable;
$sClass = '';
if (isset($aCriteria['ref']))
{
if (isset($aCriteria['ref'])) {
$aRef = explode('.', $aCriteria['ref']);
if (isset($aClasses[$aRef[0]]))
{
if (isset($aClasses[$aRef[0]])) {
$sClass = $aClasses[$aRef[0]];
$aCriteria['class'] = $sClass;
}
}
// Check criteria validity
if (!isset($aCriteria['ref']) || !isset($aAllFields[$aCriteria['ref']]))
{
if (!isset($aCriteria['ref']) || !isset($aAllFields[$aCriteria['ref']])) {
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
$aCriteria['label'] = Dict::S('UI:Search:Criteria:Raw:Filtered');
if (isset($aCriteria['ref']))
{
try
{
if (isset($aCriteria['ref'])) {
try {
$aCriteria['label'] = Dict::Format('UI:Search:Criteria:Raw:FilteredOn', MetaModel::GetName($sClass));
}
catch (Exception $e)
{
} catch (Exception $e) {
}
}
}
if (array_key_exists('widget', $aCriteria))
{
if (array_key_exists($aCriteria['widget'], $aMappingOperatorToFunction))
{
if (array_key_exists('widget', $aCriteria)) {
if (array_key_exists($aCriteria['widget'], $aMappingOperatorToFunction)) {
$sFct = $aMappingOperatorToFunction[$aCriteria['widget']];
$aAndCriterion = array_merge($aAndCriterion, self::$sFct($aCriteria, $aAllFields));
}
else
{
} else {
$aAndCriterion[] = $aCriteria;
}
}
}
// Regroup criterion by variable name (no ref first)
usort($aAndCriterion, function ($a, $b)
{
if (array_key_exists('ref', $a) || array_key_exists('ref', $b))
{
if (array_key_exists('ref', $a) && array_key_exists('ref', $b))
{
usort($aAndCriterion, function ($a, $b) {
if (array_key_exists('ref', $a) || array_key_exists('ref', $b)) {
if (array_key_exists('ref', $a) && array_key_exists('ref', $b)) {
$iRefCmp = strcmp($a['ref'], $b['ref']);
if ($iRefCmp != 0)
{
if ($iRefCmp != 0) {
return $iRefCmp;
}
return strcmp($a['operator'], $b['operator']);
}
if (array_key_exists('ref', $a))
{
if (array_key_exists('ref', $a)) {
return 1;
}
return -1;
}
if (array_key_exists('oql', $a) && array_key_exists('oql', $b))
{
if (array_key_exists('oql', $a) && array_key_exists('oql', $b)) {
return strcmp($a['oql'], $b['oql']);
}
return 0;
});
$aMergeFctByWidget = array(
$aMergeFctByWidget = [
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE => 'MergeDate',
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME => 'MergeDateTime',
AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC => 'MergeNumeric',
AttributeDefinition::SEARCH_WIDGET_TYPE_ENUM => 'MergeEnumExtKeys',
AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_KEY => 'MergeEnumExtKeys',
);
];
$aPrevCriterion = null;
$aMergedCriterion = array();
foreach($aAndCriterion as $aCurrCriterion)
{
if (!is_null($aPrevCriterion))
{
if (array_key_exists('ref', $aPrevCriterion) && array_key_exists('widget', $aPrevCriterion))
{
$aMergedCriterion = [];
foreach ($aAndCriterion as $aCurrCriterion) {
if (!is_null($aPrevCriterion)) {
if (array_key_exists('ref', $aPrevCriterion) && array_key_exists('widget', $aPrevCriterion)) {
// If previous has ref, the current has ref as the array is sorted with all without ref first
if (($aPrevCriterion['ref'] == $aCurrCriterion['ref']) && ($aPrevCriterion['widget'] == $aCurrCriterion['widget']))
{
if (($aPrevCriterion['ref'] == $aCurrCriterion['ref']) && ($aPrevCriterion['widget'] == $aCurrCriterion['widget'])) {
// Same attribute, try to merge
if (array_key_exists('widget', $aCurrCriterion))
{
if (array_key_exists($aCurrCriterion['widget'], $aMergeFctByWidget))
{
if (array_key_exists('widget', $aCurrCriterion)) {
if (array_key_exists($aCurrCriterion['widget'], $aMergeFctByWidget)) {
$sFct = $aMergeFctByWidget[$aCurrCriterion['widget']];
$aPrevCriterion = self::$sFct($aPrevCriterion, $aCurrCriterion, $aMergedCriterion);
continue;
@@ -195,44 +166,35 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$aPrevCriterion = $aCurrCriterion;
}
if (!is_null($aPrevCriterion))
{
if (!is_null($aPrevCriterion)) {
$aMergedCriterion[] = $aPrevCriterion;
}
// Sort by label criterion by variable name (no ref first)
usort($aMergedCriterion, function ($a, $b)
{
usort($aMergedCriterion, function ($a, $b) {
if (($a['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW) ||
($b['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW))
{
($b['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW)) {
if (($a['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW) &&
($b['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW))
{
if (!isset($a['label']))
{
($b['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW)) {
if (!isset($a['label'])) {
return -1;
}
if (!isset($b['label']))
{
if (!isset($b['label'])) {
return 1;
}
return strcmp($a['label'], $b['label']);
}
if ($a['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW)
{
if ($a['widget'] === AttributeDefinition::SEARCH_WIDGET_TYPE_RAW) {
return -1;
}
return 1;
}
if (!isset($a['label']))
{
if (!isset($a['label'])) {
return -1;
}
if (!isset($b['label']))
{
if (!isset($b['label'])) {
return 1;
}
return strcmp($a['label'], $b['label']);
@@ -253,8 +215,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
{
$sPrevOperator = $aPrevCriterion['operator'];
$sCurrOperator = $aCurrCriterion['operator'];
if (($sPrevOperator != '<=') || ($sCurrOperator != '>='))
{
if (($sPrevOperator != '<=') || ($sCurrOperator != '>=')) {
$aMergedCriterion[] = $aPrevCriterion;
return $aCurrCriterion;
@@ -274,9 +235,9 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$sFirstDateValue = $oDate->format(AttributeDate::GetSQLFormat());
$sFirstDateLabel = $oFormat->format($oDate);
$aCurrCriterion['values'] = array();
$aCurrCriterion['values'][] = array('value' => $sFirstDateValue, 'label' => $sFirstDateLabel);
$aCurrCriterion['values'][] = array('value' => $sLastDateValue, 'label' => $sLastDateLabel);
$aCurrCriterion['values'] = [];
$aCurrCriterion['values'][] = ['value' => $sFirstDateValue, 'label' => $sFirstDateLabel];
$aCurrCriterion['values'][] = ['value' => $sLastDateValue, 'label' => $sLastDateLabel];
$aCurrCriterion['oql'] = "({$aPrevCriterion['oql']} AND {$aCurrCriterion['oql']})";
$aCurrCriterion['label'] = $aPrevCriterion['label'].' '.Dict::S('Expression:Operator:AND', 'AND').' '.$aCurrCriterion['label'];
@@ -298,8 +259,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
{
$sPrevOperator = $aPrevCriterion['operator'];
$sCurrOperator = $aCurrCriterion['operator'];
if (($sPrevOperator != '<=') || ($sCurrOperator != '>='))
{
if (($sPrevOperator != '<=') || ($sCurrOperator != '>=')) {
$aMergedCriterion[] = $aPrevCriterion;
return $aCurrCriterion;
@@ -318,13 +278,15 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$sFirstDateValue = $oDate->format(AttributeDateTime::GetSQLFormat());
$sFirstDateLabel = AttributeDateTime::GetFormat()->Format($sFirstDateValue);
$aCurrCriterion['values'] = array();
$aCurrCriterion['values'][] = array('value' => $sFirstDateValue, 'label' => $sFirstDateLabel);
$aCurrCriterion['values'][] = array('value' => $sLastDateValue, 'label' => $sLastDateLabel);
$aCurrCriterion['values'] = [];
$aCurrCriterion['values'][] = ['value' => $sFirstDateValue, 'label' => $sFirstDateLabel];
$aCurrCriterion['values'][] = ['value' => $sLastDateValue, 'label' => $sLastDateLabel];
$aCurrCriterion['oql'] = "({$aPrevCriterion['oql']} AND {$aCurrCriterion['oql']})";
$aCurrCriterion['label'] = $aPrevCriterion['label'].' '.Dict::S('Expression:Operator:AND',
'AND').' '.$aCurrCriterion['label'];
$aCurrCriterion['label'] = $aPrevCriterion['label'].' '.Dict::S(
'Expression:Operator:AND',
'AND'
).' '.$aCurrCriterion['label'];
$aMergedCriterion[] = $aCurrCriterion;
@@ -343,8 +305,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
{
$sPrevOperator = $aPrevCriterion['operator'];
$sCurrOperator = $aCurrCriterion['operator'];
if (($sPrevOperator != '<=') || ($sCurrOperator != '>='))
{
if (($sPrevOperator != '<=') || ($sCurrOperator != '>=')) {
$aMergedCriterion[] = $aPrevCriterion;
return $aCurrCriterion;
@@ -353,9 +314,9 @@ class CriterionToSearchForm extends CriterionConversionAbstract
// Merge into 'between' operation.
$sLastNum = $aPrevCriterion['values'][0]['value'];
$sFirstNum = $aCurrCriterion['values'][0]['value'];
$aCurrCriterion['values'] = array();
$aCurrCriterion['values'][] = array('value' => $sFirstNum, 'label' => "$sFirstNum");
$aCurrCriterion['values'][] = array('value' => $sLastNum, 'label' => "$sLastNum");
$aCurrCriterion['values'] = [];
$aCurrCriterion['values'][] = ['value' => $sFirstNum, 'label' => "$sFirstNum"];
$aCurrCriterion['values'][] = ['value' => $sLastNum, 'label' => "$sLastNum"];
$aCurrCriterion['oql'] = "({$aPrevCriterion['oql']} AND {$aCurrCriterion['oql']})";
$aCurrCriterion['label'] = $aPrevCriterion['label'].' '.Dict::S('Expression:Operator:AND', 'AND').' '.$aCurrCriterion['label'];
@@ -368,9 +329,8 @@ class CriterionToSearchForm extends CriterionConversionAbstract
private static function SerializeValues($aValues)
{
$aSerializedValues = array();
foreach($aValues as $aValue)
{
$aSerializedValues = [];
foreach ($aValues as $aValue) {
$aSerializedValues[] = serialize($aValue);
}
@@ -397,8 +357,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$bStartWithPercent = substr($sValue, 0, 1) == '%' ? true : false;
$bEndWithPercent = substr($sValue, -1) == '%' ? true : false;
switch (true)
{
switch (true) {
case ('' == $sValue and ($sOperator == '=' or $sOperator == 'LIKE')):
$aCriteria['operator'] = CriterionConversionAbstract::OP_EMPTY;
break;
@@ -425,7 +384,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
break;
}
return array($aCriteria);
return [$aCriteria];
}
protected static function ExternalFieldToSearchForm($aCriteria, $aFields)
@@ -436,8 +395,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$bStartWithPercent = substr($sValue, 0, 1) == '%' ? true : false;
$bEndWithPercent = substr($sValue, -1) == '%' ? true : false;
switch (true)
{
switch (true) {
case ($sOperator == 'ISNULL'):
case ('' == $sValue and ($sOperator == 'LIKE')):
$aCriteria['operator'] = CriterionConversionAbstract::OP_EMPTY;
@@ -465,59 +423,44 @@ class CriterionToSearchForm extends CriterionConversionAbstract
break;
}
return array($aCriteria);
return [$aCriteria];
}
protected static function DateTimeToSearchForm($aCriterion, $aFields)
{
if ((!array_key_exists('is_relative', $aCriterion) || !$aCriterion['is_relative'])
&& (!isset($aCriterion['unit']) || ($aCriterion['unit'] == 'DAY')))
{
&& (!isset($aCriterion['unit']) || ($aCriterion['unit'] == 'DAY'))) {
// Convert '=' in 'between'
if (isset($aCriterion['operator']))
{
switch ($aCriterion['operator'])
{
if (isset($aCriterion['operator'])) {
switch ($aCriterion['operator']) {
case '=':
if (isset($aCriterion['has_undefined']) && (isset($aCriterion['values'][0]['value']) && ($aCriterion['values'][0]['value'] == 0)))
{
if (isset($aCriterion['has_undefined']) && (isset($aCriterion['values'][0]['value']) && ($aCriterion['values'][0]['value'] == 0))) {
// Special case for NOT EMPTY
$aCriterion['operator'] = CriterionConversionAbstract::OP_NOT_EMPTY;
}
else
{
} else {
$aCriterion['operator'] = CriterionConversionAbstract::OP_BETWEEN_DATES;
$sWidget = $aCriterion['widget'];
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE)
{
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE) {
$aCriterion['values'][1] = $aCriterion['values'][0];
}
else
{
} else {
$sDate = $aCriterion['values'][0]['value'];
$oDate = new DateTime($sDate);
$sFirstDateValue = $oDate->format(AttributeDateTime::GetSQLFormat());
try
{
try {
$sFirstDateLabel = AttributeDateTime::GetFormat()->Format($sFirstDateValue);
$aCriterion['values'][0] = array('value' => $sFirstDateValue, 'label' => "$sFirstDateLabel");
}
catch (Exception $e)
{
$aCriterion['values'][0] = ['value' => $sFirstDateValue, 'label' => "$sFirstDateLabel"];
} catch (Exception $e) {
}
$oDate->add(DateInterval::createFromDateString('1 day'));
$oDate->sub(DateInterval::createFromDateString('1 second'));
$sLastDateValue = $oDate->format(AttributeDateTime::GetSQLFormat());
try
{
try {
$sLastDateLabel = AttributeDateTime::GetFormat()->Format($sLastDateValue);
$aCriterion['values'][1] = array('value' => $sLastDateValue, 'label' => "$sLastDateLabel");
}
catch (Exception $e)
{
$aCriterion['values'][1] = ['value' => $sLastDateValue, 'label' => "$sLastDateLabel"];
} catch (Exception $e) {
}
}
}
@@ -530,13 +473,10 @@ class CriterionToSearchForm extends CriterionConversionAbstract
case '>':
$aCriterion['operator'] = '>=';
$sWidget = $aCriterion['widget'];
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE)
{
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE) {
$sDelta = '1 day';
$sAttributeClass = AttributeDate::class;
}
else
{
} else {
$sDelta = '1 second';
$sAttributeClass = AttributeDateTime::class;
}
@@ -547,23 +487,20 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$oDate = new DateTime($sFirstDate);
$oDate->add(DateInterval::createFromDateString($sDelta));
$sFirstDateValue = $oDate->format($sAttributeClass::GetSQLFormat());
try
{
try {
$sFirstDateLabel = $oFormat->format($oDate);
$aCriterion['values'][0] = array('value' => $sFirstDateValue, 'label' => $sFirstDateLabel);
} catch (Exception $e) {}
$aCriterion['values'][0] = ['value' => $sFirstDateValue, 'label' => $sFirstDateLabel];
} catch (Exception $e) {
}
break;
case '<':
$aCriterion['operator'] = '<=';
$sWidget = $aCriterion['widget'];
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE)
{
if ($sWidget == AttributeDefinition::SEARCH_WIDGET_TYPE_DATE) {
$sDelta = '1 day';
$sAttributeClass = AttributeDate::class;
}
else
{
} else {
$sDelta = '1 second';
$sAttributeClass = AttributeDateTime::class;
}
@@ -574,26 +511,23 @@ class CriterionToSearchForm extends CriterionConversionAbstract
$oDate = new DateTime($sFirstDate);
$oDate->sub(DateInterval::createFromDateString($sDelta));
$sFirstDateValue = $oDate->format($sAttributeClass::GetSQLFormat());
try
{
try {
$sFirstDateLabel = $oFormat->format($oDate);
$aCriterion['values'][0] = array('value' => $sFirstDateValue, 'label' => $sFirstDateLabel);
} catch (Exception $e) {}
$aCriterion['values'][0] = ['value' => $sFirstDateValue, 'label' => $sFirstDateLabel];
} catch (Exception $e) {
}
break;
}
}
return array($aCriterion);
return [$aCriterion];
}
if (isset($aCriterion['values'][0]['value']))
{
if (isset($aCriterion['values'][0]['value'])) {
$sLabel = $aCriterion['values'][0]['value'];
if (isset($aCriterion['verb']))
{
switch ($aCriterion['verb'])
{
if (isset($aCriterion['verb'])) {
switch ($aCriterion['verb']) {
case 'DATE_SUB':
$sLabel = '-'.$sLabel;
break;
@@ -602,8 +536,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
break;
}
}
if (isset($aCriterion['unit']))
{
if (isset($aCriterion['unit'])) {
$sLabel .= Dict::S('Expression:Unit:Short:'.$aCriterion['unit'], $aCriterion['unit']);
}
$aCriterion['values'][0]['label'] = "$sLabel";
@@ -612,34 +545,31 @@ class CriterionToSearchForm extends CriterionConversionAbstract
// Temporary until the JS widget support relative dates
$aCriterion['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
return array($aCriterion);
return [$aCriterion];
}
protected static function NumericToSearchForm($aCriteria, $aFields)
{
switch ($aCriteria['operator'])
{
case 'ISNULL':
switch ($aCriteria['operator']) {
case 'ISNULL':
$aCriteria['operator'] = CriterionConversionAbstract::OP_EMPTY;
break;
case '=':
if (isset($aCriteria['has_undefined']) && (isset($aCriteria['values'][0]['value']) && ($aCriteria['values'][0]['value'] == 0)))
{
if (isset($aCriteria['has_undefined']) && (isset($aCriteria['values'][0]['value']) && ($aCriteria['values'][0]['value'] == 0))) {
// Special case for NOT EMPTY
$aCriteria['operator'] = CriterionConversionAbstract::OP_NOT_EMPTY;
}
break;
}
return array($aCriteria);
return [$aCriteria];
}
protected static function EnumToSearchForm($aCriteria, $aFields)
{
$sOperator = $aCriteria['operator'];
switch ($sOperator)
{
switch ($sOperator) {
case '=':
// Same as IN
$aCriteria['operator'] = CriterionConversionAbstract::OP_IN;
@@ -657,14 +587,12 @@ class CriterionToSearchForm extends CriterionConversionAbstract
case 'ISNULL':
// Special case when undefined and/or other values are selected
$aCriteria['operator'] = CriterionConversionAbstract::OP_IN;
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
if (!isset($aCriteria['values']))
{
$aCriteria['values'] = array();
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined']) {
if (!isset($aCriteria['values'])) {
$aCriteria['values'] = [];
}
// Convention for 'undefined' enums
$aCriteria['values'][] = array('value' => 'null', 'label' => Dict::S('Enum:Undefined'));
$aCriteria['values'][] = ['value' => 'null', 'label' => Dict::S('Enum:Undefined')];
}
break;
default:
@@ -673,58 +601,49 @@ class CriterionToSearchForm extends CriterionConversionAbstract
break;
}
return array($aCriteria);
return [$aCriteria];
}
protected static function TagSetToSearchForm($aCriteria, $aFields)
{
$aCriterion = array($aCriteria);
$aCriterion = [$aCriteria];
$sOperator = $aCriteria['operator'];
switch ($sOperator)
{
switch ($sOperator) {
case 'MATCHES':
// Nothing special to do
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
if (!isset($aCriteria['values']))
{
$aCriteria['values'] = array();
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined']) {
if (!isset($aCriteria['values'])) {
$aCriteria['values'] = [];
}
// Convention for 'undefined' tag set
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
$aCriteria['values'][] = ['value' => '', 'label' => Dict::S('Enum:Undefined')];
}
break;
case 'OR':
case 'ISNULL':
$aCriteria['operator'] = CriterionConversionAbstract::OP_EQUALS;
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
if (!isset($aCriteria['values']))
{
$aCriteria['values'] = array();
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined']) {
if (!isset($aCriteria['values'])) {
$aCriteria['values'] = [];
}
// Convention for 'undefined' tag set
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
$aCriteria['values'][] = ['value' => '', 'label' => Dict::S('Enum:Undefined')];
}
break;
case '=':
$aCriteria['operator'] = CriterionConversionAbstract::OP_MATCHES;
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
$aCriteria['values'] = array();
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined']) {
$aCriteria['values'] = [];
// Convention for 'undefined' tag set
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
}
else
{
$aCriteria['values'][] = ['value' => '', 'label' => Dict::S('Enum:Undefined')];
} else {
// Split values into a list of Matches
$aCriterion = array();
$aCriterion = [];
$aValues = $aCriteria['values'];
foreach($aValues as $aValue)
{
$aCriteria['values'] = array($aValue);
foreach ($aValues as $aValue) {
$aCriteria['values'] = [$aValue];
$aCriterion[] = $aCriteria;
}
}
@@ -741,14 +660,13 @@ class CriterionToSearchForm extends CriterionConversionAbstract
protected static function SetToSearchForm($aCriteria, $aFields)
{
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
return array($aCriteria);
return [$aCriteria];
}
protected static function ExternalKeyToSearchForm($aCriteria, $aFields)
{
$sOperator = $aCriteria['operator'];
switch ($sOperator)
{
switch ($sOperator) {
case '=':
// Same as IN
$aCriteria['operator'] = CriterionConversionAbstract::OP_IN;
@@ -763,7 +681,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
break;
}
return array($aCriteria);
return [$aCriteria];
}
/**
@@ -776,32 +694,25 @@ class CriterionToSearchForm extends CriterionConversionAbstract
{
$sRef = $aCriteria['ref'];
$aValues = $aCriteria['values'];
if (array_key_exists($sRef, $aFields))
{
if (array_key_exists($sRef, $aFields)) {
$aField = $aFields[$sRef];
if (array_key_exists('allowed_values', $aField) && array_key_exists('values', $aField['allowed_values']))
{
if (array_key_exists('allowed_values', $aField) && array_key_exists('values', $aField['allowed_values'])) {
$aAllowedValues = $aField['allowed_values']['values'];
}
else
{
} else {
// Can't obtain the list of allowed values, just set as unknown
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
}
}
if (isset($aAllowedValues))
{
foreach($aValues as $aValue)
{
if (isset($aAllowedValues)) {
foreach ($aValues as $aValue) {
$sValue = $aValue['value'];
unset($aAllowedValues[$sValue]);
}
$aCriteria['values'] = array();
$aCriteria['values'] = [];
foreach($aAllowedValues as $sValue => $sLabel)
{
$aValue = array('value' => $sValue, 'label' => "$sLabel");
foreach ($aAllowedValues as $sValue => $sLabel) {
$aValue = ['value' => $sValue, 'label' => "$sLabel"];
$aCriteria['values'][] = $aValue;
}
$aCriteria['operator'] = 'IN';

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -28,8 +29,6 @@
namespace Combodo\iTop\Application\Search;
class AjaxSearchException extends \Exception
{
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -19,25 +20,21 @@
*
*/
namespace Combodo\iTop\Application\Search;
abstract class CriterionConversionAbstract
{
const OP_CONTAINS = 'contains';
const OP_EQUALS = '=';
const OP_STARTS_WITH = 'starts_with';
const OP_ENDS_WITH = 'ends_with';
const OP_EMPTY = 'empty';
const OP_NOT_EMPTY = 'not_empty';
const OP_IN = 'IN';
const OP_BETWEEN_DATES = 'between_dates';
const OP_BETWEEN = 'between';
const OP_REGEXP = 'REGEXP';
const OP_ALL = 'all';
const OP_MATCHES = 'MATCHES';
public const OP_CONTAINS = 'contains';
public const OP_EQUALS = '=';
public const OP_STARTS_WITH = 'starts_with';
public const OP_ENDS_WITH = 'ends_with';
public const OP_EMPTY = 'empty';
public const OP_NOT_EMPTY = 'not_empty';
public const OP_IN = 'IN';
public const OP_BETWEEN_DATES = 'between_dates';
public const OP_BETWEEN = 'between';
public const OP_REGEXP = 'REGEXP';
public const OP_ALL = 'all';
public const OP_MATCHES = 'MATCHES';
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -28,7 +29,6 @@
namespace Combodo\iTop\Application\Search;
use Combodo\iTop\Application\Search\CriterionConversion\CriterionToOQL;
use DBObjectSearch;
use Expression;
@@ -37,7 +37,6 @@ use OQLException;
class CriterionParser
{
/**
* @param $sBaseOql
* @param $aCriterion
@@ -47,30 +46,25 @@ class CriterionParser
*/
public static function Parse($sBaseOql, $aCriterion, $sHiddenCriteria = null)
{
try
{
try {
$oSearch = DBObjectSearch::FromOQL($sBaseOql);
$aExpression = array();
$aExpression = [];
$aOr = $aCriterion['or'];
foreach($aOr as $aAndList)
{
foreach ($aOr as $aAndList) {
$sExpression = self::ParseAndList($oSearch, $aAndList['and']);
if (!empty($sExpression))
{
if (!empty($sExpression)) {
$aExpression[] = $sExpression;
}
}
if (!empty($sHiddenCriteria))
{
if (!empty($sHiddenCriteria)) {
$oHiddenCriteriaExpression = Expression::FromOQL($sHiddenCriteria);
$oSearch->AddConditionExpression($oHiddenCriteriaExpression);
}
if (empty($aExpression))
{
if (empty($aExpression)) {
return $oSearch;
}
@@ -78,8 +72,7 @@ class CriterionParser
$oSearch->AddConditionExpression($oExpression);
return $oSearch;
} catch (OQLException $e)
{
} catch (OQLException $e) {
IssueLog::Error($e->getMessage());
}
return null;
@@ -87,22 +80,19 @@ class CriterionParser
private static function ParseAndList($oSearch, $aAnd)
{
$aExpression = array();
foreach($aAnd as $aCriteria)
{
$aExpression = [];
foreach ($aAnd as $aCriteria) {
$sExpression = CriterionToOQL::Convert($oSearch, $aCriteria);
if ($sExpression !== '1')
{
if ($sExpression !== '1') {
$aExpression[] = $sExpression;
}
}
if (empty($aExpression))
{
if (empty($aExpression)) {
return '1';
}
return '('.implode(" AND ", $aExpression).')';
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\Search;
use ApplicationContext;
use AttributeDefinition;
use AttributeEnumSet;
@@ -46,13 +45,13 @@ class SearchForm
*
* @return string
*/
public function GetSearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
public function GetSearchForm(WebPage $oPage, CMDBObjectSet $oSet, $aExtraParams = [])
{
$oPage->AddUiBlock($this->GetSearchFormUIBlock($oPage, $oSet, $aExtraParams));
return '';
}
public function GetSearchFormUIBlock(WebPage $oPage, DBObjectSet $oSet, $aExtraParams = array())
public function GetSearchFormUIBlock(WebPage $oPage, DBObjectSet $oSet, $aExtraParams = [])
{
$oUiBlock = new UIContentBlock();
$oUiBlock->AddMultipleJsFilesRelPaths([
@@ -76,10 +75,9 @@ class SearchForm
$oAppContext = new ApplicationContext();
$sClassName = $oSet->GetFilter()->GetClass();
$aListParams = array();
$aListParams = [];
foreach($aExtraParams as $key => $value)
{
foreach ($aExtraParams as $key => $value) {
$aListParams[$key] = $value;
}
@@ -127,7 +125,7 @@ class SearchForm
} else {
$aSubClasses = MetaModel::GetSubclasses($sRootClass);
if (count($aSubClasses) > 0) {
$aOptions = array();
$aOptions = [];
$aOptions[MetaModel::GetName($sRootClass)] = "<option value=\"$sRootClass\">".MetaModel::GetName($sRootClass)."</options>\n";
foreach ($aSubClasses as $sSubclassName) {
if (UserRights::IsActionAllowed($sSubclassName, UR_ACTION_READ)) {
@@ -137,23 +135,20 @@ class SearchForm
$aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
ksort($aOptions);
$sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext', '$sOuterSelector', $sJsonExtraParams)\">\n".implode('',
$aOptions)."</select>\n";
}
else
{
$sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext', '$sOuterSelector', $sJsonExtraParams)\">\n".implode(
'',
$aOptions
)."</select>\n";
} else {
$sClassesCombo = MetaModel::GetName($sClassName);
}
}
$bAutoSubmit = true;
$mSubmitParam = utils::GetConfig()->Get('search_manual_submit');
if ($mSubmitParam !== false)
{
if ($mSubmitParam !== false) {
$bAutoSubmit = false;
}
else
{
} else {
$mSubmitParam = utils::GetConfig()->Get('high_cardinality_classes');
if (is_array($mSubmitParam)) {
if (in_array($sClassName, $mSubmitParam)) {
@@ -163,7 +158,6 @@ class SearchForm
}
$bShowObsoleteData = \appUserPreferences::GetPref('show_obsolete_data', MetaModel::GetConfig()->Get('obsolescence.show_obsolete_data'));// ? What to do when true == utils::IsArchiveMode()
$sAction = (isset($aExtraParams['action'])) ? $aExtraParams['action'] : utils::GetAbsoluteUrlAppRoot().'pages/UI.php';
$aCSSClasses = ["ibo-search-form"];
if ($bOpen != 'true') {
@@ -188,14 +182,13 @@ class SearchForm
}
if ($bAutoSubmit === false) {
$sAutoSubmit = Dict::S('UI:Search:AutoSubmit:DisabledHint');
$sHtml .= "<span class=\"sft_hint pull-right\"><span class=\"fa-stack fa-fw\" aria-label=\"$sAutoSubmit\" data-tooltip-content=\"$sAutoSubmit\"><span class=\"fas fa-sync-alt fa-stack-1x\"></span><span class=\"fas fa-slash fa-stack-1x\"></span
$sHtml .= "<span class=\"sft_hint pull-right\"><span class=\"fa-stack fa-fw\" aria-label=\"$sAutoSubmit\" data-tooltip-content=\"$sAutoSubmit\"><span class=\"fas fa-sync-alt fa-stack-1x\"></span><span class=\"fas fa-slash fa-stack-1x\"></span
></span></span>";
$sHtml .= "</span>";
}
$sHtml .= "<br class='clearboth' />";
$oUiSearchBlock->AddToolbarBlock(new Html($sHtml));
$oFormSearch = new Form("fs_".$sSearchFormId);
$oFormSearch->SetAction($sAction)
->AddCSSClasses($aCSSClasses);
@@ -208,14 +201,12 @@ class SearchForm
if (isset($aExtraParams['query_params'])) {
$aArgs = $aExtraParams['query_params'];
} else
{
$aArgs = array();
} else {
$aArgs = [];
}
$bIsRemovable = true;
if (isset($aExtraParams['selection_type']) && ($aExtraParams['selection_type'] == 'single'))
{
if (isset($aExtraParams['selection_type']) && ($aExtraParams['selection_type'] == 'single')) {
// Mark all criterion as read-only and non-removable for external keys only
$bIsRemovable = false;
}
@@ -251,7 +242,7 @@ class SearchForm
$aListParams['debug'] = 'true';
}
$aDaysMin = array(
$aDaysMin = [
Dict::S('DayOfWeek-Sunday-Min'),
Dict::S('DayOfWeek-Monday-Min'),
Dict::S('DayOfWeek-Tuesday-Min'),
@@ -259,8 +250,8 @@ class SearchForm
Dict::S('DayOfWeek-Thursday-Min'),
Dict::S('DayOfWeek-Friday-Min'),
Dict::S('DayOfWeek-Saturday-Min'),
);
$aMonthsShort = array(
];
$aMonthsShort = [
Dict::S('Month-01-Short'),
Dict::S('Month-02-Short'),
Dict::S('Month-03-Short'),
@@ -273,14 +264,14 @@ class SearchForm
Dict::S('Month-10-Short'),
Dict::S('Month-11-Short'),
Dict::S('Month-12-Short'),
);
];
$sDateTimeFormat = \AttributeDateTime::GetFormat()->ToDatePicker();
$iDateTimeSeparatorPos = strpos($sDateTimeFormat, ' ');
$sDateFormat = substr($sDateTimeFormat, 0, $iDateTimeSeparatorPos);
$sTimeFormat = substr($sDateTimeFormat, $iDateTimeSeparatorPos + 1);
$aSearchParams = array(
$aSearchParams = [
'criterion_outer_selector' => "#fs_{$sSearchFormId}_criterion_outer",
'result_list_outer_selector' => "#{$aExtraParams['result_list_outer_selector']}",
'data_config_list_selector' => "#{$aExtraParams['result_list_outer_selector']}",
@@ -290,77 +281,68 @@ class SearchForm
'auto_submit' => $bAutoSubmit,
'list_params' => $aListParams,
'show_obsolete_data' => $bShowObsoleteData,
'search' => array(
'search' => [
'has_hidden_criteria' => (array_key_exists('hidden_criteria', $aListParams) && !empty($aListParams['hidden_criteria'])),
'fields' => $aFields,
'criterion' => $aCriterion,
'class_name' => $sClassName,
'class_alias' => $sClassAlias,
'base_oql' => $sBaseOQL,
),
'conf_parameters' => array(
],
'conf_parameters' => [
'min_autocomplete_chars' => MetaModel::GetConfig()->Get('min_autocomplete_chars'),
'datepicker' => array(
'datepicker' => [
'dayNamesMin' => $aDaysMin,
'monthNamesShort' => $aMonthsShort,
'firstDay' => (int) Dict::S('Calendar-FirstDayOfWeek'),
'dateFormat' => $sDateFormat,
'timeFormat' => $sTimeFormat,
),
),
);
],
],
];
$oPage->add_ready_script('$("#fs_'.$sSearchFormId.'").search_form_handler('.json_encode($aSearchParams).');');
return $oUiBlock;
}
/**
* @param \DBObjectSet $oSet
*
* @return array
*
* @throws \CoreException
*/
/**
* @param \DBObjectSet $oSet
*
* @return array
*
* @throws \CoreException
*/
public function GetFields($oSet)
{
$oSearch = $oSet->GetFilter();
$aAllClasses = $oSearch->GetSelectedClasses();
$aAuthorizedClasses = array();
foreach($aAllClasses as $sAlias => $sClassName)
{
if (\UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO)
{
$aAuthorizedClasses = [];
foreach ($aAllClasses as $sAlias => $sClassName) {
if (\UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) {
$aAuthorizedClasses[$sAlias] = $sClassName;
}
}
$aAllFields = array('zlist' => array(), 'others' => array());
try
{
foreach($aAuthorizedClasses as $sAlias => $sClass)
{
$aZList = array();
$aOthers = array();
$aAllFields = ['zlist' => [], 'others' => []];
try {
foreach ($aAuthorizedClasses as $sAlias => $sClass) {
$aZList = [];
$aOthers = [];
$this->PopulateFieldList($sClass, $sAlias, $aZList, $aOthers);
$aAllFields[$sAlias.'_zlist'] = $aZList;
$aAllFields[$sAlias.'_others'] = $aOthers;
}
}
catch (CoreException $e)
{
} catch (CoreException $e) {
IssueLog::Error($e->getMessage());
}
$aSelectedClasses = $oSearch->GetSelectedClasses();
foreach($aSelectedClasses as $sAlias => $sClassName)
{
if(array_key_exists($sAlias.'_zlist', $aAllFields))
{
foreach ($aSelectedClasses as $sAlias => $sClassName) {
if (array_key_exists($sAlias.'_zlist', $aAllFields)) {
$aAllFields['zlist'] = array_merge($aAllFields['zlist'], $aAllFields[$sAlias.'_zlist']);
unset($aAllFields[$sAlias.'_zlist']);
}
if(array_key_exists($sAlias.'_others', $aAllFields))
{
if (array_key_exists($sAlias.'_others', $aAllFields)) {
$aAllFields['others'] = array_merge($aAllFields['others'], $aAllFields[$sAlias.'_others']);
unset($aAllFields[$sAlias.'_others']);
}
@@ -380,36 +362,30 @@ class SearchForm
protected function PopulateFieldList($sClass, $sAlias, &$aZList, &$aOthers)
{
$aDBIndexes = self::DBGetIndexes($sClass);
$aIndexes = array();
foreach($aDBIndexes as $aIndexGroup)
{
foreach($aIndexGroup as $sIndex)
{
$aIndexes = [];
foreach ($aDBIndexes as $aIndexGroup) {
foreach ($aIndexGroup as $sIndex) {
$aIndexes[$sIndex] = true;
}
}
$aAttributeDefs = MetaModel::ListAttributeDefs($sClass);
$aList = MetaModel::GetZListItems($sClass, 'standard_search');
$bHasFriendlyname = false;
foreach($aList as $sAttCode)
{
if (array_key_exists($sAttCode, $aAttributeDefs))
{
foreach ($aList as $sAttCode) {
if (array_key_exists($sAttCode, $aAttributeDefs)) {
$bHasIndex = isset($aIndexes[$sAttCode]);
$oAttDef = $aAttributeDefs[$sAttCode];
$aZList = $this->AppendField($sClass, $sAlias, $sAttCode, $oAttDef, $aZList, $bHasIndex);
unset($aAttributeDefs[$sAttCode]);
}
if ($sAttCode == 'friendlyname')
{
if ($sAttCode == 'friendlyname') {
$bHasFriendlyname = true;
}
}
if (!$bHasFriendlyname)
{
if (!$bHasFriendlyname) {
// Add friendlyname to the most popular
$sAttCode = 'friendlyname';
$bHasIndex = isset($aIndexes[$sAttCode]);
$bHasIndex = isset($aIndexes[$sAttCode]);
$oAttDef = $aAttributeDefs[$sAttCode];
$aZList = $this->AppendField($sClass, $sAlias, $sAttCode, $oAttDef, $aZList, $bHasIndex);
unset($aAttributeDefs[$sAttCode]);
@@ -419,11 +395,12 @@ class SearchForm
return strcmp($aItem1['label'], $aItem2['label']);
});
foreach($aAttributeDefs as $sAttCode => $oAttDef)
{
if ($oAttDef instanceof AttributeFriendlyName) continue; //it was already forced into $aZList in the code above
foreach ($aAttributeDefs as $sAttCode => $oAttDef) {
if ($oAttDef instanceof AttributeFriendlyName) {
continue;
} //it was already forced into $aZList in the code above
$bHasIndex = isset($aIndexes[$sAttCode]);
$bHasIndex = isset($aIndexes[$sAttCode]);
$aOthers = $this->AppendField($sClass, $sAlias, $sAttCode, $oAttDef, $aOthers, $bHasIndex);
}
uasort($aOthers, function ($aItem1, $aItem2) {
@@ -441,98 +418,77 @@ class SearchForm
protected static function DBGetIndexes($sClass)
{
$aDBIndexes = MetaModel::DBGetIndexes($sClass);
while ($sClass = MetaModel::GetParentClass($sClass))
{
while ($sClass = MetaModel::GetParentClass($sClass)) {
$aDBIndexes = array_merge($aDBIndexes, MetaModel::DBGetIndexes($sClass));
}
return $aDBIndexes;
}
/**
* @param \AttributeDefinition $oAttrDef
*
* @return array
*
* @throws \CoreException
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
/**
* @param \AttributeDefinition $oAttrDef
*
* @return array
*
* @throws \CoreException
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
public static function GetFieldAllowedValues($oAttrDef)
{
$iMaxComboLength = MetaModel::GetConfig()->Get('max_combo_length');
if ($oAttrDef->IsExternalKey(EXTKEY_ABSOLUTE))
{
if ($oAttrDef instanceof AttributeExternalField)
{
if ($oAttrDef->IsExternalKey(EXTKEY_ABSOLUTE)) {
if ($oAttrDef instanceof AttributeExternalField) {
$sTargetClass = $oAttrDef->GetFinalAttDef()->GetTargetClass();
}
else
{
} else {
/** @var \AttributeExternalKey $oAttrDef */
$sTargetClass = $oAttrDef->GetTargetClass();
}
try
{
try {
$oSearch = new DBObjectSearch($sTargetClass);
} catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error($e->getMessage());
return array('values' => array());
return ['values' => []];
}
$oSearch->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
$oSet = new DBObjectSet($oSearch);
if ($oSet->CountExceeds($iMaxComboLength))
{
return array('autocomplete' => true);
if ($oSet->CountExceeds($iMaxComboLength)) {
return ['autocomplete' => true];
}
if ($oAttrDef instanceof AttributeExternalField)
{
$aAllowedValues = array();
while ($oObject = $oSet->Fetch())
{
if ($oAttrDef instanceof AttributeExternalField) {
$aAllowedValues = [];
while ($oObject = $oSet->Fetch()) {
$aAllowedValues[$oObject->GetKey()] = $oObject->GetName();
}
return array('values' => $aAllowedValues);
return ['values' => $aAllowedValues];
}
}
elseif ($oAttrDef instanceof AttributeTagSet)
{
$aAllowedValues = array();
foreach($oAttrDef->GetAllowedValues() as $sCode => $sRawValue)
{
} elseif ($oAttrDef instanceof AttributeTagSet) {
$aAllowedValues = [];
foreach ($oAttrDef->GetAllowedValues() as $sCode => $sRawValue) {
$aAllowedValues[$sCode] = utils::HtmlEntities($sRawValue);
}
return array('values' => $aAllowedValues);
}
elseif ($oAttrDef instanceof AttributeEnumSet)
{
$aAllowedValues = array();
foreach($oAttrDef->GetPossibleValues() as $sCode => $sRawValue)
{
return ['values' => $aAllowedValues];
} elseif ($oAttrDef instanceof AttributeEnumSet) {
$aAllowedValues = [];
foreach ($oAttrDef->GetPossibleValues() as $sCode => $sRawValue) {
$aAllowedValues[$sCode] = utils::HtmlEntities($sRawValue);
}
return array('values' => $aAllowedValues);
}
else
{
if (method_exists($oAttrDef, 'GetAllowedValuesAsObjectSet'))
{
return ['values' => $aAllowedValues];
} else {
if (method_exists($oAttrDef, 'GetAllowedValuesAsObjectSet')) {
/** @var DBObjectSet $oSet */
$oSet = $oAttrDef->GetAllowedValuesAsObjectSet();
if ($oSet->CountExceeds($iMaxComboLength))
{
return array('autocomplete' => true);
if ($oSet->CountExceeds($iMaxComboLength)) {
return ['autocomplete' => true];
}
}
}
$aAllowedValues = $oAttrDef->GetAllowedValuesForSelect();
return array('values' => $aAllowedValues);
return ['values' => $aAllowedValues];
}
/**
@@ -547,90 +503,73 @@ class SearchForm
* @throws \CoreException
* @throws \MissingQueryArgument
*/
public function GetCriterion($oSearch, $aFields, $aArgs = array(), $bIsRemovable = true, $bUseApplicationContext = true)
public function GetCriterion($oSearch, $aFields, $aArgs = [], $bIsRemovable = true, $bUseApplicationContext = true)
{
$aOrCriterion = array();
$aOrCriterion = [];
$bIsEmptyExpression = true;
$aArgs = MetaModel::PrepareQueryArguments($aArgs, $oSearch->GetInternalParams(), $oSearch->GetExpectedArguments());
if ($oSearch instanceof DBObjectSearch)
{
if ($oSearch instanceof DBObjectSearch) {
$oExpression = $oSearch->GetCriteria();
if (!empty($aArgs))
{
try
{
if (!empty($aArgs)) {
try {
$sOQL = $oExpression->RenderExpression(false, $aArgs);
$oExpression = Expression::FromOQL($sOQL);
}
catch (MissingQueryArgument $e)
{
} catch (MissingQueryArgument $e) {
IssueLog::Error("Search form disabled: \"".$oSearch->ToOQL()."\" Error: ".$e->getMessage());
throw $e;
}
}
$aORExpressions = Expression::Split($oExpression, 'OR');
foreach($aORExpressions as $oORSubExpr)
{
$aAndCriterion = array();
foreach ($aORExpressions as $oORSubExpr) {
$aAndCriterion = [];
$aAndExpressions = Expression::Split($oORSubExpr, 'AND');
foreach($aAndExpressions as $oAndSubExpr)
{
foreach ($aAndExpressions as $oAndSubExpr) {
/** @var Expression $oAndSubExpr */
if (($oAndSubExpr instanceof TrueExpression) || ($oAndSubExpr->RenderExpression(false) == 1))
{
if (($oAndSubExpr instanceof TrueExpression) || ($oAndSubExpr->RenderExpression(false) == 1)) {
continue;
}
$aAndCriterion[] = $oAndSubExpr->GetCriterion($oSearch);
$bIsEmptyExpression = false;
}
$aAndCriterion = CriterionToSearchForm::Convert($aAndCriterion, $aFields, $oSearch->GetJoinedClasses(), $bIsRemovable);
$aOrCriterion[] = array('and' => $aAndCriterion);
$aOrCriterion[] = ['and' => $aAndCriterion];
}
}
if ($bIsEmptyExpression)
{
$aOrCriterion = array(array('and' => array()));
if ($bIsEmptyExpression) {
$aOrCriterion = [['and' => []]];
}
$aTempCriteria = array();
foreach ($aOrCriterion as $aExistingCriteria)
{
$aTempCriteria = [];
foreach ($aOrCriterion as $aExistingCriteria) {
// Add default criteria to all the OR criteria
$aTempCriteria[] = $this->GetDefaultCriteria($oSearch, $aExistingCriteria, $aContextParams);
}
$aOrCriterion = $aTempCriteria;
if ($bUseApplicationContext)
{
if ($bUseApplicationContext) {
// Context induced criteria are read-only
$oAppContext = new ApplicationContext();
$sClass = $oSearch->GetClass();
$aCallSpec = array($sClass, 'MapContextParam');
$aContextParams = array();
if (is_callable($aCallSpec))
{
foreach ($oAppContext->GetNames() as $sContextParam)
{
$aCallSpec = [$sClass, 'MapContextParam'];
$aContextParams = [];
if (is_callable($aCallSpec)) {
foreach ($oAppContext->GetNames() as $sContextParam) {
$sParamCode = call_user_func($aCallSpec, $sContextParam); //Map context parameter to the value/filter code depending on the class
if (!is_null($sParamCode))
{
if (!is_null($sParamCode)) {
$sParamValue = $oAppContext->GetCurrentValue($sContextParam, null);
if (!is_null($sParamValue))
{
if (!is_null($sParamValue)) {
$aContextParams[$sParamCode] = $sParamValue;
}
}
}
}
foreach ($aContextParams as $sParamCode => $sParamValue)
{
foreach ($aContextParams as $sParamCode => $sParamValue) {
// Check that the code exists in the concerned class
if (!MetaModel::IsValidAttCode($oSearch->GetClass(), $sParamCode))
{
if (!MetaModel::IsValidAttCode($oSearch->GetClass(), $sParamCode)) {
continue;
}
@@ -641,14 +580,13 @@ class SearchForm
$oExpression = new \BinaryExpression($oFieldExpression, '=', $oScalarExpression);
$aCriterion = $oExpression->GetCriterion($oSearch, $aArgs);
$aCriterion['is_removable'] = false;
foreach ($aOrCriterion as &$aAndExpression)
{
foreach ($aOrCriterion as &$aAndExpression) {
$aAndExpression['and'][] = $aCriterion;
}
}
}
return array('or' => $aOrCriterion);
return ['or' => $aOrCriterion];
}
/**
@@ -660,14 +598,14 @@ class SearchForm
*/
private function AppendId($sClass, $sClassAlias, $aFields)
{
$aField = array();
$aField = [];
$aField['code'] = 'id';
$aField['class'] = $sClass;
$aField['class_alias'] = $sClassAlias;
$aField['label'] = 'Id';
$aField['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC;
$aField['is_null_allowed'] = false;
$aNewFields = array($sClassAlias.'.id' => $aField);
$aNewFields = [$sClassAlias.'.id' => $aField];
$aFields = array_merge($aNewFields, $aFields);
return $aFields;
}
@@ -690,50 +628,34 @@ class SearchForm
*/
private function AppendField($sClass, $sClassAlias, $sAttCode, $oAttDef, $aFields, $bHasIndex = false)
{
if (!is_null($oAttDef) && ($oAttDef->GetSearchType() != AttributeDefinition::SEARCH_WIDGET_TYPE_RAW))
{
if (method_exists($oAttDef, 'GetLabelForSearchField'))
{
if (!is_null($oAttDef) && ($oAttDef->GetSearchType() != AttributeDefinition::SEARCH_WIDGET_TYPE_RAW)) {
if (method_exists($oAttDef, 'GetLabelForSearchField')) {
$sLabel = $oAttDef->GetLabelForSearchField();
}
else
{
if ($sAttCode == 'friendlyname')
{
try
{
} else {
if ($sAttCode == 'friendlyname') {
try {
$sLabel = MetaModel::GetName($sClass);
}
catch (Exception $e)
{
} catch (Exception $e) {
$sLabel = $oAttDef->GetLabel();
}
}
else
{
} else {
$sLabel = $oAttDef->GetLabel();
}
}
if ($oAttDef instanceof AttributeExternalField)
{
if ($oAttDef instanceof AttributeExternalField) {
$oTargetAttDef = $oAttDef->GetFinalAttDef();
}
else
{
} else {
$oTargetAttDef = $oAttDef;
}
if (method_exists($oTargetAttDef, 'GetTargetClass'))
{
if (method_exists($oTargetAttDef, 'GetTargetClass')) {
$sTargetClass = $oTargetAttDef->GetTargetClass();
}
else
{
} else {
$sTargetClass = $oTargetAttDef->GetHostClass();
}
$aField = array();
$aField = [];
$aField['code'] = $sAttCode;
$aField['class'] = $sClass;
$aField['class_alias'] = $sClassAlias;
@@ -775,28 +697,24 @@ class SearchForm
* @throws \CoreException
* @throws \MissingQueryArgument
*/
protected function GetDefaultCriteria($oSearch, $aExistingCriteria, &$aContextParams = array())
protected function GetDefaultCriteria($oSearch, $aExistingCriteria, &$aContextParams = [])
{
$sClass = $oSearch->GetClass();
$aList = MetaModel::GetZListItems($sClass, 'default_search');
while (empty($aList))
{
while (empty($aList)) {
// search in parent class if default criteria are defined
$sClass = MetaModel::GetParentClass($sClass);
if (is_null($sClass))
{
if (is_null($sClass)) {
return $aExistingCriteria;
}
$aList = MetaModel::GetZListItems($sClass, 'default_search');
}
$sAlias = $oSearch->GetClassAlias();
$aAndCriteria = $aExistingCriteria['and'];
foreach($aList as $sAttCode)
{
foreach ($aList as $sAttCode) {
$oExpression = new FieldExpression($sAttCode, $sAlias);
$bIsRemovable = true;
if (isset($aContextParams[$sAttCode]))
{
if (isset($aContextParams[$sAttCode])) {
// When a context parameter exists, use it with the default search criteria
$oFieldExpression = $oExpression;
$oScalarExpression = new \ScalarExpression($aContextParams[$sAttCode]);
@@ -810,7 +728,7 @@ class SearchForm
$this->AddCriterion($aCriterion, $aAndCriteria);
}
// Overwrite with default criterion
$aCriteria = array('and' => $aAndCriteria);
$aCriteria = ['and' => $aAndCriteria];
return $aCriteria;
}
@@ -821,22 +739,18 @@ class SearchForm
*/
private function AddCriterion($aCriterion, &$aAndCriterion)
{
if ($aCriterion['is_removable'])
{
if ($aCriterion['is_removable']) {
// Check if the criterion is already present
// Non-removable criteria are mandatory
$ref = $aCriterion['ref'];
foreach ($aAndCriterion as $aExistingCriterion)
{
if (isset($aExistingCriterion['ref']) && ($ref === $aExistingCriterion['ref']))
{
foreach ($aAndCriterion as $aExistingCriterion) {
if (isset($aExistingCriterion['ref']) && ($ref === $aExistingCriterion['ref'])) {
// Already present do nothing
return;
}
}
}
if (isset($aCriterion['widget']) && ($aCriterion['widget'] != AttributeDefinition::SEARCH_WIDGET_TYPE_RAW))
{
if (isset($aCriterion['widget']) && ($aCriterion['widget'] != AttributeDefinition::SEARCH_WIDGET_TYPE_RAW)) {
$aAndCriterion[] = $aCriterion;
}
}

View File

@@ -11,7 +11,6 @@ define('STATUS_RUNNING', 'RUNNING');
class Status
{
/**
* @throws \CoreException
* @throws \DictExceptionUnknownLanguage
@@ -88,4 +87,4 @@ class Status
//Check if application could be started
MetaModel::Startup($soConfigFile, true);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -42,10 +43,10 @@ use ZipArchive;
abstract class Controller extends AbstractController
{
const ENUM_PAGE_TYPE_HTML = 'html';
const ENUM_PAGE_TYPE_BASIC_HTML = 'basic_html';
const ENUM_PAGE_TYPE_AJAX = 'ajax';
const ENUM_PAGE_TYPE_SETUP = 'setup';
public const ENUM_PAGE_TYPE_HTML = 'html';
public const ENUM_PAGE_TYPE_BASIC_HTML = 'basic_html';
public const ENUM_PAGE_TYPE_AJAX = 'ajax';
public const ENUM_PAGE_TYPE_SETUP = 'setup';
/** @var \Twig\Environment */
private $m_oTwig;
@@ -101,8 +102,7 @@ abstract class Controller extends AbstractController
if ($sModuleName != 'core') {
try {
$this->m_aDefaultParams = ['sIndexURL' => utils::GetAbsoluteUrlModulePage($this->m_sModule, 'index.php')];
}
catch (Exception $e) {
} catch (Exception $e) {
IssueLog::Error($e->getMessage());
}
}
@@ -117,12 +117,9 @@ abstract class Controller extends AbstractController
$sModulePath = dirname(dirname($this->GetDir()));
$this->SetModuleName(basename($sModulePath));
$this->SetViewPath($sModulePath.'/view');
try
{
$this->m_aDefaultParams = array('sIndexURL' => utils::GetAbsoluteUrlModulePage($this->m_sModule, 'index.php'));
}
catch (Exception $e)
{
try {
$this->m_aDefaultParams = ['sIndexURL' => utils::GetAbsoluteUrlModulePage($this->m_sModule, 'index.php')];
} catch (Exception $e) {
IssueLog::Error($e->getMessage());
}
}
@@ -164,8 +161,7 @@ abstract class Controller extends AbstractController
*/
public function HandleOperation()
{
try
{
try {
$this->CheckAccess();
$this->m_sOperation = utils::ReadParam('operation', $this->m_sDefaultOperation);
@@ -182,9 +178,7 @@ abstract class Controller extends AbstractController
}
$this->DisplayBadRequest();
}
catch (Exception $e)
{
} catch (Exception $e) {
http_response_code(500);
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
@@ -202,8 +196,7 @@ abstract class Controller extends AbstractController
*/
public function HandleAjaxOperation()
{
try
{
try {
$this->CheckAccess();
$this->m_sOperation = utils::ReadParam('operation', $this->m_sDefaultOperation);
@@ -217,11 +210,9 @@ abstract class Controller extends AbstractController
}
$this->DisplayPageNotFound();
}
catch (Exception $e)
{
} catch (Exception $e) {
http_response_code(500);
$aResponse = array('sError' => $e->getMessage());
$aResponse = ['sError' => $e->getMessage()];
echo json_encode($aResponse);
}
}
@@ -261,8 +252,7 @@ abstract class Controller extends AbstractController
*/
protected function CheckAccess()
{
if ($this->m_bCheckDemoMode && MetaModel::GetConfig()->Get('demo_mode'))
{
if ($this->m_bCheckDemoMode && MetaModel::GetConfig()->Get('demo_mode')) {
throw new Exception("Sorry, iTop is in <b>demonstration mode</b>: this feature is disabled.");
}
@@ -270,31 +260,32 @@ abstract class Controller extends AbstractController
$sConfiguredAccessTokenValue = empty($this->m_sAccessTokenConfigParamId) ? "" : trim(MetaModel::GetConfig()->GetModuleSetting($sExecModule, $this->m_sAccessTokenConfigParamId));
if (empty($sExecModule) || empty($sConfiguredAccessTokenValue)){
if (empty($sExecModule) || empty($sConfiguredAccessTokenValue)) {
LoginWebPage::DoLogin($this->m_bMustBeAdmin);
} else {
//token mode without login required
//N°7147 - Error HTTP 500 due to access_token not URL decoded
$sPassedToken = utils::ReadPostedParam($this->m_sAccessTokenConfigParamId, null, false, 'raw_data');
if (is_null($sPassedToken)){
if (is_null($sPassedToken)) {
$sPassedToken = utils::ReadParam($this->m_sAccessTokenConfigParamId, null, false, 'raw_data');
}
$sDecodedPassedToken = urldecode($sPassedToken);
if ($sDecodedPassedToken !== $sConfiguredAccessTokenValue){
if ($sDecodedPassedToken !== $sConfiguredAccessTokenValue) {
$sMsg = "Invalid token passed under '$this->m_sAccessTokenConfigParamId' http param to reach '$sExecModule' page.";
IssueLog::Error($sMsg, null,
IssueLog::Error(
$sMsg,
null,
[
'sHtmlDecodedToken' => $sDecodedPassedToken,
'conf param ID' => $this->m_sAccessTokenConfigParamId
'conf param ID' => $this->m_sAccessTokenConfigParamId,
]
);
throw new Exception("Invalid token");
}
}
if (!empty($this->m_sMenuId))
{
if (!empty($this->m_sMenuId)) {
ApplicationMenu::CheckMenuIdEnabled($this->m_sMenuId);
}
}
@@ -384,7 +375,7 @@ abstract class Controller extends AbstractController
*
* @throws \Exception
*/
public function DisplayAjaxPage($aParams = array(), $sTemplateName = null)
public function DisplayAjaxPage($aParams = [], $sTemplateName = null)
{
$this->DisplayPage($aParams, $sTemplateName, 'ajax');
}
@@ -399,7 +390,7 @@ abstract class Controller extends AbstractController
*
* @throws \Exception
*/
public function DisplaySetupPage($aParams = array(), $sTemplateName = null)
public function DisplaySetupPage($aParams = [], $sTemplateName = null)
{
$this->DisplayPage($aParams, $sTemplateName, 'setup');
}
@@ -415,7 +406,7 @@ abstract class Controller extends AbstractController
*
* @throws \Exception
*/
public function DisplayPage($aParams = array(), $sTemplateName = null, $sPageType = 'html')
public function DisplayPage($aParams = [], $sTemplateName = null, $sPageType = 'html')
{
if (empty($sTemplateName)) {
$sTemplateName = $this->m_sOperation;
@@ -472,13 +463,12 @@ abstract class Controller extends AbstractController
* @param int $iResponseCode HTTP response code
* @param array $aHeaders additional HTTP headers
*/
public function DisplayJSONPage($aParams = array(), $iResponseCode = 200, $aHeaders = array())
public function DisplayJSONPage($aParams = [], $iResponseCode = 200, $aHeaders = [])
{
$oKpi = new ExecutionKPI();
http_response_code($iResponseCode);
header('Content-Type: application/json');
foreach ($aHeaders as $sHeader)
{
foreach ($aHeaders as $sHeader) {
header($sHeader);
}
$sJSON = json_encode($aParams);
@@ -501,7 +491,7 @@ abstract class Controller extends AbstractController
*
* @since 3.0.1 3.1.0 Add $sReportFileName parameter
*/
public function DownloadZippedPage($aParams = array(), $sTemplateName = null, $sReportFileName = 'itop-system-information-report')
public function DownloadZippedPage($aParams = [], $sTemplateName = null, $sReportFileName = 'itop-system-information-report')
{
if (empty($sTemplateName)) {
$sTemplateName = $this->m_sOperation;
@@ -516,7 +506,7 @@ abstract class Controller extends AbstractController
file_put_contents($sHTMLReport, ob_get_contents());
ob_end_clean();
$this->ZipDownloadRemoveFile(array($sHTMLReport), $sZIPReportFile, true);
$this->ZipDownloadRemoveFile([$sHTMLReport], $sZIPReportFile, true);
}
/**
@@ -531,16 +521,13 @@ abstract class Controller extends AbstractController
$sArchiveFileFullPath = tempnam(SetupUtils::GetTmpDir(), 'itop_download-').'.zip';
$oArchive = new ZipArchive();
$oArchive->open($sArchiveFileFullPath, ZipArchive::CREATE);
foreach ($aFiles as $sFile)
{
foreach ($aFiles as $sFile) {
$oArchive->addFile($sFile, basename($sFile));
}
$oArchive->close();
if ($bUnlinkFiles)
{
foreach ($aFiles as $sFile)
{
if ($bUnlinkFiles) {
foreach ($aFiles as $sFile) {
unlink($sFile);
}
}
@@ -548,13 +535,12 @@ abstract class Controller extends AbstractController
$this->SendFileContent($sArchiveFileFullPath, $sDownloadArchiveName.'.zip', true, true);
}
final protected function SendFileContent($sFilePath, $sDownloadArchiveName = null, $bFileTransfer = true, $bRemoveFile = false, $aHeaders = array())
final protected function SendFileContent($sFilePath, $sDownloadArchiveName = null, $bFileTransfer = true, $bRemoveFile = false, $aHeaders = [])
{
$sFileMimeType = utils::GetFileMimeType($sFilePath);
header('Content-Type: '.$sFileMimeType);
if ($bFileTransfer)
{
if ($bFileTransfer) {
header('Content-Disposition: attachment; filename="'.$sDownloadArchiveName.'"');
}
@@ -570,8 +556,7 @@ abstract class Controller extends AbstractController
readfile($sFilePath);
if ($bRemoveFile)
{
if ($bRemoveFile) {
unlink($sFilePath);
}
exit(0);
@@ -631,7 +616,7 @@ abstract class Controller extends AbstractController
if (is_null($sLabel)) {
$sLabel = Dict::S($sCode);
}
$this->m_aAjaxTabs[$sCode] = array('label' => $sLabel, 'url' => $sURL, 'cache' => $bCache);
$this->m_aAjaxTabs[$sCode] = ['label' => $sLabel, 'url' => $sURL, 'cache' => $bCache];
}
/**
@@ -647,7 +632,8 @@ abstract class Controller extends AbstractController
* @since 2.7.7 3.0.1 3.1.0 N°4760 method creation
* @see Controller::SetBreadCrumbEntry() to set breadcrumb content (by default will be title)
*/
public function DisableBreadCrumb() {
public function DisableBreadCrumb()
{
$this->m_bIsBreadCrumbEnabled = false;
}
@@ -655,7 +641,8 @@ abstract class Controller extends AbstractController
* @since 2.7.7 3.0.1 3.1.0 N°4760 method creation
* @see iTopWebPage::SetBreadCrumbEntry()
*/
public function SetBreadCrumbEntry($sId, $sLabel, $sDescription, $sUrl = '', $sIcon = '') {
public function SetBreadCrumbEntry($sId, $sLabel, $sDescription, $sUrl = '', $sIcon = '')
{
$this->m_aBreadCrumbEntry = [$sId, $sLabel, $sDescription, $sUrl, $sIcon];
}
@@ -669,20 +656,15 @@ abstract class Controller extends AbstractController
*/
private function RenderTemplate($aParams, $sName, $sTemplateFileExtension)
{
if (empty($this->m_oTwig))
{
if (empty($this->m_oTwig)) {
throw new Exception('Not initialized. Call Controller::InitFromModule() or Controller::SetViewPath() before any display');
}
try
{
try {
return $this->m_oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams);
}
catch (SyntaxError $e) {
} catch (SyntaxError $e) {
IssueLog::Error($e->getMessage().' - file: '.$e->getFile().'('.$e->getLine().')');
}
catch (Error $e) {
if (strpos($e->getMessage(), 'Unable to find template') === false)
{
} catch (Error $e) {
if (strpos($e->getMessage(), 'Unable to find template') === false) {
IssueLog::Error($e->getMessage());
}
}
@@ -697,8 +679,7 @@ abstract class Controller extends AbstractController
*/
private function CreatePage($sPageType)
{
switch ($sPageType)
{
switch ($sPageType) {
case self::ENUM_PAGE_TYPE_HTML:
$this->m_oPage = new iTopWebPage($this->GetOperationTitle(), false);
$this->m_oPage->add_http_headers();

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\TwigBase\Twig;
use ApplicationMenu;
use AttributeDate;
use AttributeDateTime;
@@ -76,8 +76,7 @@ class Extension
if (preg_match('@^\d\d\d\d-\d\d-\d\d$@', trim($sDate))) {
return AttributeDate::GetFormat()->Format($sDate);
}
}
catch (Exception $e) {
} catch (Exception $e) {
}
return $sDate;
@@ -202,7 +201,8 @@ class Extension
// Function to render a UI block (HTML, inline CSS, inline JS) and its sub blocks directly in the TWIG
// Usage in twig: {{ render_block(oBlock) }}
/** @since 3.0.0 */
$aFunctions[] = new TwigFunction('render_block',
$aFunctions[] = new TwigFunction(
'render_block',
function (iUIBlock $oBlock, $aContextParams = []) {
$oRenderer = new BlockRenderer($oBlock, $aContextParams);
@@ -211,28 +211,29 @@ class Extension
['is_safe' => ['html']]
);
/** @since 3.2.0 */
$aFunctions[] = new TwigFunction('source_abs', function (Environment $oEnv, $sUrlAbsName) {
// Extract the source path from the absolute url and replace it with approot
$sAppRootAbsName = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sUrlAbsName);
$oLoader = $oEnv->getLoader();
// Check if the file is in any of the twig paths
if($oLoader instanceof FilesystemLoader) {
$aPaths = $oLoader->getPaths();
foreach ($aPaths as $sPath) {
$sTwigPathRelativeName = substr($sAppRootAbsName, strlen($sPath) + 1);
// If we find our path in the absolute url and the file actually exist, return it
if (str_contains($sAppRootAbsName, $sPath) && $oLoader->exists($sTwigPathRelativeName)) {
return $oLoader->getSourceContext($sTwigPathRelativeName)->getCode();
$aFunctions[] = new TwigFunction(
'source_abs',
function (Environment $oEnv, $sUrlAbsName) {
// Extract the source path from the absolute url and replace it with approot
$sAppRootAbsName = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sUrlAbsName);
$oLoader = $oEnv->getLoader();
// Check if the file is in any of the twig paths
if ($oLoader instanceof FilesystemLoader) {
$aPaths = $oLoader->getPaths();
foreach ($aPaths as $sPath) {
$sTwigPathRelativeName = substr($sAppRootAbsName, strlen($sPath) + 1);
// If we find our path in the absolute url and the file actually exist, return it
if (str_contains($sAppRootAbsName, $sPath) && $oLoader->exists($sTwigPathRelativeName)) {
return $oLoader->getSourceContext($sTwigPathRelativeName)->getCode();
}
}
}
}
// Otherwise return empty content
$oEmptySource = new Source('', $sUrlAbsName, '');
return $oEmptySource->getCode();
},
['needs_environment' => true,
// Otherwise return empty content
$oEmptySource = new Source('', $sUrlAbsName, '');
return $oEmptySource->getCode();
},
['needs_environment' => true,
'is_safe' => ['all']]
);

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -20,7 +21,6 @@ use Twig\Error\Error;
use Twig\Loader\FilesystemLoader;
use utils;
/**
* Class TwigHelper
*
@@ -73,7 +73,7 @@ class TwigHelper
* @return Environment
* @throws \Twig\Error\LoaderError
*/
public static function GetTwigEnvironment($sViewPath, $aAdditionalPaths = array())
public static function GetTwigEnvironment($sViewPath, $aAdditionalPaths = [])
{
$oLoader = new FilesystemLoader($sViewPath);
foreach ($aAdditionalPaths as $sAdditionalPath) {
@@ -108,7 +108,7 @@ class TwigHelper
* @throws \Exception
* @api
*/
public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = self::DEFAULT_FILE_TYPE)
public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = [], $sDefaultType = self::DEFAULT_FILE_TYPE)
{
$oTwig = self::GetTwigEnvironment($sViewPath);
$oTwig->addGlobal('UIBlockParent', [$oPage]);
@@ -132,7 +132,7 @@ class TwigHelper
* @throws \Twig\Error\LoaderError
* @since 3.0.0
*/
public static function RenderIntoBlock(WebPage $oPage, UIBlock $oBlock, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = self::DEFAULT_FILE_TYPE)
public static function RenderIntoBlock(WebPage $oPage, UIBlock $oBlock, $sViewPath, $sTemplateName, $aParams = [], $sDefaultType = self::DEFAULT_FILE_TYPE)
{
$oTwig = self::GetTwigEnvironment($sViewPath);
$oTwig->addGlobal('UIBlockParent', [$oBlock]);
@@ -161,8 +161,7 @@ class TwigHelper
$oKPI->ComputeStats('Render TWIG', $sFileName);
return $sResult;
}
catch (Error $oTwigException) {
} catch (Error $oTwigException) {
$oTwigPreviousException = $oTwigException->getPrevious();
if (!is_null(($oTwigPreviousException)) && ($oTwigPreviousException instanceof CoreTemplateException)) {
// handles recursive calls : if we're here, an exception was already raised in a child template !

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI;
use Combodo\iTop\Application\UI\Base\iUIBlockFactory;
use Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery;
use Twig\Extension\AbstractExtension;
@@ -36,4 +35,4 @@ class UIBlockExtension extends AbstractExtension
return $aParsers;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI;
use Exception;
use ReflectionClass;
use ReflectionException;
@@ -159,4 +158,4 @@ class UIBlockNode extends Node
}
$oCompiler->write("ob_start();\n");
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
@@ -30,7 +29,6 @@ class UIBlockParser extends AbstractTokenParser
/** @var string */
protected $sBlockClassName;
/**
* UIBlockParser constructor.
*
@@ -44,7 +42,6 @@ class UIBlockParser extends AbstractTokenParser
$this->bHasSubBlocks = is_subclass_of($this->sBlockClassName, "Combodo\\iTop\\Application\\UI\\Base\\Layout\\UIContentBlock") || $this->sBlockClassName == "Combodo\\iTop\\Application\\UI\\Base\\Layout\\UIContentBlock";
}
/**
* @inheritDoc
*/
@@ -81,4 +78,4 @@ class UIBlockParser extends AbstractTokenParser
{
return $sToken->test('End'.$this->sTag);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base;
/**
* Class AbstractUIBlockFactory
*
@@ -46,4 +45,4 @@ abstract class AbstractUIBlockFactory implements iUIBlockFactory
{
return static::UI_BLOCK_CLASS_NAME;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Alert;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
@@ -254,10 +254,9 @@ class Alert extends UIContentBlock
*/
public function IsOpenedByDefault(): bool
{
if($this->IsCollapsible()) {
if ($this->IsCollapsible()) {
return $this->bIsOpenedByDefault;
}
else {
} else {
return true;
}
}
@@ -292,4 +291,4 @@ class Alert extends UIContentBlock
return $this->sSectionStateStorageKey;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -158,4 +159,4 @@ class AlertUIBlockFactory extends AbstractUIBlockFactory
{
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_SECONDARY, $sId);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Breadcrumbs;
use Combodo\iTop\Application\UI\Base\UIBlock;
use MetaModel;
use utils;
@@ -90,8 +90,7 @@ class Breadcrumbs extends UIBlock
$aJsWidgetOptions = [];
$iBreadCrumbMaxCount = utils::GetConfig()->Get('breadcrumb.max_count');
if ($iBreadCrumbMaxCount > 1)
{
if ($iBreadCrumbMaxCount > 1) {
$oConfig = MetaModel::GetConfig();
$siTopInstanceId = $oConfig->GetItopInstanceid();
@@ -104,4 +103,4 @@ class Breadcrumbs extends UIBlock
return $aJsWidgetOptions;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Button;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -39,7 +39,7 @@ class Button extends UIBlock
'js/components/button.js',
];
public const REQUIRES_ANCESTORS_DEFAULT_JS_FILES = true;
// Specific constants
/** @var string ENUM_ACTION_TYPE_REGULAR */
public const ENUM_ACTION_TYPE_REGULAR = 'regular';
@@ -271,4 +271,4 @@ class Button extends UIBlock
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Button;
/**
* Class Button
*
@@ -66,19 +66,34 @@ class ButtonJS extends Button
* @param string $sOnClickJsCode
*/
public function __construct(
string $sLabel, string $sId = null, string $sName = '', string $sValue = '', string $sType = self::DEFAULT_TYPE,
string $sTooltip = '', string $sIconClass = '',
string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColor = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '',
string $sLabel,
string $sId = null,
string $sName = '',
string $sValue = '',
string $sType = self::DEFAULT_TYPE,
string $sTooltip = '',
string $sIconClass = '',
string $sActionType = self::DEFAULT_ACTION_TYPE,
string $sColor = self::DEFAULT_COLOR_SCHEME,
string $sJsCode = '',
string $sOnClickJsCode = ''
) {
parent::__construct( $sLabel,$sId, $sTooltip, $sIconClass,
$sActionType, $sColor, $sJsCode, $sOnClickJsCode);
parent::__construct(
$sLabel,
$sId,
$sTooltip,
$sIconClass,
$sActionType,
$sColor,
$sJsCode,
$sOnClickJsCode
);
$this->sName = $sName;
$this->sValue = $sValue;
$this->sType = $sType;
}
/**
* @return string
*/
@@ -135,4 +150,4 @@ class ButtonJS extends Button
$this->sValue = $sValue;
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -149,8 +150,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_DESTRUCTIVE,
Button::ENUM_ACTION_TYPE_REGULAR,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
//-------------------------------------------------
@@ -175,8 +183,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_NEUTRAL,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
/**
@@ -198,8 +213,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_PRIMARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_PRIMARY,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
/**
@@ -220,8 +242,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_SECONDARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_SECONDARY,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
/**
@@ -242,8 +271,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_VALIDATION, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_VALIDATION,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
/**
@@ -264,8 +300,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_DESTRUCTIVE,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
/**
@@ -289,8 +332,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
$sLabel = $sLabel ?? Dict::S('UI:Button:Cancel');
$sName = $sName ?? 'cancel';
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
return static::MakeForAction(
$sLabel,
Button::ENUM_COLOR_SCHEME_NEUTRAL,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
}
/**
@@ -311,8 +361,15 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
bool $bIsSubmit = false,
?string $sId = null
) {
$oButton = static::MakeForAction('', Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
$oButton = static::MakeForAction(
'',
Button::ENUM_COLOR_SCHEME_NEUTRAL,
Button::ENUM_ACTION_TYPE_ALTERNATIVE,
$sValue,
$sName,
$bIsSubmit,
$sId
);
$oButton->SetIconClass($sIconClasses);
$oButton->SetTooltip($sTooltipText);
@@ -335,14 +392,17 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeLinkNeutral(
string $sURL, ?string $sLabel = '', ?string $sIconClasses = null, ?string $sTarget = null,
string $sURL,
?string $sLabel = '',
?string $sIconClasses = null,
?string $sTarget = null,
?string $sId = null
) {
if (empty($sTarget)) {
$sTarget = ButtonURL::DEFAULT_TARGET;
}
$sType = empty($sIconClasses) ? Button::ENUM_ACTION_TYPE_REGULAR : Button::ENUM_ACTION_TYPE_ALTERNATIVE;
$oButton = static::MakeForLink($sLabel, $sURL,Button::ENUM_COLOR_SCHEME_NEUTRAL, $sType, $sTarget, $sId);
$oButton = static::MakeForLink($sLabel, $sURL, Button::ENUM_COLOR_SCHEME_NEUTRAL, $sType, $sTarget, $sId);
if (!empty($sIconClasses)) {
$oButton->SetIconClass($sIconClasses);
@@ -361,19 +421,22 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonURL
*/
public static function MakeIconLink(
string $sIconClasses, string $sTooltipText, ?string $sURL = '', ?string $sTarget = null,
string $sIconClasses,
string $sTooltipText,
?string $sURL = '',
?string $sTarget = null,
?string $sId = null
) {
if (empty($sTarget)) {
$sTarget = ButtonURL::DEFAULT_TARGET;
}
$oButton = static::MakeForLink('', $sURL,Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sTarget, $sId);
$oButton = static::MakeForLink('', $sURL, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sTarget, $sId);
$oButton->SetIconClass($sIconClasses);
$oButton->SetTooltip($sTooltipText);
return $oButton;
}
/**
* @param string $sIconClasses
* @param string $sTooltipText
@@ -385,10 +448,14 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeDestructiveIconLink(
string $sIconClasses, string $sTooltipText, ?string $sURL = null, ?string $sName = null, ?string $sTarget = null,
string $sIconClasses,
string $sTooltipText,
?string $sURL = null,
?string $sName = null,
?string $sTarget = null,
?string $sId = null
) {
$oButton = static::MakeIconLink($sIconClasses, $sTooltipText, $sURL, $sTarget, $sId);
$oButton = static::MakeIconLink($sIconClasses, $sTooltipText, $sURL, $sTarget, $sId);
$oButton->SetColor(Button::ENUM_COLOR_SCHEME_DESTRUCTIVE);
$oButton->SetTooltip($sTooltipText);
return $oButton;
@@ -467,7 +534,7 @@ class ButtonUIBlockFactory extends AbstractUIBlockFactory
$oButton = new ButtonURL($sLabel, $sURL, $sId, $sTarget);
$oButton->SetActionType($sActionType)
->SetColor($sColor);
return $oButton;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Button;
/**
* Class Button
*
@@ -37,15 +37,14 @@ class ButtonURL extends Button
/** @var string ENUM_TARGET_BLANK */
public const ENUM_TARGET_BLANK = '_blank';
/** @var string ENUM_TARGET_SELF */
public const ENUM_TARGET_SELF= '_self';
public const ENUM_TARGET_SELF = '_self';
/** @var string ENUM_TARGET_PARENT */
public const ENUM_TARGET_PARENT= '_parent';
public const ENUM_TARGET_PARENT = '_parent';
/** @var string ENUM_TARGET_TOP */
public const ENUM_TARGET_TOP= '_top';
public const ENUM_TARGET_TOP = '_top';
/** @var string DEFAULT_TARGET */
public const DEFAULT_TARGET = self::ENUM_TARGET_SELF;
/** @var string */
protected $sURL;
/** @var string */
@@ -66,12 +65,27 @@ class ButtonURL extends Button
* @param string $sOnClickJsCode
*/
public function __construct(
string $sLabel, string $sURL, string $sId = null, string $sTarget = self::DEFAULT_TARGET, string $sTooltip = '', string $sIconClass = '',
string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColor = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '',
string $sOnClickJsCode = '')
{
parent::__construct($sLabel, $sId, $sTooltip, $sIconClass,
$sActionType, $sColor, $sJsCode, $sOnClickJsCode);
string $sLabel,
string $sURL,
string $sId = null,
string $sTarget = self::DEFAULT_TARGET,
string $sTooltip = '',
string $sIconClass = '',
string $sActionType = self::DEFAULT_ACTION_TYPE,
string $sColor = self::DEFAULT_COLOR_SCHEME,
string $sJsCode = '',
string $sOnClickJsCode = ''
) {
parent::__construct(
$sLabel,
$sId,
$sTooltip,
$sIconClass,
$sActionType,
$sColor,
$sJsCode,
$sOnClickJsCode
);
$this->sURL = $sURL;
$this->sTarget = $sTarget;
}
@@ -86,7 +100,7 @@ class ButtonURL extends Button
/**
* @param string $sURL
*
*
* @return $this
*/
public function SetURL(string $sURL)
@@ -105,7 +119,7 @@ class ButtonURL extends Button
/**
* @param string $sTarget
*
*
* @return $this
*/
public function SetTarget(string $sTarget)
@@ -113,4 +127,4 @@ class ButtonURL extends Button
$this->sTarget = $sTarget;
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\ButtonGroup;
use Combodo\iTop\Application\UI\Base\Component\Button\Button;
use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
@@ -150,4 +150,4 @@ class ButtonGroup extends UIBlock
{
return array_merge($this->GetButtons(), $this->GetExtraBlocks());
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -55,4 +56,4 @@ class ButtonGroupUIBlockFactory extends AbstractUIBlockFactory
return $oButtonGroup;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\CollapsibleSection;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\tUIContentAreas;
@@ -99,4 +99,4 @@ class CollapsibleSection extends UIContentBlock
{
return $this->sSectionStateStorageKey;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\CollapsibleSection;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
@@ -36,4 +35,4 @@ class CollapsibleSectionUIBlockFactory extends AbstractUIBlockFactory
{
return new CollapsibleSection($sTitle, [], $sId);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
use utils;
@@ -55,10 +54,14 @@ class DashletBadge extends DashletContainer
* @param array $aRefreshParams
*/
public function __construct(
string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, ?string $sCreateActionUrl = '',
?string $sCreateActionLabel = '', array $aRefreshParams = []
)
{
string $sClassIconUrl,
string $sHyperlink,
string $iCount,
string $sClassLabel,
?string $sCreateActionUrl = '',
?string $sCreateActionLabel = '',
array $aRefreshParams = []
) {
parent::__construct();
$this->sClassIconUrl = $sClassIconUrl;
@@ -71,7 +74,6 @@ class DashletBadge extends DashletContainer
$this->sClassDescription = '';
}
/**
* @return string
*/
@@ -210,7 +212,7 @@ class DashletBadge extends DashletContainer
public function SetClassDescription(string $sClassDescription)
{
$this->sClassDescription = $sClassDescription;
return $this;
}
@@ -236,4 +238,4 @@ class DashletBadge extends DashletContainer
$('#".$this->sId."').unblock();";
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
class DashletContainer extends UIContentBlock
@@ -21,4 +20,4 @@ class DashletContainer extends UIContentBlock
$this->AddDataAttribute('role', static::BLOCK_CODE);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
/**
* Class DashletFactory
*
@@ -33,4 +32,4 @@ class DashletFactory
return new DashletPlainText($sText, $sId);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
/**
* Class DashletHeaderStatic
*
@@ -42,7 +41,6 @@ class DashletHeaderStatic extends DashletContainer
$this->sIconUrl = $sIconUrl;
}
/**
* @return string
*/
@@ -82,4 +80,4 @@ class DashletHeaderStatic extends DashletContainer
return $this;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
/**
* Class DashletPlainText
*
@@ -56,4 +55,4 @@ class DashletPlainText extends DashletContainer
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
use ApplicationContext;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
@@ -63,7 +63,6 @@ class DataTable extends UIContentBlock
public const DEFAULT_ACTION_ROW_CONFIRMATION = true;
/**
* Panel constructor.
*
@@ -95,17 +94,14 @@ class DataTable extends UIContentBlock
*/
public function SetAjaxUrl(string $sAjaxUrl)
{
if (strlen($sAjaxUrl) > 0)
{
if (strlen($sAjaxUrl) > 0) {
$oAppContext = new ApplicationContext();
if(strpos ($sAjaxUrl,'?')) {
if (strpos($sAjaxUrl, '?')) {
$this->sAjaxUrl = $sAjaxUrl.$oAppContext->GetForLink(true);
} else {
$this->sAjaxUrl = $sAjaxUrl."?".$oAppContext->GetForLink();
}
}
else
{
} else {
$this->sAjaxUrl = $sAjaxUrl;
}

View File

@@ -42,4 +42,4 @@ class DataTableConfig extends UIContentBlock
return $this->GetDataTable()->GetId();
}
}
}

View File

@@ -23,49 +23,49 @@ class DataTableSettings
/**
* @var array
*/
public $aClassAliases;
public $aClassAliases;
/**
* @var null|string
*/
public $sTableId;
public $sTableId;
/**
* @var int
*/
public $iDefaultPageSize;
public $iDefaultPageSize;
/**
* @var array
*/
public $aColumns;
public $aColumns;
/**
* @var array
*/
public $aSortOrder;
/**
* DataTableSettings constructor.
*
* @param $aClassAliases
* @param null $sTableId
*/
public function __construct($aClassAliases, $sTableId = null)
{
$this->aClassAliases = $aClassAliases;
$this->sTableId = $sTableId;
$this->iDefaultPageSize = 10;
$this->aColumns = array();
}
/**
* DataTableSettings constructor.
*
* @param $aClassAliases
* @param null $sTableId
*/
public function __construct($aClassAliases, $sTableId = null)
{
$this->aClassAliases = $aClassAliases;
$this->sTableId = $sTableId;
$this->iDefaultPageSize = 10;
$this->aColumns = [];
}
/**
* @return string
* @since 3.1.0
*/
public function __serialize() {
public function __serialize()
{
return serialize([
$this->aClassAliases,
$this->sTableId,
$this->iDefaultPageSize,
$this->aColumns
$this->aColumns,
]);
}
@@ -73,335 +73,343 @@ class DataTableSettings
* @param $data
* @since 3.1.0
*/
public function __unserialize($data) {
public function __unserialize($data)
{
list(
$this->aClassAliases,
$this->sTableId,
$this->iDefaultPageSize,
$this->aColumns
) = unserialize($data);
) = unserialize($data);
}
/**
* @param $iDefaultPageSize
* @param $aSortOrder
* @param $aColumns
*/
protected function Init($iDefaultPageSize, $aSortOrder, $aColumns)
{
$this->iDefaultPageSize = $iDefaultPageSize;
$this->aColumns = $aColumns;
$this->FixVisibleColumns();
}
/**
* @param $iDefaultPageSize
* @param $aSortOrder
* @param $aColumns
*/
protected function Init($iDefaultPageSize, $aSortOrder, $aColumns)
{
$this->iDefaultPageSize = $iDefaultPageSize;
$this->aColumns = $aColumns;
$this->FixVisibleColumns();
}
/**
* @return string
*/
public function serialize()
{
// Save only the 'visible' columns
$aColumns = array();
foreach ($this->aClassAliases as $sAlias => $sClass) {
$aColumns[$sAlias] = array();
if (isset($this->aColumns[$sAlias])) {
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
unset($aData['label']); // Don't save the display name
unset($aData['alias']); // Don't save the alias (redundant)
unset($aData['code']); // Don't save the code (redundant)
if ($aData['checked']) {
$aColumns[$sAlias][$sAttCode] = $aData;
}
}
}
}
return serialize(
array(
'iDefaultPageSize' => $this->iDefaultPageSize,
'aColumns' => $aColumns,
)
);
}
/**
* @return string
*/
public function serialize()
{
// Save only the 'visible' columns
$aColumns = [];
foreach ($this->aClassAliases as $sAlias => $sClass) {
$aColumns[$sAlias] = [];
if (isset($this->aColumns[$sAlias])) {
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
unset($aData['label']); // Don't save the display name
unset($aData['alias']); // Don't save the alias (redundant)
unset($aData['code']); // Don't save the code (redundant)
if ($aData['checked']) {
$aColumns[$sAlias][$sAttCode] = $aData;
}
}
}
}
return serialize(
[
'iDefaultPageSize' => $this->iDefaultPageSize,
'aColumns' => $aColumns,
]
);
}
/**
* @param string $sData
*
* @throws \Exception
*/
public function unserialize($sData)
{
$aData = unserialize($sData);
$this->iDefaultPageSize = $aData['iDefaultPageSize'];
$this->aColumns = $aData['aColumns'];
foreach ($this->aClassAliases as $sAlias => $sClass) {
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
$aFieldData = false;
if ($sAttCode == '_key_') {
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, null, true /* bChecked */, $aData['sort']);
} else if (MetaModel::isValidAttCode($sClass, $sAttCode)) {
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, $oAttDef, true /* bChecked */, $aData['sort']);
}
/**
* @param string $sData
*
* @throws \Exception
*/
public function unserialize($sData)
{
$aData = unserialize($sData);
$this->iDefaultPageSize = $aData['iDefaultPageSize'];
$this->aColumns = $aData['aColumns'];
foreach ($this->aClassAliases as $sAlias => $sClass) {
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
$aFieldData = false;
if ($sAttCode == '_key_') {
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, null, true /* bChecked */, $aData['sort']);
} elseif (MetaModel::isValidAttCode($sClass, $sAttCode)) {
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, $oAttDef, true /* bChecked */, $aData['sort']);
}
if ($aFieldData) {
$this->aColumns[$sAlias][$sAttCode] = $aFieldData;
} else {
unset($this->aColumns[$sAlias][$sAttCode]);
}
}
}
$this->FixVisibleColumns();
}
if ($aFieldData) {
$this->aColumns[$sAlias][$sAttCode] = $aFieldData;
} else {
unset($this->aColumns[$sAlias][$sAttCode]);
}
}
}
$this->FixVisibleColumns();
}
/**
* @param $aClassAliases
* @param $bViewLink
* @param $aDefaultLists
*
* @return DataTableSettings
* @throws \CoreException
* @throws \DictExceptionMissingString
*/
public static function GetDataModelSettings($aClassAliases, $bViewLink, $aDefaultLists)
{
$oSettings = new DataTableSettings($aClassAliases);
// Retrieve the class specific settings for each class/alias based on the 'list' ZList
//TODO let the caller pass some other default settings (another Zlist, extre fields...)
$aColumns = [];
$aSortOrder = [];
foreach ($aClassAliases as $sAlias => $sClass) {
if ($aDefaultLists == null) {
$aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClass, 'list'));
} else {
$aList = $aDefaultLists[$sAlias];
}
/**
* @param $aClassAliases
* @param $bViewLink
* @param $aDefaultLists
*
* @return DataTableSettings
* @throws \CoreException
* @throws \DictExceptionMissingString
*/
public static function GetDataModelSettings($aClassAliases, $bViewLink, $aDefaultLists)
{
$oSettings = new DataTableSettings($aClassAliases);
// Retrieve the class specific settings for each class/alias based on the 'list' ZList
//TODO let the caller pass some other default settings (another Zlist, extre fields...)
$aColumns = [];
$aSortOrder = [];
foreach ($aClassAliases as $sAlias => $sClass) {
if ($aDefaultLists == null) {
$aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClass, 'list'));
} else {
$aList = $aDefaultLists[$sAlias];
}
$aSortOrder = MetaModel::GetOrderByDefault($sClass);
if ($bViewLink) {
$sSort = 'none';
if (array_key_exists('friendlyname', $aSortOrder)) {
$sSort = $aSortOrder['friendlyname'] ? 'asc' : 'desc';
}
$sNormalizedFName = MetaModel::NormalizeFieldSpec($sClass, 'friendlyname');
if (array_key_exists($sNormalizedFName, $aSortOrder)) {
$sSort = $aSortOrder[$sNormalizedFName] ? 'asc' : 'desc';
}
$aColumns[$sAlias]['_key_'] = $oSettings->GetFieldData($sAlias, '_key_', null, true /* bChecked */, $sSort);
}
$aSortOrder = MetaModel::GetOrderByDefault($sClass);
if ($bViewLink) {
$sSort = 'none';
if (array_key_exists('friendlyname', $aSortOrder)) {
$sSort = $aSortOrder['friendlyname'] ? 'asc' : 'desc';
}
$sNormalizedFName = MetaModel::NormalizeFieldSpec($sClass, 'friendlyname');
if (array_key_exists($sNormalizedFName, $aSortOrder)) {
$sSort = $aSortOrder[$sNormalizedFName] ? 'asc' : 'desc';
}
$aColumns[$sAlias]['_key_'] = $oSettings->GetFieldData($sAlias, '_key_', null, true /* bChecked */, $sSort);
}
foreach ($aList as $sAttCode) {
$sSort = 'none';
if (array_key_exists($sAttCode, $aSortOrder)) {
$sSort = $aSortOrder[$sAttCode] ? 'asc' : 'desc';
}
$oAttDef = Metamodel::GetAttributeDef($sClass, $sAttCode);
$aFieldData = $oSettings->GetFieldData($sAlias, $sAttCode, $oAttDef, true /* bChecked */, $sSort);
if ($aFieldData) $aColumns[$sAlias][$sAttCode] = $aFieldData;
}
}
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
$oSettings->Init($iDefaultPageSize, $aSortOrder, $aColumns);
return $oSettings;
}
foreach ($aList as $sAttCode) {
$sSort = 'none';
if (array_key_exists($sAttCode, $aSortOrder)) {
$sSort = $aSortOrder[$sAttCode] ? 'asc' : 'desc';
}
$oAttDef = Metamodel::GetAttributeDef($sClass, $sAttCode);
$aFieldData = $oSettings->GetFieldData($sAlias, $sAttCode, $oAttDef, true /* bChecked */, $sSort);
if ($aFieldData) {
$aColumns[$sAlias][$sAttCode] = $aFieldData;
}
}
}
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
$oSettings->Init($iDefaultPageSize, $aSortOrder, $aColumns);
return $oSettings;
}
/**
* @throws \CoreException
*/
protected function FixVisibleColumns()
{
foreach ($this->aClassAliases as $sAlias => $sClass) {
if (!isset($this->aColumns[$sAlias])) {
continue;
}
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
// Remove non-existent columns
// TODO: check if the existing ones are still valid (in case their type changed)
if (($sAttCode != '_key_') && (!MetaModel::IsValidAttCode($sClass, $sAttCode))) {
unset($this->aColumns[$sAlias][$sAttCode]);
}
}
$aList = MetaModel::ListAttributeDefs($sClass);
/**
* @throws \CoreException
*/
protected function FixVisibleColumns()
{
foreach ($this->aClassAliases as $sAlias => $sClass) {
if (!isset($this->aColumns[$sAlias])) {
continue;
}
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
// Remove non-existent columns
// TODO: check if the existing ones are still valid (in case their type changed)
if (($sAttCode != '_key_') && (!MetaModel::IsValidAttCode($sClass, $sAttCode))) {
unset($this->aColumns[$sAlias][$sAttCode]);
}
}
$aList = MetaModel::ListAttributeDefs($sClass);
// Add the other (non visible ones), sorted in alphabetical order
$aTempData = array();
foreach ($aList as $sAttCode => $oAttDef) {
if ((!array_key_exists($sAttCode, $this->aColumns[$sAlias])) && (!($oAttDef instanceof AttributeLinkedSet || $oAttDef instanceof AttributeDashboard))) {
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, $oAttDef, false /* bChecked */, 'none');
if ($aFieldData) $aTempData[$aFieldData['label']] = $aFieldData;
}
}
ksort($aTempData);
foreach ($aTempData as $sLabel => $aFieldData) {
$this->aColumns[$sAlias][$aFieldData['code']] = $aFieldData;
}
}
}
// Add the other (non visible ones), sorted in alphabetical order
$aTempData = [];
foreach ($aList as $sAttCode => $oAttDef) {
if ((!array_key_exists($sAttCode, $this->aColumns[$sAlias])) && (!($oAttDef instanceof AttributeLinkedSet || $oAttDef instanceof AttributeDashboard))) {
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, $oAttDef, false /* bChecked */, 'none');
if ($aFieldData) {
$aTempData[$aFieldData['label']] = $aFieldData;
}
}
}
ksort($aTempData);
foreach ($aTempData as $sLabel => $aFieldData) {
$this->aColumns[$sAlias][$aFieldData['code']] = $aFieldData;
}
}
}
/**
* @param $aClassAliases
* @param null $sTableId
* @param bool $bOnlyOnTable
*
* @return DataTableSettings|null
* @throws \Exception
*/
static public function GetTableSettings($aClassAliases, $sTableId = null, $bOnlyOnTable = false)
{
$pref = null;
$oSettings = new DataTableSettings($aClassAliases, $sTableId);
/**
* @param $aClassAliases
* @param null $sTableId
* @param bool $bOnlyOnTable
*
* @return DataTableSettings|null
* @throws \Exception
*/
public static function GetTableSettings($aClassAliases, $sTableId = null, $bOnlyOnTable = false)
{
$pref = null;
$oSettings = new DataTableSettings($aClassAliases, $sTableId);
if ($sTableId != null) {
// An identified table, let's fetch its own settings (if any)
$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey($sTableId), null);
}
if ($sTableId != null) {
// An identified table, let's fetch its own settings (if any)
$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey($sTableId), null);
}
if ($pref == null) {
if (!$bOnlyOnTable) {
// Try the global preferred values for this class / set of classes
$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey(null), null);
}
if ($pref == null) {
// no such settings, use the default values provided by the data model
return null;
}
}
$oSettings->unserialize($pref);
if ($pref == null) {
if (!$bOnlyOnTable) {
// Try the global preferred values for this class / set of classes
$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey(null), null);
}
if ($pref == null) {
// no such settings, use the default values provided by the data model
return null;
}
}
$oSettings->unserialize($pref);
return $oSettings;
}
return $oSettings;
}
/**
* @return array
*/
public function GetSortOrder()
{
$aSortOrder = array();
foreach ($this->aColumns as $sAlias => $aColumns) {
foreach ($aColumns as $aColumn) {
if ($aColumn['sort'] != 'none') {
$sCode = ($aColumn['code'] == '_key_') ? 'friendlyname' : $aColumn['code'];
$aSortOrder[$sCode] = ($aColumn['sort'] == 'asc'); // true for ascending, false for descending
}
}
break; // TODO: For now the Set object supports only sorting on the first class of the set
}
return $aSortOrder;
}
/**
* @return array
*/
public function GetSortOrder()
{
$aSortOrder = [];
foreach ($this->aColumns as $sAlias => $aColumns) {
foreach ($aColumns as $aColumn) {
if ($aColumn['sort'] != 'none') {
$sCode = ($aColumn['code'] == '_key_') ? 'friendlyname' : $aColumn['code'];
$aSortOrder[$sCode] = ($aColumn['sort'] == 'asc'); // true for ascending, false for descending
}
}
break; // TODO: For now the Set object supports only sorting on the first class of the set
}
return $aSortOrder;
}
/**
* @param null $sTargetTableId
*
* @return bool
*/
public function Save($sTargetTableId = null)
{
$sSaveId = is_null($sTargetTableId) ? $this->sTableId : $sTargetTableId;
if ($sSaveId == null) return false; // Cannot save, the table is not identified, use SaveAsDefault instead
/**
* @param null $sTargetTableId
*
* @return bool
*/
public function Save($sTargetTableId = null)
{
$sSaveId = is_null($sTargetTableId) ? $this->sTableId : $sTargetTableId;
if ($sSaveId == null) {
return false;
} // Cannot save, the table is not identified, use SaveAsDefault instead
$sSettings = $this->serialize();
appUserPreferences::SetPref($this->GetPrefsKey($sSaveId), $sSettings);
return true;
}
$sSettings = $this->serialize();
appUserPreferences::SetPref($this->GetPrefsKey($sSaveId), $sSettings);
return true;
}
/**
* @return bool
*/
public function SaveAsDefault()
{
$sSettings = $this->serialize();
appUserPreferences::SetPref($this->GetPrefsKey(null), $sSettings);
return true;
}
/**
* @return bool
*/
public function SaveAsDefault()
{
$sSettings = $this->serialize();
appUserPreferences::SetPref($this->GetPrefsKey(null), $sSettings);
return true;
}
/**
* Clear the preferences for this particular table
* @param $bResetAll boolean If true,the settings for all tables of the same class(es)/alias(es) are reset
*/
public function ResetToDefault($bResetAll)
{
if (($this->sTableId == null) && (!$bResetAll)) {
return false;
} // Cannot reset, the table is not identified, use force $bResetAll instead
if ($bResetAll) {
// Turn the key into a suitable PCRE pattern
$sKey = $this->GetPrefsKey(null);
$sPattern = str_replace(['|'], ['\\|'], $sKey); // escape the | character
$sPattern = '#^'.str_replace(['*'], ['.*'], $sPattern).'$#'; // Don't use slash as the delimiter since it's used in our key to delimit aliases
appUserPreferences::UnsetPref($sPattern, true);
} else {
appUserPreferences::UnsetPref($this->GetPrefsKey($this->sTableId), false);
}
return true;
}
/**
* Clear the preferences for this particular table
* @param $bResetAll boolean If true,the settings for all tables of the same class(es)/alias(es) are reset
*/
public function ResetToDefault($bResetAll)
{
if (($this->sTableId == null) && (!$bResetAll)) return false; // Cannot reset, the table is not identified, use force $bResetAll instead
if ($bResetAll) {
// Turn the key into a suitable PCRE pattern
$sKey = $this->GetPrefsKey(null);
$sPattern = str_replace(array('|'), array('\\|'), $sKey); // escape the | character
$sPattern = '#^' . str_replace(array('*'), array('.*'), $sPattern) . '$#'; // Don't use slash as the delimiter since it's used in our key to delimit aliases
appUserPreferences::UnsetPref($sPattern, true);
} else {
appUserPreferences::UnsetPref($this->GetPrefsKey($this->sTableId), false);
}
return true;
}
/**
* @param null $sTableId
*
* @return string
*/
protected function GetPrefsKey($sTableId = null)
{
return static::GetAppUserPreferenceKey($this->aClassAliases, $sTableId);
}
/**
* @param null $sTableId
*
* @return string
*/
protected function GetPrefsKey($sTableId = null)
{
return static::GetAppUserPreferenceKey($this->aClassAliases, $sTableId);
}
public static function GetAppUserPreferenceKey($aClassAliases, $sTableId)
{
if ($sTableId === null) {
$sTableId = '*';
}
public static function GetAppUserPreferenceKey($aClassAliases, $sTableId)
{
if ($sTableId === null) {
$sTableId = '*';
}
$aKeys = [];
foreach ($aClassAliases as $sAlias => $sClass) {
$aKeys[] = $sAlias.'-'.$sClass;
}
return implode('/', $aKeys).'|'.$sTableId;
}
$aKeys = array();
foreach ($aClassAliases as $sAlias => $sClass) {
$aKeys[] = $sAlias . '-' . $sClass;
}
return implode('/', $aKeys) . '|' . $sTableId;
}
/**
* @param $sAlias
* @param $sAttCode
* @param $oAttDef
* @param $bChecked
* @param $sSort
*
* @return array|bool
* @throws \CoreException
* @throws \DictExceptionMissingString
*/
protected function GetFieldData($sAlias, $sAttCode, $oAttDef, $bChecked, $sSort)
{
$ret = false;
if ($sAttCode == '_key_') {
$sLabel = Dict::Format('UI:ExtKey_AsLink', MetaModel::GetName($this->aClassAliases[$sAlias]));
$ret = array(
'label' => $sLabel,
'checked' => $bChecked,
'disabled' => true,
'alias' => $sAlias,
'code' => $sAttCode,
'sort' => $sSort,
);
} else if (!$oAttDef->IsLinkSet()) {
$sLabel = $oAttDef->GetLabel();
if ($oAttDef->IsExternalKey()) {
$sLabel = Dict::Format('UI:ExtKey_AsLink', $oAttDef->GetLabel());
} else if ($oAttDef->IsExternalField()) {
if ($oAttDef->IsFriendlyName()) {
$sLabel = Dict::Format('UI:ExtKey_AsFriendlyName', $oAttDef->GetLabel());
} else {
$oExtAttDef = $oAttDef->GetExtAttDef();
$sLabel = Dict::Format('UI:ExtField_AsRemoteField', $oAttDef->GetLabel(), $oExtAttDef->GetLabel());
}
} elseif ($oAttDef instanceof AttributeFriendlyName) {
$sLabel = Dict::Format('UI:ExtKey_AsFriendlyName', $oAttDef->GetLabel());
}
$ret = array(
'label' => $sLabel,
'checked' => $bChecked,
'disabled' => false,
'alias' => $sAlias,
'code' => $sAttCode,
'sort' => $sSort,
);
}
return $ret;
}
}
/**
* @param $sAlias
* @param $sAttCode
* @param $oAttDef
* @param $bChecked
* @param $sSort
*
* @return array|bool
* @throws \CoreException
* @throws \DictExceptionMissingString
*/
protected function GetFieldData($sAlias, $sAttCode, $oAttDef, $bChecked, $sSort)
{
$ret = false;
if ($sAttCode == '_key_') {
$sLabel = Dict::Format('UI:ExtKey_AsLink', MetaModel::GetName($this->aClassAliases[$sAlias]));
$ret = [
'label' => $sLabel,
'checked' => $bChecked,
'disabled' => true,
'alias' => $sAlias,
'code' => $sAttCode,
'sort' => $sSort,
];
} elseif (!$oAttDef->IsLinkSet()) {
$sLabel = $oAttDef->GetLabel();
if ($oAttDef->IsExternalKey()) {
$sLabel = Dict::Format('UI:ExtKey_AsLink', $oAttDef->GetLabel());
} elseif ($oAttDef->IsExternalField()) {
if ($oAttDef->IsFriendlyName()) {
$sLabel = Dict::Format('UI:ExtKey_AsFriendlyName', $oAttDef->GetLabel());
} else {
$oExtAttDef = $oAttDef->GetExtAttDef();
$sLabel = Dict::Format('UI:ExtField_AsRemoteField', $oAttDef->GetLabel(), $oExtAttDef->GetLabel());
}
} elseif ($oAttDef instanceof AttributeFriendlyName) {
$sLabel = Dict::Format('UI:ExtKey_AsFriendlyName', $oAttDef->GetLabel());
}
$ret = [
'label' => $sLabel,
'checked' => $bChecked,
'disabled' => false,
'alias' => $sAlias,
'code' => $sAttCode,
'sort' => $sSort,
];
}
return $ret;
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -75,7 +76,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
* @throws \OQLException
* @throws \ReflectionException
*/
public static function MakeForResult(WebPage $oPage, string $sListId, DBObjectSet $oSet, $aExtraParams = array())
public static function MakeForResult(WebPage $oPage, string $sListId, DBObjectSet $oSet, $aExtraParams = [])
{
$oDataTable = DataTableUIBlockFactory::MakeForRendering($sListId, $oSet, $aExtraParams);
if ($oPage->IsPrintableVersion()) {
@@ -105,7 +106,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
* @throws \OQLException
* @throws \ReflectionException
*/
public static function MakeForObject(WebPage $oPage, string $sListId, DBObjectSet $oSet, $aExtraParams = array())
public static function MakeForObject(WebPage $oPage, string $sListId, DBObjectSet $oSet, $aExtraParams = [])
{
$oDataTable = DataTableUIBlockFactory::MakeForRendering($sListId, $oSet, $aExtraParams);
if ($oPage->IsPrintableVersion()) {
@@ -190,7 +191,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
}
// Panel subtitle
if(!empty($oDataTable->GetInitDisplayData()) && isset($oDataTable->GetInitDisplayData()['recordsTotal'])){
if (!empty($oDataTable->GetInitDisplayData()) && isset($oDataTable->GetInitDisplayData()['recordsTotal'])) {
$iCount = $oDataTable->GetInitDisplayData()['recordsTotal'];
} else {
$iCount = $oSet->Count();
@@ -200,7 +201,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$sSubTitle = Dict::Format('UI:Pagination:HeaderSelection', $sCountHtml, '<span class="ibo-datatable--selected-count">0</span>');
} else {
$sSubTitle = Dict::Format('UI:Pagination:HeaderNoSelection', $sCountHtml);
}
}
if (utils::IsNotNullOrEmptyString($sFilterListUrl)) {
$sSubTitle = '<a href="'.$sFilterListUrl.'" title="'.Dict::S('UI:Menu:FilterList').'">'.$sSubTitle.'</a>';
@@ -292,15 +293,15 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
* @throws \DictExceptionMissingString
* @throws \MySQLException
*/
public static function MakeForRendering(string $sListId, DBObjectSet $oSet, $aExtraParams = array())
public static function MakeForRendering(string $sListId, DBObjectSet $oSet, $aExtraParams = [])
{
$oDataTable = new DataTable('datatable_'.$sListId);
$aLists = array();
$aLists = [];
// Initialize and check the parameters
$bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
// Check if there is a list of aliases to limit the display to...
$aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : array();
$aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',', $aExtraParams['display_aliases']) : [];
$sZListName = isset($aExtraParams['zlist']) ? ($aExtraParams['zlist']) : 'list';
$sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : '';
@@ -317,9 +318,11 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
}
}
$aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',',
trim($aExtraParams['extra_fields'])) : array();
$aExtraFields = array();
$aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(
',',
trim($aExtraParams['extra_fields'])
) : [];
$aExtraFields = [];
$sAttCode = '';
foreach ($aExtraFieldsRaw as $sFieldName) {
// Ignore attributes not of the main queried class
@@ -332,10 +335,10 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
} else {
$aExtraFields['*'][] = $sFieldName;
}
}
}
$aClassAliases = $oSet->GetFilter()->GetSelectedClasses();
$aAuthorizedClasses = array();
$aAuthorizedClasses = [];
foreach ($aClassAliases as $sAlias => $sClassName) {
if ((UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) &&
((count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases)))) {
@@ -345,65 +348,65 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
foreach ($aAuthorizedClasses as $sAlias => $sClassName) {
// In case there is only 1 "alias" for the extra fields and it is the fallback ("*"), then consider that all fields are for the current alias.
// This is for the particular use case when the zlist is set to false and extra fields are specified.
if ( (count($aExtraFields) === 1) && (array_keys($aExtraFields)[0] === '*') ) {
if ((count($aExtraFields) === 1) && (array_keys($aExtraFields)[0] === '*')) {
$aLists[$sAlias] = $aExtraFields['*'];
}
// Regular use case, dispatch fields to their corresponding aliases
else if (array_key_exists($sAlias, $aExtraFields)) {
elseif (array_key_exists($sAlias, $aExtraFields)) {
$aLists[$sAlias] = $aExtraFields[$sAlias];
}
}
// Finally, if unknown alias, ignore fields
else {
$aLists[$sAlias] = array();
$aLists[$sAlias] = [];
}
// If zlist specified, merge its fields with the currently present
if ($sZListName !== false) {
if ($sZListName !== false) {
$aDefaultList = MetaModel::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName));
$aLists[$sAlias] = array_merge($aDefaultList, $aLists[$sAlias]);
}
}
// Filter the list to removed linked set since we are not able to display them here
// Filter the list to removed linked set since we are not able to display them here
foreach ($aLists[$sAlias] as $index => $sAttCode) {
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
if ($oAttDef instanceof AttributeLinkedSet) {
// Removed from the display list
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
if ($oAttDef instanceof AttributeLinkedSet) {
// Removed from the display list
unset($aLists[$sAlias][$index]);
}
}
if (empty($aLists[$sAlias])) {
unset($aLists[$sAlias], $aAuthorizedClasses[$sAlias]);
}
}
// Only for main class
if (!empty($sLinkageAttribute) && $sClassName === $oSet->GetFilter()->GetClass()) {
// The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
// and other objects...
// The display will then group all the attributes related to the link itself:
// | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
$aDisplayList = array();
$aAttDefs = MetaModel::ListAttributeDefs($sClassName);
assert(isset($aAttDefs[$sLinkageAttribute]));
$oAttDef = $aAttDefs[$sLinkageAttribute];
assert($oAttDef->IsExternalKey());
// First display all the attributes specific to the link record
// The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
// and other objects...
// The display will then group all the attributes related to the link itself:
// | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
$aDisplayList = [];
$aAttDefs = MetaModel::ListAttributeDefs($sClassName);
assert(isset($aAttDefs[$sLinkageAttribute]));
$oAttDef = $aAttDefs[$sLinkageAttribute];
assert($oAttDef->IsExternalKey());
// First display all the attributes specific to the link record
foreach ($aLists[$sAlias] as $sLinkAttCode) {
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
if ((!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField())) {
$aDisplayList[] = $sLinkAttCode;
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
if ((!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField())) {
$aDisplayList[] = $sLinkAttCode;
}
}
}
// Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
// Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
foreach ($aLists[$sAlias] as $sLinkAttCode) {
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
|| ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode() != $sLinkageAttribute))) {
$aDisplayList[] = $sLinkAttCode;
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
|| ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode() != $sLinkageAttribute))) {
$aDisplayList[] = $sLinkAttCode;
}
}
}
// First display all the attributes specific to the link
// Then display all the attributes linked to the other end of the relationship
// First display all the attributes specific to the link
// Then display all the attributes linked to the other end of the relationship
$aLists[$sAlias] = $aDisplayList;
}
}
@@ -460,7 +463,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$sIdName = isset($aExtraParams["id_for_select"]) ? $aExtraParams["id_for_select"] : "";
// Load only the requested columns
$aColumnsToLoad = array();
$aColumnsToLoad = [];
foreach ($oCustomSettings->aColumns as $sAlias => $aColumnsInfo) {
foreach ($aColumnsInfo as $sAttCode => $aData) {
$bForceLoad = false;
@@ -488,7 +491,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$oSet->OptimizeColumnLoad($aColumnsToLoad);
$aColumnDefinition = [];
$iIndexColumn=0;
$iIndexColumn = 0;
$bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
$bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false;
@@ -509,12 +512,11 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$sCode = ($aData['code'] == '_key_') ? 'friendlyname' : $aData['code'];
if ($aData['sort'] != 'none') {
$aSortOrder[$sClassAlias.'.'.$sCode] = ($aData['sort'] == 'asc'); // true for ascending, false for descending
$aSortDatable=[$iIndexColumn,$aData['sort']];
}
elseif (isset($oCustomSettings->aSortOrder[$sAttCode])){
$aSortDatable = [$iIndexColumn,$aData['sort']];
} elseif (isset($oCustomSettings->aSortOrder[$sAttCode])) {
$aSortOrder[$sClassAlias.'.'.$sCode] = $oCustomSettings->aSortOrder[$sAttCode]; // true for ascending, false for descending
}
if ($aData['checked']) {
if ($sAttCode == '_key_') {
if ($bViewLink) {
@@ -557,7 +559,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$aOptions = [];
if ($oDefaultSettings != null) {
$aOptions['oDefaultSettings'] = json_encode(array('iDefaultPageSize' => $oDefaultSettings->iDefaultPageSize, 'oColumns' => $oDefaultSettings->aColumns));
$aOptions['oDefaultSettings'] = json_encode(['iDefaultPageSize' => $oDefaultSettings->iDefaultPageSize, 'oColumns' => $oDefaultSettings->aColumns]);
}
// Selection mode
@@ -568,7 +570,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$aOptions['select_mode'] = "single";
}
}
$aOptions['selectionMode'] = $aExtraParams['selectionMode']?? 'positive';
$aOptions['selectionMode'] = $aExtraParams['selectionMode'] ?? 'positive';
// Sort
$aOptions['sort'] = $aSortDatable;
@@ -600,9 +602,8 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
} else {
$aOptions['sSelectedRows'] = '[]';
}
$aExtraParams['table_id']=$sTableId;
$aExtraParams['list_id']=$sListId;
$aExtraParams['table_id'] = $sTableId;
$aExtraParams['list_id'] = $sListId;
$oDataTable->SetOptions($aOptions);
$oDataTable->SetAjaxUrl(utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php");
@@ -623,7 +624,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$oDataTable->SetRowActions($aExtraParams['row_actions']);
}
if (isset($aExtraParams['creation_in_modal_js_handler'])){
if (isset($aExtraParams['creation_in_modal_js_handler'])) {
$oDataTable->SetModalCreationHandler($aExtraParams['creation_in_modal_js_handler']);
}
@@ -643,7 +644,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
* @throws \DictExceptionMissingString
* @throws \MySQLException
*/
public static function MakeForRenderingObject(string $sListId, DBObjectSet $oSet, $aExtraParams = array())
public static function MakeForRenderingObject(string $sListId, DBObjectSet $oSet, $aExtraParams = [])
{
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('use DataTableUIBlockFactory::MakeForRendering instead');
@@ -691,18 +692,17 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$aColumnDefinition["data"] = "";
$aColumnDefinition["render"]["display"] = "";
if ($sSelectMode != "single") {
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"checkbox\" class=\"selectList".$sTableId."\" name=\"selectObject[]\" value='+row.id+' /></span>');";
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]." var oCheckboxElem = $('<span class=\"row_input\"><input type=\"checkbox\" class=\"selectList".$sTableId."\" name=\"selectObject[]\" value='+row.id+' /></span>');";
} else {
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]." var oCheckboxElem = $('<span class=\"row_input\"><input type=\"radio\" class=\"selectList".$sTableId."\" name=\"selectObject[]\" value='+ row.id +' /></span>');";
}
else {
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"radio\" class=\"selectList".$sTableId."\" name=\"selectObject[]\" value='+ row.id +' /></span>');";
}
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " if (row.limited_access) { oCheckboxElem.html('-'); } else { oCheckboxElem.find(':input').attr('data-object-id', row.id).attr('data-target-object-id', row.target_id); }";
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]. " return oCheckboxElem.prop('outerHTML'); ";
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]." if (row.limited_access) { oCheckboxElem.html('-'); } else { oCheckboxElem.find(':input').attr('data-object-id', row.id).attr('data-target-object-id', row.target_id); }";
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]." return oCheckboxElem.prop('outerHTML'); ";
array_push($aColumnsDefinitions, $aColumnDefinition);
}
foreach ($aColumns as $sClassAlias => $aClassColumns) {
$sClassName=$aClassAliases[$sClassAlias];
$sClassName = $aClassAliases[$sClassAlias];
foreach ($aClassColumns as $sAttCode => $aData) {
if ($aData['checked'] == "true") {
$aColumnDefinition["width"] = "auto";
@@ -823,7 +823,7 @@ JS;
"data": '.$sAjaxData.',
"method": "post",
"pages": 5 // number of pages to cache
} )'
} )',
]);
if (count($aJsFiles) > 0) {
foreach ($aJsFiles as $sJsFile) {
@@ -974,4 +974,4 @@ JS;
/** Don't provide the standard object creation feature */
];
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTable;
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTableRow\FormTableRow;
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\StaticTable;
use Combodo\iTop\Application\UI\Base\Component\DataTable\tTableRowActions;
@@ -67,4 +67,4 @@ class FormTable extends StaticTable
$this->aRows[] = $oRow;
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTableRow;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -136,4 +136,4 @@ class FormTableRow extends UIBlock
return $this;
}
}
}

View File

@@ -201,4 +201,4 @@ class StaticTable extends UIContentBlock
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -20,7 +21,7 @@ use Combodo\iTop\Application\UI\Base\Component\Dialog\DialogUIBlockFactory;
trait tTableRowActions
{
/** @var bool static dialog initialized flag to avoid multiple html markups */
static public bool $bDialogInitialized = false;
public static bool $bDialogInitialized = false;
/**
* @var $aRowActions array array of row actions
@@ -81,4 +82,4 @@ trait tTableRowActions
{
return DataTableUIBlockFactory::MakeActionRowToolbarTemplate($this);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Field;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
use utils;
@@ -390,4 +390,4 @@ class Field extends UIContentBlock
{
return utils::IsNotNullOrEmptyString($this->GetDescription());
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
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;
@@ -150,4 +150,4 @@ class FieldUIBlockFactory extends AbstractUIBlockFactory
return $oField;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\FieldBadge;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
/**
@@ -23,4 +23,4 @@ class FieldBadge extends UIContentBlock
{
parent::__construct($sId, $aContainerClasses);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\FieldBadge;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use ormStyle;
use utils;
@@ -62,4 +61,4 @@ class FieldBadgeUIBlockFactory extends AbstractUIBlockFactory
$oBadge->AddHtml($sHtml);
return $oBadge;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\FieldSet;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
/**
@@ -42,5 +42,5 @@ class FieldSet extends UIContentBlock
{
return $this->sLegend;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\FieldSet;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
@@ -36,4 +35,4 @@ class FieldSetUIBlockFactory extends AbstractUIBlockFactory
{
return new FieldSet($sLegend, $sId);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Form;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
/**
@@ -65,4 +65,4 @@ class Form extends UIContentBlock
return $this;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Form;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
@@ -35,4 +34,4 @@ class FormUIBlockFactory extends AbstractUIBlockFactory
{
return new Form($sId);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\GlobalSearch;
use Combodo\iTop\Application\UI\Base\UIBlock;
use Combodo\iTop\Application\UI\Hook\iKeyboardShortcut;
use MetaModel;
@@ -183,4 +183,4 @@ class GlobalSearch extends UIBlock implements iKeyboardShortcut
{
return "[data-role='".static::BLOCK_CODE."']";
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\GlobalSearch;
/**
* Class GlobalSearchFactory
*
@@ -45,4 +45,4 @@ class GlobalSearchFactory
return new GlobalSearch($aLastClasses, GlobalSearch::BLOCK_CODE);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\GlobalSearch;
use appUserPreferences;
use MetaModel;
use utils;
@@ -59,15 +59,13 @@ class GlobalSearchHelper
];
// Set icon only when necessary
if (!empty($sIconRelUrl))
{
if (!empty($sIconRelUrl)) {
//Ensure URL is relative to limit space in the preferences and avoid broken links in case app_root_url changes
$aNewEntry['icon_url'] = str_replace(utils::GetAbsoluteUrlAppRoot(), '', $sIconRelUrl);
}
// Set label only when necessary to avoid unnecessary space filling of the preferences in the DB
if(!empty($sLabelAsHtml))
{
if (!empty($sLabelAsHtml)) {
$aNewEntry['label_html'] = $sLabelAsHtml;
}
@@ -75,10 +73,8 @@ class GlobalSearchHelper
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
// Remove same query from history to avoid duplicates
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
{
if($aHistoryEntries[$iIdx]['query'] === $sQuery)
{
for ($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) {
if ($aHistoryEntries[$iIdx]['query'] === $sQuery) {
unset($aHistoryEntries[$iIdx]);
}
}
@@ -107,21 +103,21 @@ class GlobalSearchHelper
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
static::TruncateHistory($aHistoryEntries);
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++){
for ($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) {
$sRawQuery = $aHistoryEntries[$iIdx]['query'];
// Make icon URL absolute
if(isset($aHistoryEntries[$iIdx]['icon_url'])){
if (isset($aHistoryEntries[$iIdx]['icon_url'])) {
$aHistoryEntries[$iIdx]['icon_url'] = utils::GetAbsoluteUrlAppRoot().$aHistoryEntries[$iIdx]['icon_url'];
}
// Add HTML label if missing
if(!isset($aHistoryEntries[$iIdx]['label_html'])) {
if (!isset($aHistoryEntries[$iIdx]['label_html'])) {
$aHistoryEntries[$iIdx]['label_html'] = utils::EscapeHtml($sRawQuery);
}
// Add URL
if(!isset($aHistoryEntries[$iIdx]['target_url'])){
if (!isset($aHistoryEntries[$iIdx]['target_url'])) {
$aHistoryEntries[$iIdx]['target_url'] = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=full_text&text='.urlencode($sRawQuery);
}
}
@@ -137,9 +133,8 @@ class GlobalSearchHelper
protected static function TruncateHistory(array &$aHistoryEntries): void
{
$iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('global_search.max_history_results');
if(count($aHistoryEntries) > $iMaxHistoryResults)
{
if (count($aHistoryEntries) > $iMaxHistoryResults) {
$aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults);
}
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Html;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -87,4 +87,4 @@ class Html extends UIBlock
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Html;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Html
* @since 3.0.0
@@ -62,4 +62,4 @@ class HtmlFactory
{
return new Html('<div class="ibo-is-html-content">'.$sContent.'</div>');
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -76,4 +76,4 @@ abstract class AbstractInput extends UIBlock
return $this;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @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;
@@ -103,5 +102,5 @@ class FileSelect extends UIBlock
{
return $this->bShowFilename;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\FileSelect;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
@@ -36,4 +35,4 @@ class FileSelectUIBlockFactory extends AbstractUIBlockFactory
{
return new FileSelect($sName, $sId);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* Class Input
*
@@ -21,7 +21,7 @@ class Input extends AbstractInput
public const INPUT_HIDDEN = 'hidden';
protected $bIsChecked = false;
protected $bIsDisabled = false;
protected $bIsReadonly = false;
@@ -128,4 +128,4 @@ class Input extends AbstractInput
{
return !is_null($this->sLabel);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @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;
@@ -78,10 +77,12 @@ class InputUIBlockFactory extends AbstractUIBlockFactory
* @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'
)
{
string $sLabel,
string $sInputName,
?string $sInputValue = null,
?string $sInputId = null,
string $sInputType = 'type'
) {
$oInput = new Input($sInputId);
$oInput->SetType($sInputType);
$oInput->SetValue($sInputValue);
@@ -109,4 +110,4 @@ class InputUIBlockFactory extends AbstractUIBlockFactory
return new InputWithLabel($sLabel, $oInput, $sId);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use Combodo\iTop\Application\UI\Base\UIBlock;
use utils;
@@ -142,4 +141,4 @@ class InputWithLabel extends UIBlock
{
return [$this->oInput->GetId() => $this->oInput];
}
}
}

View File

@@ -1,9 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\RichText;
use Combodo\iTop\Application\Helper\CKEditorHelper;
use Combodo\iTop\Application\Helper\WebResourcesHelper;
use Combodo\iTop\Application\UI\Base\UIBlock;
@@ -83,7 +86,7 @@ class RichText extends UIBlock
public function SetValue(?string $sValue)
{
$this->sValue = $sValue;
if(is_array($this->aConfig)) {
if (is_array($this->aConfig)) {
$this->aConfig['detectChanges'] = ['initialValue' => $sValue];
}
@@ -111,4 +114,4 @@ class RichText extends UIBlock
{
return $this->aConfig;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @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;
@@ -26,7 +25,6 @@ class Select extends UIContentBlock
/** @var bool Allow multiple selection */
protected $bIsMultiple = false;
public function __construct(?string $sId = null)
{
parent::__construct($sId);
@@ -95,4 +93,4 @@ class Select extends UIContentBlock
return $this;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @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
@@ -80,8 +79,8 @@ class SelectOption extends UIBlock
{
$this->bSelected = $bSelected;
return $this;
}
}
/**
* @return bool
*/
@@ -101,4 +100,4 @@ class SelectOption extends UIBlock
return $this;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
@@ -45,4 +44,4 @@ class SelectOptionUIBlockFactory extends AbstractUIBlockFactory
return $oInput;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
@@ -64,4 +63,4 @@ class SelectUIBlockFactory extends AbstractUIBlockFactory
return $oInput;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -156,5 +157,4 @@ abstract class AbstractDataProvider implements iDataProvider
return $this->GetType() === iDataProvider::TYPE_SIMPLE_PROVIDER;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -28,7 +29,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider;
class AjaxDataProvider extends SimpleDataProvider
{
/** @var int DEFAULT_MAX_RESULTS maximum results fetched */
const DEFAULT_MAX_RESULTS = 25;
public const DEFAULT_MAX_RESULTS = 25;
/**
* @see \Combodo\iTop\Service\Router\Router
@@ -45,7 +46,6 @@ class AjaxDataProvider extends SimpleDataProvider
/** @var int $iMaxResults Maximum entries */
private int $iMaxResults = AjaxDataProvider::DEFAULT_MAX_RESULTS;
/**
* Constructor.
*
@@ -166,4 +166,4 @@ class AjaxDataProvider extends SimpleDataProvider
return $this->iMaxResults;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -27,7 +28,6 @@ namespace Combodo\iTop\Application\UI\Base\Component\Input\Set\DataProvider;
*/
class AjaxDataProviderForOQL extends AjaxDataProvider
{
/**
* Constructor.
*
@@ -62,4 +62,4 @@ class AjaxDataProviderForOQL extends AjaxDataProvider
->SetDataSearchFields(['friendlyname', 'additional_field']);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -92,4 +93,4 @@ class SimpleDataProvider extends AbstractDataProvider
return array_values($aGroups);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -142,4 +143,4 @@ interface iDataProvider
* @return $this
*/
public function SetTooltipField(string $sField): iDataProvider;
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -54,7 +55,6 @@ class Set extends AbstractInput
private ?int $iMinItems;
/** @var int|null $iMaxItem Maximum number of displayed options */
private ?int $iMaxOptions;
@@ -608,4 +608,4 @@ class Set extends AbstractInput
$this->bIsDisabled = $bIsDisabled;
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -157,4 +158,4 @@ class SetUIBlockFactory extends AbstractUIBlockFactory
return $oSetUIBlock;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Input
*/
@@ -88,5 +88,4 @@ class TextArea extends AbstractInput
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,25 +7,23 @@
namespace Combodo\iTop\Application\UI\Base\Component\Input;
/**
* @package Combodo\iTop\Application\UI\Base\Component\Input
* @since 3.2.0
*/
class Toggler extends Input {
class Toggler extends Input
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-toggler';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/input-toggler';
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/input/input-toggler';
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->SetType('checkbox');
}
public function SetIsToggled(bool $bIsToggled): static
{
return $this->SetIsChecked($bIsToggled);
@@ -34,4 +33,4 @@ class Toggler extends Input {
{
return $this->IsChecked();
}
}
}

View File

@@ -1,10 +1,10 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Input;
use utils;
@@ -122,4 +122,4 @@ trait tInputLabel
{
return utils::StrLen($this->sDescription) > 0;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\MedallionIcon;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -38,7 +38,7 @@ class MedallionIcon extends UIBlock
{
parent::__construct($sId);
$this->sImageUrl = $sImageUrl;
$this->sIconClass= $sIconClass;
$this->sIconClass = $sIconClass;
}
/**
@@ -78,7 +78,7 @@ class MedallionIcon extends UIBlock
$this->sIconClass = $sIconClass;
return $this;
}
/**
* @return string
*/
@@ -97,5 +97,5 @@ class MedallionIcon extends UIBlock
$this->sDescription = $sDescription;
return $this;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -56,4 +57,4 @@ class DoNotShowAgainOptionBlock extends UIContentBlock
$oCheckBox->SetLabel(Dict::S('UI:UserPref:DoNotShowAgain'));
$this->AddSubBlock($oCheckBox);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Panel;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
@@ -518,7 +518,8 @@ class Panel extends UIContentBlock
*
* @return $this
*/
public function SetMainBlocks(array $aBlocks) {
public function SetMainBlocks(array $aBlocks)
{
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN, $aBlocks);
return $this;
@@ -530,7 +531,8 @@ class Panel extends UIContentBlock
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
* @throws \Exception
*/
public function GetMainBlocks(): array {
public function GetMainBlocks(): array
{
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN);
}
@@ -586,7 +588,8 @@ class Panel extends UIContentBlock
*
* @return $this
*/
public function SetToolBlocks(array $aBlocks) {
public function SetToolBlocks(array $aBlocks)
{
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_TOOLBAR, $aBlocks);
return $this;
@@ -598,7 +601,8 @@ class Panel extends UIContentBlock
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
* @throws \Exception
*/
public function GetToolbarBlocks(): array {
public function GetToolbarBlocks(): array
{
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_TOOLBAR);
}
@@ -654,7 +658,8 @@ class Panel extends UIContentBlock
/**
* @inheritDoc
*/
public function AddHtml(string $sHtml) {
public function AddHtml(string $sHtml)
{
$oBlock = new Html($sHtml);
$this->AddMainBlock($oBlock);
@@ -666,7 +671,8 @@ class Panel extends UIContentBlock
*
* @inheritDoc
*/
public function AddSubBlock(?iUIBlock $oSubBlock) {
public function AddSubBlock(?iUIBlock $oSubBlock)
{
if ($oSubBlock) {
$this->AddMainBlock($oSubBlock);
}
@@ -680,7 +686,8 @@ class Panel extends UIContentBlock
*
* @return $this
*/
public function RemoveSubBlock(string $sId) {
public function RemoveSubBlock(string $sId)
{
foreach ($this->GetContentAreas() as $oContentArea) {
$oContentArea->RemoveSubBlock($sId);
}
@@ -695,7 +702,8 @@ class Panel extends UIContentBlock
*
* @return bool
*/
public function HasSubBlock(string $sId): bool {
public function HasSubBlock(string $sId): bool
{
foreach ($this->GetContentAreas() as $oContentArea) {
if ($oContentArea->HasSubBlock($sId)) {
return true;
@@ -710,7 +718,8 @@ class Panel extends UIContentBlock
*
* @inheritDoc
*/
public function GetSubBlock(string $sId): ?iUIBlock {
public function GetSubBlock(string $sId): ?iUIBlock
{
foreach ($this->GetContentAreas() as $oContentArea) {
$oSubBlock = $oContentArea->GetSubBlock($sId);
if (!is_null($oSubBlock)) {
@@ -727,7 +736,8 @@ class Panel extends UIContentBlock
* @inheritDoc
* @return $this|\Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock
*/
public function SetSubBlocks(array $aSubBlocks): iUIContentBlock {
public function SetSubBlocks(array $aSubBlocks): iUIContentBlock
{
$this->SetMainBlocks($aSubBlocks);
return $this;

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -218,4 +219,4 @@ class PanelUIBlockFactory extends AbstractUIBlockFactory
return $oPanel;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Pill;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
/**
@@ -142,4 +141,4 @@ class Pill extends UIContentBlock
{
return !empty($this->sTooltip);
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Pill;
use Combodo\iTop\Application\UI\Helper\UIHelper;
use MetaModel;
@@ -42,4 +41,4 @@ class PillFactory
return $oPill;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
/**
@@ -65,4 +65,4 @@ class NewsroomMenu extends PopoverMenu
{
return json_encode($this->aParams);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -62,17 +63,17 @@ class NewsroomMenuFactory
*/
protected static function PrepareParametersForNewsroomMenu()
{
$aProviderParams=[];
$aProviderParams = [];
$oUser = UserRights::GetUserObject();
/** @var iNewsroomProvider[] $aProviders */
$aProviders = InterfaceDiscovery::GetInstance()->FindItopClasses(iNewsroomProvider::class);
foreach($aProviders as $cProvider) {
foreach ($aProviders as $cProvider) {
$oProvider = new $cProvider();
$oConfig = MetaModel::GetConfig();
$oProvider->SetConfig($oConfig);
$bProviderEnabled = appUserPreferences::GetPref('newsroom_provider_'.get_class($oProvider), true);
if ($bProviderEnabled && $oProvider->IsApplicable($oUser)) {
$aProviderParams[] = array(
$aProviderParams[] = [
'label' => $oProvider->GetLabel(),
'fetch_url' => $oProvider->GetFetchURL(),
'target' => utils::StartsWith($oProvider->GetFetchURL(), $oConfig->Get('app_root_url')) ? '_self' : '_blank',
@@ -80,25 +81,25 @@ class NewsroomMenuFactory
'mark_all_as_read_url' => $oProvider->GetMarkAllAsReadURL(),
'placeholders' => $oProvider->GetPlaceholders(),
'ttl' => $oProvider->GetTTL(),
);
];
}
}
$sImageUrl= 'fas fa-comment-dots';
$sPlaceholderImageUrl= 'far fa-envelope';
$aParams = array(
$sImageUrl = 'fas fa-comment-dots';
$sPlaceholderImageUrl = 'far fa-envelope';
$aParams = [
'image_icon' => $sImageUrl,
'no_message_icon' => file_get_contents(APPROOT.'images/illustrations/undraw_social_serenity.svg'),
'placeholder_image_icon' => $sPlaceholderImageUrl,
'cache_uuid' => 'itop-newsroom-'.UserRights::GetUserId().'-'.md5(APPROOT),
'providers' => $aProviderParams,
'display_limit' => (int)appUserPreferences::GetPref('newsroom_display_size', 7),
'labels' => array(
'labels' => [
'no_notification' => 'UI:Newsroom:NoNewMessage',
'x_notifications' => 'UI:Newsroom:XNewMessage',
'mark_all_as_read' => 'UI:Newsroom:MarkAllAsRead',
'view_all' => 'UI:Newsroom:ViewAllMessages'
),
);
'view_all' => 'UI:Newsroom:ViewAllMessages',
],
];
return $aParams;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem;
use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
@@ -336,8 +336,7 @@ class PopoverMenu extends UIBlock
*/
public function AddSection(string $sId)
{
if (false === $this->HasSection($sId))
{
if (false === $this->HasSection($sId)) {
$this->aSections[$sId] = [
'aItems' => [],
];
@@ -357,8 +356,7 @@ class PopoverMenu extends UIBlock
*/
public function RemoveSection(string $sId)
{
if (true === $this->HasSection($sId))
{
if (true === $this->HasSection($sId)) {
unset($this->aSections[$sId]);
}
@@ -387,8 +385,7 @@ class PopoverMenu extends UIBlock
*/
public function ClearSection(string $sId)
{
if (false === $this->HasSection($sId))
{
if (false === $this->HasSection($sId)) {
throw new Exception('Could not clear section "'.$sId.'" as it does not exist in the "'.$this->GetId().'" menu');
}
@@ -448,13 +445,11 @@ class PopoverMenu extends UIBlock
*/
public function RemoveItem(string $sSectionId, string $sItemId)
{
if (false === $this->HasSection($sSectionId))
{
if (false === $this->HasSection($sSectionId)) {
throw new Exception('Could not remove en item from the "'.$sSectionId.'" as it does not seem to exist in the "'.$this->GetId().'" menu.');
}
if (array_key_exists($sItemId, $this->aSections[$sSectionId]['aItems']))
{
if (array_key_exists($sItemId, $this->aSections[$sSectionId]['aItems'])) {
unset($this->aSections[$sSectionId]['aItems'][$sItemId]);
}
@@ -472,7 +467,7 @@ class PopoverMenu extends UIBlock
*/
public function AddItems(string $sSectionId, array $aItems)
{
foreach($aItems as $oItem){
foreach ($aItems as $oItem) {
$this->AddItem($sSectionId, $oItem);
}
@@ -525,12 +520,11 @@ class PopoverMenu extends UIBlock
$aSubBlocks = [];
foreach ($this->aSections as $sSectionId => $aSectionData) {
foreach($aSectionData['aItems'] as $sItemId => $oItem)
{
foreach ($aSectionData['aItems'] as $sItemId => $oItem) {
$aSubBlocks[$sItemId] = $oItem;
}
}
return $aSubBlocks;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,8 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItemFactory;
use Dict;
use JSPopupMenuItem;
@@ -80,7 +79,7 @@ class PopoverMenuFactory
return $oMenu;
}
/**
* Return the allowed portals items for the current user
*
@@ -89,10 +88,8 @@ class PopoverMenuFactory
protected static function PrepareAllowedPortalsItemsForUserMenu()
{
$aItems = [];
foreach (UserRights::GetAllowedPortals() as $aAllowedPortal)
{
if ($aAllowedPortal['id'] !== 'backoffice')
{
foreach (UserRights::GetAllowedPortals() as $aAllowedPortal) {
if ($aAllowedPortal['id'] !== 'backoffice') {
$oPopupMenuItem = new URLPopupMenuItem(
'portal:'.$aAllowedPortal['id'],
Dict::S($aAllowedPortal['label']),
@@ -127,8 +124,7 @@ class PopoverMenuFactory
);
// Archive mode
if(true === utils::IsArchiveMode())
{
if (true === utils::IsArchiveMode()) {
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new JSPopupMenuItem(
'UI:ArchiveModeOff',
@@ -136,9 +132,7 @@ class PopoverMenuFactory
'return ArchiveMode(false);'
)
);
}
elseif(UserRights::CanBrowseArchive())
{
} elseif (UserRights::CanBrowseArchive()) {
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new JSPopupMenuItem(
'UI:ArchiveModeOn',
@@ -149,8 +143,7 @@ class PopoverMenuFactory
}
// Logoff
if(utils::CanLogOff())
{
if (utils::CanLogOff()) {
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
'UI:LogOffMenu',
@@ -161,8 +154,7 @@ class PopoverMenuFactory
}
// Change password
if (UserRights::CanChangePassword())
{
if (UserRights::CanChangePassword()) {
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
'UI:ChangePwdMenu',
@@ -189,7 +181,7 @@ class PopoverMenuFactory
utils::GetPopupMenuItemsBlock($oMenu, iPopupMenuExtension::MENU_USER_ACTIONS, null, $aOriginalItems);
$aTransformedItems = [];
foreach($aOriginalItems as $sItemID => $aItemData) {
foreach ($aOriginalItems as $sItemID => $aItemData) {
$aTransformedItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItemData($sItemID, $aItemData);
}
@@ -273,4 +265,4 @@ class PopoverMenuFactory
return $oMenu;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
use JSPopupMenuItem;
/**
@@ -27,7 +27,7 @@ use JSPopupMenuItem;
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem
* @property \JSPopupMenuItem $oPopupMenuItem
* @property \JSPopupMenuItem $oPopupMenuItem
* @since 3.0.0
*/
class JsPopoverMenuItem extends PopoverMenuItem
@@ -63,4 +63,4 @@ class JsPopoverMenuItem extends PopoverMenuItem
return $aJsFiles;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
use ApplicationPopupMenuItem;
use Combodo\iTop\Application\UI\Base\UIBlock;
use utils;
@@ -106,7 +106,7 @@ class PopoverMenuItem extends UIBlock
{
return $this->oPopupMenuItem->GetCssClasses();
}
/**
* @return string
* @uses oPopupMenuItem
@@ -137,7 +137,7 @@ class PopoverMenuItem extends UIBlock
{
return $this->oPopupMenuItem->GetTooltip();
}
/**
* @return $this
* @uses oPopupMenuItem
@@ -149,7 +149,6 @@ class PopoverMenuItem extends UIBlock
return $this;
}
/**
* @return string
* @uses oPopupMenuItem
@@ -160,5 +159,4 @@ class PopoverMenuItem extends UIBlock
return $this->oPopupMenuItem->GetUID();
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,8 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
use ApplicationPopupMenuItem;
use JSPopupMenuItem;
use SeparatorPopupMenuItem;
@@ -46,14 +45,13 @@ class PopoverMenuItemFactory
public static function MakeFromApplicationPopupMenuItem(ApplicationPopupMenuItem $oItem)
{
$sNamespace = 'Combodo\\iTop\\Application\\UI\\Base\\Component\\PopoverMenu\\PopoverMenuItem\\';
switch(true)
{
switch (true) {
case $oItem instanceof URLPopupMenuItem:
$sTargetClass = 'UrlPopoverMenuItem';
break;
case $oItem instanceof JSPopupMenuItem:
$sTargetClass = 'JsPopoverMenuItem';
break;
break;
case $oItem instanceof SeparatorPopupMenuItem:
$sTargetClass = 'SeparatorPopoverMenuItem';
break;
@@ -99,7 +97,8 @@ class PopoverMenuItemFactory
new JSPopupMenuItem(
$aRefactoredItem['uid'],
$aRefactoredItem['label'],
$aRefactoredItem['on_click'])
$aRefactoredItem['on_click']
)
);
} elseif (!empty($aRefactoredItem['url'])) {
// URL
@@ -108,7 +107,8 @@ class PopoverMenuItemFactory
$aRefactoredItem['uid'],
$aRefactoredItem['label'],
$aRefactoredItem['url'],
$aRefactoredItem['target'])
$aRefactoredItem['target']
)
);
} else {
// Separator
@@ -140,4 +140,4 @@ class PopoverMenuItemFactory
{
return new SeparatorPopoverMenuItem(new SeparatorPopupMenuItem());
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
/**
* Class SeparatorPopoverMenuItem
*
@@ -33,4 +33,4 @@ class SeparatorPopoverMenuItem extends PopoverMenuItem
// Overloaded constants
public const BLOCK_CODE = 'ibo-popover-menu--item-separator';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/item/mode_separator';
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
/**
* Class UrlPopoverMenuItem
*
@@ -41,7 +41,7 @@ class UrlPopoverMenuItem extends PopoverMenuItem
{
return $this->oPopupMenuItem->GetUrl();
}
/**
* @see \URLPopupMenuItem::GetTarget()
* @return string
@@ -50,4 +50,4 @@ class UrlPopoverMenuItem extends PopoverMenuItem
{
return $this->oPopupMenuItem->GetTarget();
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\QuickCreate;
use Combodo\iTop\Application\UI\Base\UIBlock;
use Combodo\iTop\Application\UI\Hook\iKeyboardShortcut;
use MetaModel;
@@ -77,7 +77,7 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut
{
parent::__construct($sId);
$this->SetEndpoint(static::DEFAULT_ENDPOINT_REL_URL);
$this->aAvailableClasses = $this->FilterAvailableClasses(UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('bizmodel'), true));
$this->aAvailableClasses = $this->FilterAvailableClasses(UserRights::GetAllowedClasses(UR_ACTION_CREATE, ['bizmodel'], true));
$this->aLastClasses = $aLastClasses;
$this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results');
$this->bShowHistory = (bool) MetaModel::GetConfig()->Get('quick_create.show_history');
@@ -135,14 +135,14 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut
{
$aFilteredClasses = [];
foreach ($aClasses as $sClassName => $sClassLabel){
foreach ($aClasses as $sClassName => $sClassLabel) {
// Skip not derivating from cmdbAbstractObject
if(false === is_a($sClassName, '\cmdbAbstractObject', true)) {
if (false === is_a($sClassName, '\cmdbAbstractObject', true)) {
continue;
}
// Skip n:n classes
if(MetaModel::IsLinkClass($sClassName)) {
if (MetaModel::IsLinkClass($sClassName)) {
continue;
}
@@ -212,4 +212,4 @@ class QuickCreate extends UIBlock implements iKeyboardShortcut
{
return "[data-role='".static::BLOCK_CODE."']";
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\QuickCreate;
/**
* Class QuickCreateFactory
*
@@ -44,4 +44,4 @@ class QuickCreateFactory
return new QuickCreate($aLastClasses, QuickCreate::BLOCK_CODE);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\QuickCreate;
use appUserPreferences;
use DBObject;
use MetaModel;
@@ -59,10 +59,8 @@ class QuickCreateHelper
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
// Remove same entry from history to avoid duplicates
for ($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
{
if ($aHistoryEntries[$iIdx]['class'] === $sClass)
{
for ($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) {
if ($aHistoryEntries[$iIdx]['class'] === $sClass) {
unset($aHistoryEntries[$iIdx]);
}
}
@@ -90,33 +88,28 @@ class QuickCreateHelper
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
static::TruncateHistory($aHistoryEntries);
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
{
for ($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++) {
$sClass = $aHistoryEntries[$iIdx]['class'];
if (!MetaModel::IsValidClass($sClass)) {
continue;
}
// Add class icon
if(!isset($aHistoryEntries[$iIdx]['icon_url']))
{
if (!isset($aHistoryEntries[$iIdx]['icon_url'])) {
$sClassIconUrl = MetaModel::GetClassIcon($sClass, false);
// Mind that some classes don't have an icon
if(!empty($sClassIconUrl))
{
if (!empty($sClassIconUrl)) {
$aHistoryEntries[$iIdx]['icon_url'] = $sClassIconUrl;
}
}
// Add class label
if(!isset($aHistoryEntries[$iIdx]['label_html']))
{
if (!isset($aHistoryEntries[$iIdx]['label_html'])) {
$aHistoryEntries[$iIdx]['label_html'] = utils::EscapeHtml(MetaModel::GetName($sClass));
}
// Add URL
if(!isset($aHistoryEntries[$iIdx]['target_url']))
{
if (!isset($aHistoryEntries[$iIdx]['target_url'])) {
$aHistoryEntries[$iIdx]['target_url'] = DBObject::ComputeStandardUIPage($sClass).'?operation=new&class='.$sClass;
}
}
@@ -132,9 +125,8 @@ class QuickCreateHelper
protected static function TruncateHistory(array &$aHistoryEntries): void
{
$iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results');
if(count($aHistoryEntries) > $iMaxHistoryResults)
{
if (count($aHistoryEntries) > $iMaxHistoryResults) {
$aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults);
}
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\UI\Base\Component\Spinner;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
@@ -19,7 +19,7 @@ class Spinner extends UIBlock
// Overloaded constants
public const BLOCK_CODE = 'ibo-spinner';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/spinner/layout';
/* @var string Display size for inline element, rather small */
public const ENUM_SPINNER_SIZE_INLINE = 'inline';
/* @var string Display size for small element, displayed in a column */
@@ -60,7 +60,7 @@ class Spinner extends UIBlock
$this->sDescription = $sDescription;
return $this;
}
/**
* @return bool
*/
@@ -68,7 +68,7 @@ class Spinner extends UIBlock
{
return $this->sDescription !== '';
}
/**
* @return string
*/
@@ -86,4 +86,4 @@ class Spinner extends UIBlock
$this->sSize = $sSize;
return $this;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Spinner;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
@@ -50,7 +49,7 @@ class SpinnerUIBlockFactory extends AbstractUIBlockFactory
$oSpinner->SetSize(Spinner::ENUM_SPINNER_SIZE_SMALL);
return $oSpinner;
}
/**
* @api
*
@@ -80,4 +79,4 @@ class SpinnerUIBlockFactory extends AbstractUIBlockFactory
$oSpinner->SetSize(Spinner::ENUM_SPINNER_SIZE_LARGE);
return $oSpinner;
}
}
}

Some files were not shown because too many files have changed in this diff Show More