mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°8699 - attributedef.class.inc.php to PSR4 [3-PSR4]
- Add namespaces - Add use statements - reformat code
This commit is contained in:
committed by
Benjamin Dalsass
parent
f0adbbba29
commit
3fa500c9c1
@@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Dict;
|
||||
use ValueSetEnum;
|
||||
|
||||
/**
|
||||
* An attibute that matches one of the language codes availables in the dictionnary
|
||||
@@ -7,38 +16,38 @@
|
||||
*/
|
||||
class AttributeApplicationLanguage extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
}
|
||||
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aAvailableLanguages = Dict::GetLanguages();
|
||||
$aLanguageCodes = array();
|
||||
foreach ($aAvailableLanguages as $sLangCode => $aInfo) {
|
||||
$aLanguageCodes[$sLangCode] = $aInfo['description'] . ' (' . $aInfo['localized_description'] . ')';
|
||||
}
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aAvailableLanguages = Dict::GetLanguages();
|
||||
$aLanguageCodes = array();
|
||||
foreach ($aAvailableLanguages as $sLangCode => $aInfo) {
|
||||
$aLanguageCodes[$sLangCode] = $aInfo['description'].' ('.$aInfo['localized_description'].')';
|
||||
}
|
||||
|
||||
// N°6462 This should be sorted directly in \Dict during the compilation but we can't for 2 reasons:
|
||||
// - Additional languages can be added on the fly even though it is not recommended
|
||||
// - Formatting is done at run time (just above)
|
||||
natcasesort($aLanguageCodes);
|
||||
// N°6462 This should be sorted directly in \Dict during the compilation but we can't for 2 reasons:
|
||||
// - Additional languages can be added on the fly even though it is not recommended
|
||||
// - Formatting is done at run time (just above)
|
||||
natcasesort($aLanguageCodes);
|
||||
|
||||
$aParams["allowed_values"] = new ValueSetEnum($aLanguageCodes);
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
$aParams["allowed_values"] = new ValueSetEnum($aLanguageCodes);
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Dict;
|
||||
use Exception;
|
||||
|
||||
class AttributeArchiveDate extends AttributeDate
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveDate/Label', $sDefault);
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveDate/Label', $sDefault);
|
||||
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveDate/Label+', $sDefault);
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveDate/Label+', $sDefault);
|
||||
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Dict;
|
||||
|
||||
class AttributeArchiveFlag extends AttributeBoolean
|
||||
{
|
||||
public function __construct($sCode)
|
||||
{
|
||||
parent::__construct($sCode, array(
|
||||
"allowed_values" => null,
|
||||
"sql" => $sCode,
|
||||
"default_value" => false,
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array()
|
||||
));
|
||||
}
|
||||
public function __construct($sCode)
|
||||
{
|
||||
parent::__construct($sCode, array(
|
||||
"allowed_values" => null,
|
||||
"sql" => $sCode,
|
||||
"default_value" => false,
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array(),
|
||||
));
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function CopyOnAllTables()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function CopyOnAllTables()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveFlag/Label', $sDefault);
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveFlag/Label', $sDefault);
|
||||
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveFlag/Label+', $sDefault);
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeArchiveFlag/Label+', $sDefault);
|
||||
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOp;
|
||||
use CMDBChangeOpSetAttributeBlob;
|
||||
use CMDBSource;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
use ormDocument;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* A blob is an ormDocument, it is stored as several columns in the database
|
||||
@@ -7,361 +22,365 @@
|
||||
*/
|
||||
class AttributeBlob extends AttributeDefinition
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("depends_on"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("depends_on"));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Document";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Document";
|
||||
}
|
||||
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormDocument('', '', '');
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormDocument('', '', '');
|
||||
}
|
||||
|
||||
public function IsNullAllowed(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->GetOptional("is_null_allowed", false);
|
||||
}
|
||||
public function IsNullAllowed(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->GetOptional("is_null_allowed", false);
|
||||
}
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param string $proposedValue Can be an URL (including an URL to iTop itself), or a local path (CSV import)
|
||||
*
|
||||
* @see AttributeDefinition::MakeRealValue()
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if ($proposedValue === null) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see AttributeDefinition::MakeRealValue()
|
||||
*
|
||||
* @param string $proposedValue Can be an URL (including an URL to iTop itself), or a local path (CSV import)
|
||||
*
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if ($proposedValue === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_object($proposedValue)) {
|
||||
$proposedValue = clone $proposedValue;
|
||||
} else {
|
||||
try {
|
||||
// Read the file from iTop, an URL (or the local file system - for admins only)
|
||||
$proposedValue = Utils::FileGetContentsAndMIMEType($proposedValue);
|
||||
} catch (Exception $e) {
|
||||
IssueLog::Warning(get_class($this) . "::MakeRealValue - " . $e->getMessage());
|
||||
// Not a real document !! store is as text !!! (This was the default behavior before)
|
||||
$proposedValue = new ormDocument($e->getMessage() . " \n" . $proposedValue, 'text/plain');
|
||||
}
|
||||
}
|
||||
if (is_object($proposedValue)) {
|
||||
$proposedValue = clone $proposedValue;
|
||||
} else {
|
||||
try {
|
||||
// Read the file from iTop, an URL (or the local file system - for admins only)
|
||||
$proposedValue = utils::FileGetContentsAndMIMEType($proposedValue);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
IssueLog::Warning(get_class($this)."::MakeRealValue - ".$e->getMessage());
|
||||
// Not a real document !! store is as text !!! (This was the default behavior before)
|
||||
$proposedValue = new ormDocument($e->getMessage()." \n".$proposedValue, 'text/plain');
|
||||
}
|
||||
}
|
||||
|
||||
return $proposedValue;
|
||||
}
|
||||
return $proposedValue;
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->GetCode();
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix . '_mimetype';
|
||||
$aColumns['_data'] = $sPrefix . '_data';
|
||||
$aColumns['_filename'] = $sPrefix . '_filename';
|
||||
$aColumns['_downloads_count'] = $sPrefix . '_downloads_count';
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->GetCode();
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix.'_mimetype';
|
||||
$aColumns['_data'] = $sPrefix.'_data';
|
||||
$aColumns['_filename'] = $sPrefix.'_filename';
|
||||
$aColumns['_downloads_count'] = $sPrefix.'_downloads_count';
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!array_key_exists($sPrefix, $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$sMimeType = isset($aCols[$sPrefix]) ? $aCols[$sPrefix] : '';
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!array_key_exists($sPrefix, $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$sMimeType = isset($aCols[$sPrefix]) ? $aCols[$sPrefix] : '';
|
||||
|
||||
if (!array_key_exists($sPrefix . '_data', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '" . $sPrefix . "_data' from {$sAvailable}");
|
||||
}
|
||||
$data = isset($aCols[$sPrefix . '_data']) ? $aCols[$sPrefix . '_data'] : null;
|
||||
if (!array_key_exists($sPrefix.'_data', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '".$sPrefix."_data' from {$sAvailable}");
|
||||
}
|
||||
$data = isset($aCols[$sPrefix.'_data']) ? $aCols[$sPrefix.'_data'] : null;
|
||||
|
||||
if (!array_key_exists($sPrefix . '_filename', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '" . $sPrefix . "_filename' from {$sAvailable}");
|
||||
}
|
||||
$sFileName = isset($aCols[$sPrefix . '_filename']) ? $aCols[$sPrefix . '_filename'] : '';
|
||||
if (!array_key_exists($sPrefix.'_filename', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '".$sPrefix."_filename' from {$sAvailable}");
|
||||
}
|
||||
$sFileName = isset($aCols[$sPrefix.'_filename']) ? $aCols[$sPrefix.'_filename'] : '';
|
||||
|
||||
if (!array_key_exists($sPrefix . '_downloads_count', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '" . $sPrefix . "_downloads_count' from {$sAvailable}");
|
||||
}
|
||||
$iDownloadsCount = isset($aCols[$sPrefix . '_downloads_count']) ? $aCols[$sPrefix . '_downloads_count'] : ormDocument::DEFAULT_DOWNLOADS_COUNT;
|
||||
if (!array_key_exists($sPrefix.'_downloads_count', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '".$sPrefix."_downloads_count' from {$sAvailable}");
|
||||
}
|
||||
$iDownloadsCount = isset($aCols[$sPrefix.'_downloads_count']) ? $aCols[$sPrefix.'_downloads_count'] : ormDocument::DEFAULT_DOWNLOADS_COUNT;
|
||||
|
||||
$value = new ormDocument($data, $sMimeType, $sFileName, $iDownloadsCount);
|
||||
$value = new ormDocument($data, $sMimeType, $sFileName, $iDownloadsCount);
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
// #@# Optimization: do not load blobs anytime
|
||||
// As per mySQL doc, selecting blob columns will prevent mySQL from
|
||||
// using memory in case a temporary table has to be created
|
||||
// (temporary tables created on disk)
|
||||
// We will have to remove the blobs from the list of attributes when doing the select
|
||||
// then the use of Get() should finalize the load
|
||||
if ($value instanceof ormDocument) {
|
||||
$aValues = array();
|
||||
if (!$value->IsEmpty()) {
|
||||
$aValues[$this->GetCode() . '_data'] = $value->GetData();
|
||||
} else {
|
||||
$aValues[$this->GetCode() . '_data'] = '';
|
||||
}
|
||||
$aValues[$this->GetCode() . '_mimetype'] = $value->GetMimeType();
|
||||
$aValues[$this->GetCode() . '_filename'] = $value->GetFileName();
|
||||
$aValues[$this->GetCode() . '_downloads_count'] = $value->GetDownloadsCount();
|
||||
} else {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode() . '_data'] = '';
|
||||
$aValues[$this->GetCode() . '_mimetype'] = '';
|
||||
$aValues[$this->GetCode() . '_filename'] = '';
|
||||
$aValues[$this->GetCode() . '_downloads_count'] = ormDocument::DEFAULT_DOWNLOADS_COUNT;
|
||||
}
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
// #@# Optimization: do not load blobs anytime
|
||||
// As per mySQL doc, selecting blob columns will prevent mySQL from
|
||||
// using memory in case a temporary table has to be created
|
||||
// (temporary tables created on disk)
|
||||
// We will have to remove the blobs from the list of attributes when doing the select
|
||||
// then the use of Get() should finalize the load
|
||||
if ($value instanceof ormDocument) {
|
||||
$aValues = array();
|
||||
if (!$value->IsEmpty()) {
|
||||
$aValues[$this->GetCode().'_data'] = $value->GetData();
|
||||
} else {
|
||||
$aValues[$this->GetCode().'_data'] = '';
|
||||
}
|
||||
$aValues[$this->GetCode().'_mimetype'] = $value->GetMimeType();
|
||||
$aValues[$this->GetCode().'_filename'] = $value->GetFileName();
|
||||
$aValues[$this->GetCode().'_downloads_count'] = $value->GetDownloadsCount();
|
||||
} else {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode().'_data'] = '';
|
||||
$aValues[$this->GetCode().'_mimetype'] = '';
|
||||
$aValues[$this->GetCode().'_filename'] = '';
|
||||
$aValues[$this->GetCode().'_downloads_count'] = ormDocument::DEFAULT_DOWNLOADS_COUNT;
|
||||
}
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode() . '_data'] = 'LONGBLOB'; // 2^32 (4 Gb)
|
||||
$aColumns[$this->GetCode() . '_mimetype'] = 'VARCHAR(255)' . CMDBSource::GetSqlStringColumnDefinition();
|
||||
$aColumns[$this->GetCode() . '_filename'] = 'VARCHAR(255)' . CMDBSource::GetSqlStringColumnDefinition();
|
||||
$aColumns[$this->GetCode() . '_downloads_count'] = 'INT(11) UNSIGNED';
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode().'_data'] = 'LONGBLOB'; // 2^32 (4 Gb)
|
||||
$aColumns[$this->GetCode().'_mimetype'] = 'VARCHAR(255)'.CMDBSource::GetSqlStringColumnDefinition();
|
||||
$aColumns[$this->GetCode().'_filename'] = 'VARCHAR(255)'.CMDBSource::GetSqlStringColumnDefinition();
|
||||
$aColumns[$this->GetCode().'_downloads_count'] = 'INT(11) UNSIGNED';
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return 'true';
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return 'true';
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $value->GetAsHTML();
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $value->GetAsHTML();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sAttCode = $this->GetCode();
|
||||
if ($sValue instanceof ormDocument && !$sValue->IsEmpty()) {
|
||||
return $sValue->GetDownloadURL(get_class($oHostObject), $oHostObject->GetKey(), $sAttCode);
|
||||
}
|
||||
/**
|
||||
* @param string $sValue
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sAttCode = $this->GetCode();
|
||||
if ($sValue instanceof ormDocument && !$sValue->IsEmpty()) {
|
||||
return $sValue->GetDownloadURL(get_class($oHostObject), $oHostObject->GetKey(), $sAttCode);
|
||||
}
|
||||
|
||||
return ''; // Not exportable in CSV !
|
||||
}
|
||||
return ''; // Not exportable in CSV !
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sRet = '';
|
||||
if (is_object($value)) {
|
||||
/** @var \ormDocument $value */
|
||||
if (!$value->IsEmpty()) {
|
||||
$sRet = '<mimetype>' . $value->GetMimeType() . '</mimetype>';
|
||||
$sRet .= '<filename>' . $value->GetFileName() . '</filename>';
|
||||
$sRet .= '<data>' . base64_encode($value->GetData()) . '</data>';
|
||||
$sRet .= '<downloads_count>' . $value->GetDownloadsCount() . '</downloads_count>';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sRet = '';
|
||||
if (is_object($value)) {
|
||||
/** @var ormDocument $value */
|
||||
if (!$value->IsEmpty()) {
|
||||
$sRet = '<mimetype>'.$value->GetMimeType().'</mimetype>';
|
||||
$sRet .= '<filename>'.$value->GetFileName().'</filename>';
|
||||
$sRet .= '<data>'.base64_encode($value->GetData()).'</data>';
|
||||
$sRet .= '<downloads_count>'.$value->GetDownloadsCount().'</downloads_count>';
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
if ($value instanceof ormDocument) {
|
||||
$aValues = array();
|
||||
$aValues['data'] = base64_encode($value->GetData());
|
||||
$aValues['mimetype'] = $value->GetMimeType();
|
||||
$aValues['filename'] = $value->GetFileName();
|
||||
$aValues['downloads_count'] = $value->GetDownloadsCount();
|
||||
} else {
|
||||
$aValues = null;
|
||||
}
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
if ($value instanceof ormDocument) {
|
||||
$aValues = array();
|
||||
$aValues['data'] = base64_encode($value->GetData());
|
||||
$aValues['mimetype'] = $value->GetMimeType();
|
||||
$aValues['filename'] = $value->GetFileName();
|
||||
$aValues['downloads_count'] = $value->GetDownloadsCount();
|
||||
} else {
|
||||
$aValues = null;
|
||||
}
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function FromJSONToValue($json)
|
||||
{
|
||||
if (isset($json->data)) {
|
||||
$data = base64_decode($json->data);
|
||||
$value = new ormDocument($data, $json->mimetype, $json->filename, $json->downloads_count);
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
public function FromJSONToValue($json)
|
||||
{
|
||||
if (isset($json->data)) {
|
||||
$data = base64_decode($json->data);
|
||||
$value = new ormDocument($data, $json->mimetype, $json->filename, $json->downloads_count);
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function Fingerprint($value)
|
||||
{
|
||||
$sFingerprint = '';
|
||||
if ($value instanceof ormDocument) {
|
||||
$sFingerprint = $value->GetSignature();
|
||||
}
|
||||
public function Fingerprint($value)
|
||||
{
|
||||
$sFingerprint = '';
|
||||
if ($value instanceof ormDocument) {
|
||||
$sFingerprint = $value->GetSignature();
|
||||
}
|
||||
|
||||
return $sFingerprint;
|
||||
}
|
||||
return $sFingerprint;
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\BlobField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\BlobField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
/** @var $oFormField \Combodo\iTop\Form\Field\BlobField */
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
/** @var $oFormField BlobField */
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
|
||||
// Note: As of today we want this field to always be read-only
|
||||
$oFormField->SetReadOnly(true);
|
||||
// Note: As of today we want this field to always be read-only
|
||||
$oFormField->SetReadOnly(true);
|
||||
|
||||
// Calling parent before so current value is set, then proceed
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
// Calling parent before so current value is set, then proceed
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
// Setting current value correctly as the default method returns an empty string when there is no file yet.
|
||||
/** @var \ormDocument $value */
|
||||
$value = $oObject->Get($this->GetCode());
|
||||
if (!is_object($value)) {
|
||||
$oFormField->SetCurrentValue(new ormDocument());
|
||||
}
|
||||
// Setting current value correctly as the default method returns an empty string when there is no file yet.
|
||||
/** @var ormDocument $value */
|
||||
$value = $oObject->Get($this->GetCode());
|
||||
if (!is_object($value)) {
|
||||
$oFormField->SetCurrentValue(new ormDocument());
|
||||
}
|
||||
|
||||
// Generating urls
|
||||
if (is_object($value) && !$value->IsEmpty()) {
|
||||
$oFormField->SetDownloadUrl($value->GetDownloadURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
$oFormField->SetDisplayUrl($value->GetDisplayURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
}
|
||||
// Generating urls
|
||||
if (is_object($value) && !$value->IsEmpty()) {
|
||||
$oFormField->SetDownloadUrl($value->GetDownloadURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
$oFormField->SetDisplayUrl($value->GetDisplayURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
}
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
if (false === ($proposedValue instanceof ormDocument)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
if (false === ($proposedValue instanceof ormDocument)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
|
||||
// Empty file (no content, just a filename) are supported since PR {@link https://github.com/Combodo/combodo-email-synchro/pull/17}, so we check for both empty content and empty filename to determine that a document has no value
|
||||
return utils::IsNotNullOrEmptyString($proposedValue->GetData()) && utils::IsNotNullOrEmptyString($proposedValue->GetFileName());
|
||||
}
|
||||
// Empty file (no content, just a filename) are supported since PR {@link https://github.com/Combodo/combodo-email-synchro/pull/17}, so we check for both empty content and empty filename to determine that a document has no value
|
||||
return utils::IsNotNullOrEmptyString($proposedValue->GetData()) && utils::IsNotNullOrEmptyString($proposedValue->GetFileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param \ormDocument $original
|
||||
* @param \ormDocument $value
|
||||
* @since N°6502
|
||||
*/
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
// N°6502 Don't record history if only the download count has changed
|
||||
if ((null !== $original) && (null !== $value) && $original->EqualsExceptDownloadsCount($value)) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param ormDocument $original
|
||||
* @param ormDocument $value
|
||||
*
|
||||
* @since N°6502
|
||||
*/
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
// N°6502 Don't record history if only the download count has changed
|
||||
if ((null !== $original) && (null !== $value) && $original->EqualsExceptDownloadsCount($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::RecordAttChange($oObject, $original, $value);
|
||||
}
|
||||
parent::RecordAttChange($oObject, $original, $value);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
if (is_null($original)) {
|
||||
$original = new ormDocument();
|
||||
}
|
||||
$oMyChangeOp->Set("prevdata", $original);
|
||||
}
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
if (is_null($original)) {
|
||||
$original = new ormDocument();
|
||||
}
|
||||
$oMyChangeOp->Set("prevdata", $original);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeBlob::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeBlob::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOpSetAttributeScalar;
|
||||
use Combodo\iTop\Form\Field\SelectField;
|
||||
use DBObject;
|
||||
use Dict;
|
||||
|
||||
/**
|
||||
* Map a boolean column to an attribute
|
||||
@@ -7,236 +18,236 @@
|
||||
*/
|
||||
class AttributeBoolean extends AttributeInteger
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Integer";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Integer";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TINYINT(1)" . ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TINYINT(1)".($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return null;
|
||||
}
|
||||
if ((int)$proposedValue) {
|
||||
return true;
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return null;
|
||||
}
|
||||
if ((int)$proposedValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if ($value) {
|
||||
return 1;
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if ($value) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function GetValueLabel($bValue)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sLabel = Dict::S('Core:' . get_class($this) . '/Value:null');
|
||||
} else {
|
||||
$sValue = $bValue ? 'yes' : 'no';
|
||||
$sDefault = Dict::S('Core:' . get_class($this) . '/Value:' . $sValue);
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sValue, $sDefault, true /*user lang*/);
|
||||
}
|
||||
public function GetValueLabel($bValue)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sLabel = Dict::S('Core:'.get_class($this).'/Value:null');
|
||||
} else {
|
||||
$sValue = $bValue ? 'yes' : 'no';
|
||||
$sDefault = Dict::S('Core:'.get_class($this).'/Value:'.$sValue);
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, $sDefault, true /*user lang*/);
|
||||
}
|
||||
|
||||
return $sLabel;
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
public function GetValueDescription($bValue)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sDescription = Dict::S('Core:' . get_class($this) . '/Value:null+');
|
||||
} else {
|
||||
$sValue = $bValue ? 'yes' : 'no';
|
||||
$sDefault = Dict::S('Core:' . get_class($this) . '/Value:' . $sValue . '+');
|
||||
$sDescription = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sValue . '+', $sDefault,
|
||||
true /*user lang*/);
|
||||
}
|
||||
public function GetValueDescription($bValue)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sDescription = Dict::S('Core:'.get_class($this).'/Value:null+');
|
||||
} else {
|
||||
$sValue = $bValue ? 'yes' : 'no';
|
||||
$sDefault = Dict::S('Core:'.get_class($this).'/Value:'.$sValue.'+');
|
||||
$sDescription = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue.'+', $sDefault,
|
||||
true /*user lang*/);
|
||||
}
|
||||
|
||||
return $sDescription;
|
||||
}
|
||||
return $sDescription;
|
||||
}
|
||||
|
||||
public function GetAsHTML($bValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sRes = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sLabel = $this->GetValueLabel($bValue);
|
||||
$sDescription = $this->GetValueDescription($bValue);
|
||||
// later, we could imagine a detailed description in the title
|
||||
$sRes = "<span title=\"$sDescription\">" . parent::GetAsHtml($sLabel) . "</span>";
|
||||
} else {
|
||||
$sRes = $bValue ? 'yes' : 'no';
|
||||
}
|
||||
public function GetAsHTML($bValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sRes = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sLabel = $this->GetValueLabel($bValue);
|
||||
$sDescription = $this->GetValueDescription($bValue);
|
||||
// later, we could imagine a detailed description in the title
|
||||
$sRes = "<span title=\"$sDescription\">".parent::GetAsHtml($sLabel)."</span>";
|
||||
} else {
|
||||
$sRes = $bValue ? 'yes' : 'no';
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
public function GetAsXML($bValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($bValue);
|
||||
} else {
|
||||
$sFinalValue = $bValue ? 'yes' : 'no';
|
||||
}
|
||||
$sRes = parent::GetAsXML($sFinalValue, $oHostObject, $bLocalize);
|
||||
public function GetAsXML($bValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($bValue);
|
||||
} else {
|
||||
$sFinalValue = $bValue ? 'yes' : 'no';
|
||||
}
|
||||
$sRes = parent::GetAsXML($sFinalValue, $oHostObject, $bLocalize);
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$bValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($bValue);
|
||||
} else {
|
||||
$sFinalValue = $bValue ? 'yes' : 'no';
|
||||
}
|
||||
$sRes = parent::GetAsCSV($sFinalValue, $sSeparator, $sTextQualifier, $oHostObject, $bLocalize);
|
||||
public function GetAsCSV(
|
||||
$bValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (is_null($bValue)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($bValue);
|
||||
} else {
|
||||
$sFinalValue = $bValue ? 'yes' : 'no';
|
||||
}
|
||||
$sRes = parent::GetAsCSV($sFinalValue, $sSeparator, $sTextQualifier, $oHostObject, $bLocalize);
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SelectField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SelectField';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DBObject $oObject
|
||||
* @param \Combodo\iTop\Form\Field\SelectField $oFormField
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\SelectField
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
/**
|
||||
* @param DBObject $oObject
|
||||
* @param SelectField $oFormField
|
||||
*
|
||||
* @return SelectField
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
|
||||
$oFormField->SetChoices(array('yes' => $this->GetValueLabel(true), 'no' => $this->GetValueLabel(false)));
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
$oFormField->SetChoices(array('yes' => $this->GetValueLabel(true), 'no' => $this->GetValueLabel(false)));
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
public function GetEditValue($value, $oHostObj = null)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return '';
|
||||
} else {
|
||||
return $this->GetValueLabel($value);
|
||||
}
|
||||
}
|
||||
public function GetEditValue($value, $oHostObj = null)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return '';
|
||||
} else {
|
||||
return $this->GetValueLabel($value);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
return (bool)$value;
|
||||
}
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
return (bool)$value;
|
||||
}
|
||||
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
$sInput = mb_strtolower(trim($sProposedValue));
|
||||
if ($bLocalizedValue) {
|
||||
switch ($sInput) {
|
||||
case '1': // backward compatibility
|
||||
case $this->GetValueLabel(true):
|
||||
$value = true;
|
||||
break;
|
||||
case '0': // backward compatibility
|
||||
case 'no':
|
||||
case $this->GetValueLabel(false):
|
||||
$value = false;
|
||||
break;
|
||||
default:
|
||||
$value = null;
|
||||
}
|
||||
} else {
|
||||
switch ($sInput) {
|
||||
case '1': // backward compatibility
|
||||
case 'yes':
|
||||
$value = true;
|
||||
break;
|
||||
case '0': // backward compatibility
|
||||
case 'no':
|
||||
$value = false;
|
||||
break;
|
||||
default:
|
||||
$value = null;
|
||||
}
|
||||
}
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
$sInput = mb_strtolower(trim($sProposedValue));
|
||||
if ($bLocalizedValue) {
|
||||
switch ($sInput) {
|
||||
case '1': // backward compatibility
|
||||
case $this->GetValueLabel(true):
|
||||
$value = true;
|
||||
break;
|
||||
case '0': // backward compatibility
|
||||
case 'no':
|
||||
case $this->GetValueLabel(false):
|
||||
$value = false;
|
||||
break;
|
||||
default:
|
||||
$value = null;
|
||||
}
|
||||
} else {
|
||||
switch ($sInput) {
|
||||
case '1': // backward compatibility
|
||||
case 'yes':
|
||||
$value = true;
|
||||
break;
|
||||
case '0': // backward compatibility
|
||||
case 'no':
|
||||
$value = false;
|
||||
break;
|
||||
default:
|
||||
$value = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
parent::RecordAttChange($oObject, $original ? 1 : 0, $value ? 1 : 0);
|
||||
}
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
parent::RecordAttChange($oObject, $original ? 1 : 0, $value ? 1 : 0);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeScalar::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeScalar::class;
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = ''): array
|
||||
{
|
||||
return [
|
||||
0 => $this->GetValueLabel(false),
|
||||
1 => $this->GetValueLabel(true)
|
||||
];
|
||||
}
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = ''): array
|
||||
{
|
||||
return [
|
||||
0 => $this->GetValueLabel(false),
|
||||
1 => $this->GetValueLabel(true),
|
||||
];
|
||||
}
|
||||
|
||||
public function GetDisplayStyle()
|
||||
{
|
||||
return $this->GetOptional('display_style', 'select');
|
||||
}
|
||||
public function GetDisplayStyle()
|
||||
{
|
||||
return $this->GetOptional('display_style', 'select');
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOp;
|
||||
use CMDBChangeOpSetAttributeCaseLog;
|
||||
use CMDBSource;
|
||||
use CoreWarning;
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use ormCaseLog;
|
||||
use stdClass;
|
||||
use UserRights;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* An attibute that stores a case log (i.e journal)
|
||||
@@ -7,388 +25,389 @@
|
||||
*/
|
||||
class AttributeCaseLog extends AttributeLongText
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
if (!($proposedValue instanceof ormCaseLog)) {
|
||||
return ($proposedValue == '');
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
if (!($proposedValue instanceof ormCaseLog)) {
|
||||
return ($proposedValue == '');
|
||||
}
|
||||
|
||||
return ($proposedValue->GetText() == '');
|
||||
}
|
||||
return ($proposedValue->GetText() == '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param \ormCaseLog $proposedValue
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Protection against wrong value type
|
||||
if (false === ($proposedValue instanceof ormCaseLog)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param ormCaseLog $proposedValue
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Protection against wrong value type
|
||||
if (false === ($proposedValue instanceof ormCaseLog)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
|
||||
// We test if there is at least 1 entry in the log, not if the user is adding one
|
||||
return $proposedValue->GetEntryCount() > 0;
|
||||
}
|
||||
// We test if there is at least 1 entry in the log, not if the user is adding one
|
||||
return $proposedValue->GetEntryCount() > 0;
|
||||
}
|
||||
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (!is_string($value) && !is_null($value)) {
|
||||
throw new CoreWarning('Expected the attribute value to be a string', array(
|
||||
'found_type' => gettype($value),
|
||||
'value' => $value,
|
||||
'class' => $this->GetCode(),
|
||||
'attribute' => $this->GetHostClass()
|
||||
));
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (!is_string($value) && !is_null($value)) {
|
||||
throw new CoreWarning('Expected the attribute value to be a string', array(
|
||||
'found_type' => gettype($value),
|
||||
'value' => $value,
|
||||
'class' => $this->GetCode(),
|
||||
'attribute' => $this->GetHostClass(),
|
||||
));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "CaseLog";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "CaseLog";
|
||||
}
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
if (!($sValue instanceof ormCaseLog)) {
|
||||
return '';
|
||||
}
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
if (!($sValue instanceof ormCaseLog)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $sValue->GetModifiedEntry();
|
||||
}
|
||||
return $sValue->GetModifiedEntry();
|
||||
}
|
||||
|
||||
/**
|
||||
* For fields containing a potential markup, return the value without this markup
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetAsPlainText($value, $oHostObj = null)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
/** ormCaseLog $value */
|
||||
return $value->GetAsPlainText();
|
||||
} else {
|
||||
return (string)$value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* For fields containing a potential markup, return the value without this markup
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetAsPlainText($value, $oHostObj = null)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
/** ormCaseLog $value */
|
||||
return $value->GetAsPlainText();
|
||||
} else {
|
||||
return (string)$value;
|
||||
}
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormCaseLog();
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormCaseLog();
|
||||
}
|
||||
|
||||
public function Equals($val1, $val2)
|
||||
{
|
||||
return ($val1->GetText() == $val2->GetText());
|
||||
}
|
||||
public function Equals($val1, $val2)
|
||||
{
|
||||
return ($val1->GetText() == $val2->GetText());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Facilitate things: allow the user to Set the value from a string
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @return mixed|null|\ormCaseLog|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if ($proposedValue instanceof ormCaseLog) {
|
||||
// Passthrough
|
||||
$ret = clone $proposedValue;
|
||||
} else {
|
||||
// Append the new value if an instance of the object is supplied
|
||||
//
|
||||
$oPreviousLog = null;
|
||||
if ($oHostObj != null) {
|
||||
$oPreviousLog = $oHostObj->Get($this->GetCode());
|
||||
if (!is_object($oPreviousLog)) {
|
||||
$oPreviousLog = $oHostObj->GetOriginal($this->GetCode());;
|
||||
}
|
||||
/**
|
||||
* Facilitate things: allow the user to Set the value from a string
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param DBObject $oHostObj
|
||||
*
|
||||
* @return mixed|null|ormCaseLog|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if ($proposedValue instanceof ormCaseLog) {
|
||||
// Passthrough
|
||||
$ret = clone $proposedValue;
|
||||
} else {
|
||||
// Append the new value if an instance of the object is supplied
|
||||
//
|
||||
$oPreviousLog = null;
|
||||
if ($oHostObj != null) {
|
||||
$oPreviousLog = $oHostObj->Get($this->GetCode());
|
||||
if (!is_object($oPreviousLog)) {
|
||||
$oPreviousLog = $oHostObj->GetOriginal($this->GetCode());;
|
||||
}
|
||||
|
||||
}
|
||||
if (is_object($oPreviousLog)) {
|
||||
$oCaseLog = clone($oPreviousLog);
|
||||
} else {
|
||||
$oCaseLog = new ormCaseLog();
|
||||
}
|
||||
}
|
||||
if (is_object($oPreviousLog)) {
|
||||
$oCaseLog = clone($oPreviousLog);
|
||||
} else {
|
||||
$oCaseLog = new ormCaseLog();
|
||||
}
|
||||
|
||||
if ($proposedValue instanceof stdClass) {
|
||||
$oCaseLog->AddLogEntryFromJSON($proposedValue);
|
||||
} else {
|
||||
if (utils::StrLen($proposedValue) > 0) {
|
||||
//N°5135 - add impersonation information in caselog
|
||||
if (UserRights::IsImpersonated()) {
|
||||
$sOnBehalfOf = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUserFriendlyName(), UserRights::GetUserFriendlyName());
|
||||
$oCaseLog->AddLogEntry($proposedValue, $sOnBehalfOf, UserRights::GetConnectedUserId());
|
||||
} else {
|
||||
$oCaseLog->AddLogEntry($proposedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
$ret = $oCaseLog;
|
||||
}
|
||||
if ($proposedValue instanceof stdClass) {
|
||||
$oCaseLog->AddLogEntryFromJSON($proposedValue);
|
||||
} else {
|
||||
if (utils::StrLen($proposedValue) > 0) {
|
||||
//N°5135 - add impersonation information in caselog
|
||||
if (UserRights::IsImpersonated()) {
|
||||
$sOnBehalfOf = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUserFriendlyName(), UserRights::GetUserFriendlyName());
|
||||
$oCaseLog->AddLogEntry($proposedValue, $sOnBehalfOf, UserRights::GetConnectedUserId());
|
||||
} else {
|
||||
$oCaseLog->AddLogEntry($proposedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
$ret = $oCaseLog;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->Get('sql');
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix;
|
||||
$aColumns['_index'] = $sPrefix . '_index';
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->Get('sql');
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix;
|
||||
$aColumns['_index'] = $sPrefix.'_index';
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return \ormCaseLog
|
||||
* @throws \MissingColumnException
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!array_key_exists($sPrefix, $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$sLog = $aCols[$sPrefix];
|
||||
/**
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return ormCaseLog
|
||||
* @throws MissingColumnException
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!array_key_exists($sPrefix, $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$sLog = $aCols[$sPrefix];
|
||||
|
||||
if (isset($aCols[$sPrefix . '_index'])) {
|
||||
$sIndex = $aCols[$sPrefix . '_index'];
|
||||
} else {
|
||||
// For backward compatibility, allow the current state to be: 1 log, no index
|
||||
$sIndex = '';
|
||||
}
|
||||
if (isset($aCols[$sPrefix.'_index'])) {
|
||||
$sIndex = $aCols[$sPrefix.'_index'];
|
||||
} else {
|
||||
// For backward compatibility, allow the current state to be: 1 log, no index
|
||||
$sIndex = '';
|
||||
}
|
||||
|
||||
if (strlen($sIndex) > 0) {
|
||||
$aIndex = unserialize($sIndex);
|
||||
$value = new ormCaseLog($sLog, $aIndex);
|
||||
} else {
|
||||
$value = new ormCaseLog($sLog);
|
||||
}
|
||||
if (strlen($sIndex) > 0) {
|
||||
$aIndex = unserialize($sIndex);
|
||||
$value = new ormCaseLog($sLog, $aIndex);
|
||||
} else {
|
||||
$value = new ormCaseLog($sLog);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
if (!($value instanceof ormCaseLog)) {
|
||||
$value = new ormCaseLog('');
|
||||
}
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode()] = $value->GetText();
|
||||
$aValues[$this->GetCode() . '_index'] = serialize($value->GetIndex());
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
if (!($value instanceof ormCaseLog)) {
|
||||
$value = new ormCaseLog('');
|
||||
}
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode()] = $value->GetText();
|
||||
$aValues[$this->GetCode().'_index'] = serialize($value->GetIndex());
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'LONGTEXT' // 2^32 (4 Gb)
|
||||
. CMDBSource::GetSqlStringColumnDefinition();
|
||||
$aColumns[$this->GetCode() . '_index'] = 'BLOB';
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'LONGTEXT' // 2^32 (4 Gb)
|
||||
.CMDBSource::GetSqlStringColumnDefinition();
|
||||
$aColumns[$this->GetCode().'_index'] = 'BLOB';
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
$sContent = $value->GetAsHTML(null, false, array(__class__, 'RenderWikiHtml'));
|
||||
} else {
|
||||
$sContent = '';
|
||||
}
|
||||
$aStyles = array();
|
||||
if ($this->GetWidth() != '') {
|
||||
$aStyles[] = 'width:' . $this->GetWidth();
|
||||
}
|
||||
if ($this->GetHeight() != '') {
|
||||
$aStyles[] = 'height:' . $this->GetHeight();
|
||||
}
|
||||
$sStyle = '';
|
||||
if (count($aStyles) > 0) {
|
||||
$sStyle = 'style="' . implode(';', $aStyles) . '"';
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
$sContent = $value->GetAsHTML(null, false, array(__class__, 'RenderWikiHtml'));
|
||||
} else {
|
||||
$sContent = '';
|
||||
}
|
||||
$aStyles = array();
|
||||
if ($this->GetWidth() != '') {
|
||||
$aStyles[] = 'width:'.$this->GetWidth();
|
||||
}
|
||||
if ($this->GetHeight() != '') {
|
||||
$aStyles[] = 'height:'.$this->GetHeight();
|
||||
}
|
||||
$sStyle = '';
|
||||
if (count($aStyles) > 0) {
|
||||
$sStyle = 'style="'.implode(';', $aStyles).'"';
|
||||
}
|
||||
|
||||
return "<div class=\"caselog\" $sStyle>" . $sContent . '</div>';
|
||||
}
|
||||
return "<div class=\"caselog\" $sStyle>".$sContent.'</div>';
|
||||
}
|
||||
|
||||
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
return parent::GetAsCSV($value->GetText($bConvertToPlainText), $sSeparator, $sTextQualifier, $oHostObject,
|
||||
$bLocalize, $bConvertToPlainText);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
return parent::GetAsCSV($value->GetText($bConvertToPlainText), $sSeparator, $sTextQualifier, $oHostObject,
|
||||
$bLocalize, $bConvertToPlainText);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
return parent::GetAsXML($value->GetText(), $oHostObject, $bLocalize);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormCaseLog) {
|
||||
return parent::GetAsXML($value->GetText(), $oHostObject, $bLocalize);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List the available verbs for 'GetForTemplate'
|
||||
*/
|
||||
public function EnumTemplateVerbs()
|
||||
{
|
||||
return array(
|
||||
'' => 'Plain text representation of all the log entries',
|
||||
'head' => 'Plain text representation of the latest entry',
|
||||
'head_html' => 'HTML representation of the latest entry',
|
||||
'html' => 'HTML representation of all the log entries',
|
||||
);
|
||||
}
|
||||
/**
|
||||
* List the available verbs for 'GetForTemplate'
|
||||
*/
|
||||
public function EnumTemplateVerbs()
|
||||
{
|
||||
return array(
|
||||
'' => 'Plain text representation of all the log entries',
|
||||
'head' => 'Plain text representation of the latest entry',
|
||||
'head_html' => 'HTML representation of the latest entry',
|
||||
'html' => 'HTML representation of all the log entries',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get various representations of the value, for insertion into a template (e.g. in Notifications)
|
||||
*
|
||||
* @param $value mixed The current value of the field
|
||||
* @param $sVerb string The verb specifying the representation of the value
|
||||
* @param $oHostObject DBObject The object
|
||||
* @param $bLocalize bool Whether or not to localize the value
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
switch ($sVerb) {
|
||||
case '':
|
||||
return $value->GetText(true);
|
||||
/**
|
||||
* Get various representations of the value, for insertion into a template (e.g. in Notifications)
|
||||
*
|
||||
* @param $value mixed The current value of the field
|
||||
* @param $sVerb string The verb specifying the representation of the value
|
||||
* @param $oHostObject DBObject The object
|
||||
* @param $bLocalize bool Whether or not to localize the value
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
switch ($sVerb) {
|
||||
case '':
|
||||
return $value->GetText(true);
|
||||
|
||||
case 'head':
|
||||
return $value->GetLatestEntry('text');
|
||||
case 'head':
|
||||
return $value->GetLatestEntry('text');
|
||||
|
||||
case 'head_html':
|
||||
return $value->GetLatestEntry('html');
|
||||
case 'head_html':
|
||||
return $value->GetLatestEntry('html');
|
||||
|
||||
case 'html':
|
||||
return $value->GetAsEmailHtml();
|
||||
case 'html':
|
||||
return $value->GetAsEmailHtml();
|
||||
|
||||
default:
|
||||
throw new Exception("Unknown verb '$sVerb' for attribute " . $this->GetCode() . ' in class ' . get_class($oHostObject));
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new \Exception("Unknown verb '$sVerb' for attribute ".$this->GetCode().' in class '.get_class($oHostObject));
|
||||
}
|
||||
}
|
||||
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
return $value->GetForJSON();
|
||||
}
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
return $value->GetForJSON();
|
||||
}
|
||||
|
||||
public function FromJSONToValue($json)
|
||||
{
|
||||
if (is_string($json)) {
|
||||
// Will be correctly handled in MakeRealValue
|
||||
$ret = $json;
|
||||
} else {
|
||||
if (isset($json->add_item)) {
|
||||
// Will be correctly handled in MakeRealValue
|
||||
$ret = $json->add_item;
|
||||
if (!isset($ret->message)) {
|
||||
throw new Exception("Missing mandatory entry: 'message'");
|
||||
}
|
||||
} else {
|
||||
$ret = ormCaseLog::FromJSON($json);
|
||||
}
|
||||
}
|
||||
public function FromJSONToValue($json)
|
||||
{
|
||||
if (is_string($json)) {
|
||||
// Will be correctly handled in MakeRealValue
|
||||
$ret = $json;
|
||||
} else {
|
||||
if (isset($json->add_item)) {
|
||||
// Will be correctly handled in MakeRealValue
|
||||
$ret = $json->add_item;
|
||||
if (!isset($ret->message)) {
|
||||
throw new Exception("Missing mandatory entry: 'message'");
|
||||
}
|
||||
} else {
|
||||
$ret = ormCaseLog::FromJSON($json);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function Fingerprint($value)
|
||||
{
|
||||
$sFingerprint = '';
|
||||
if ($value instanceof ormCaseLog) {
|
||||
$sFingerprint = $value->GetText();
|
||||
}
|
||||
public function Fingerprint($value)
|
||||
{
|
||||
$sFingerprint = '';
|
||||
if ($value instanceof ormCaseLog) {
|
||||
$sFingerprint = $value->GetText();
|
||||
}
|
||||
|
||||
return $sFingerprint;
|
||||
}
|
||||
return $sFingerprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual formatting of the text: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'html'); // default format for case logs is now HTML
|
||||
}
|
||||
/**
|
||||
* The actual formatting of the text: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'html'); // default format for case logs is now HTML
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\CaseLogField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\CaseLogField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
// First we call the parent so the field is build
|
||||
$oFormField = parent::MakeFormField($oObject, $oFormField);
|
||||
// Then only we set the value
|
||||
$oFormField->SetCurrentValue($this->GetEditValue($oObject->Get($this->GetCode())));
|
||||
// And we set the entries
|
||||
$oFormField->SetEntries($oObject->Get($this->GetCode())->GetAsArray());
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
// First we call the parent so the field is build
|
||||
$oFormField = parent::MakeFormField($oObject, $oFormField);
|
||||
// Then only we set the value
|
||||
$oFormField->SetCurrentValue($this->GetEditValue($oObject->Get($this->GetCode())));
|
||||
// And we set the entries
|
||||
$oFormField->SetEntries($oObject->Get($this->GetCode())->GetAsArray());
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
/** @var \ormCaseLog $value */
|
||||
$oMyChangeOp->Set("lastentry", $value->GetLatestEntryIndex());
|
||||
}
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
/** @var ormCaseLog $value */
|
||||
$oMyChangeOp->Set("lastentry", $value->GetLatestEntryIndex());
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeCaseLog::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeCaseLog::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use MetaModel;
|
||||
use ValueSetEnumClasses;
|
||||
|
||||
/**
|
||||
* An attribute that matches an object class
|
||||
@@ -7,78 +17,78 @@
|
||||
*/
|
||||
class AttributeClass extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM;
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_category', 'more_values'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_category', 'more_values'));
|
||||
}
|
||||
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aParams["allowed_values"] = new ValueSetEnumClasses($aParams['class_category'], $aParams['more_values']);
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aParams["allowed_values"] = new ValueSetEnumClasses($aParams['class_category'], $aParams['more_values']);
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
$sDefault = parent::GetDefaultValue($oHostObject);
|
||||
if (!$this->IsNullAllowed() && $this->IsNull($sDefault)) {
|
||||
// For this kind of attribute specifying null as default value
|
||||
// is authorized even if null is not allowed
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
$sDefault = parent::GetDefaultValue($oHostObject);
|
||||
if (!$this->IsNullAllowed() && $this->IsNull($sDefault)) {
|
||||
// For this kind of attribute specifying null as default value
|
||||
// is authorized even if null is not allowed
|
||||
|
||||
// Pick the first one...
|
||||
$aClasses = $this->GetAllowedValues();
|
||||
$sDefault = key($aClasses);
|
||||
}
|
||||
// Pick the first one...
|
||||
$aClasses = $this->GetAllowedValues();
|
||||
$sDefault = key($aClasses);
|
||||
}
|
||||
|
||||
return $sDefault;
|
||||
}
|
||||
return $sDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
if (!$oValSetDef) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
if (!$oValSetDef) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aListClass = $oValSetDef->GetValues($aArgs, $sContains);
|
||||
/* @since 3.3.0 remove elements in class_exclusion_list */
|
||||
$sClassExclusionList = $this->GetOptional('class_exclusion_list', null);
|
||||
if (!empty($sClassExclusionList)) {
|
||||
foreach (explode(',', $sClassExclusionList) as $sClassName) {
|
||||
unset($aListClass[trim($sClassName)]);
|
||||
}
|
||||
}
|
||||
$aListClass = $oValSetDef->GetValues($aArgs, $sContains);
|
||||
/* @since 3.3.0 remove elements in class_exclusion_list */
|
||||
$sClassExclusionList = $this->GetOptional('class_exclusion_list', null);
|
||||
if (!empty($sClassExclusionList)) {
|
||||
foreach (explode(',', $sClassExclusionList) as $sClassName) {
|
||||
unset($aListClass[trim($sClassName)]);
|
||||
}
|
||||
}
|
||||
|
||||
return $aListClass;
|
||||
}
|
||||
return $aListClass;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return MetaModel::GetName($sValue);
|
||||
}
|
||||
return MetaModel::GetName($sValue);
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,214 +1,229 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CoreUnexpectedValue;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use ormSet;
|
||||
use utils;
|
||||
|
||||
class AttributeClassAttCodeSet extends AttributeSet
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
const DEFAULT_PARAM_INCLUDE_CHILD_CLASSES_ATTRIBUTES = false;
|
||||
const DEFAULT_PARAM_INCLUDE_CHILD_CLASSES_ATTRIBUTES = false;
|
||||
|
||||
public function __construct($sCode, array $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
$this->aCSSClasses[] = 'attribute-class-attcode-set';
|
||||
}
|
||||
public function __construct($sCode, array $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
$this->aCSSClasses[] = 'attribute-class-attcode-set';
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_field', 'attribute_definition_list', 'attribute_definition_exclusion_list'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_field', 'attribute_definition_list', 'attribute_definition_exclusion_list'));
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return max(255, 15 * $this->GetMaxItems());
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return max(255, 15 * $this->GetMaxItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (!isset($aArgs['this'])) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (!isset($aArgs['this'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$oHostObj = $aArgs['this'];
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sRootClass = $oHostObj->Get($sTargetClass);
|
||||
$bIncludeChildClasses = $this->GetOptional('include_child_classes_attributes', static::DEFAULT_PARAM_INCLUDE_CHILD_CLASSES_ATTRIBUTES);
|
||||
$oHostObj = $aArgs['this'];
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sRootClass = $oHostObj->Get($sTargetClass);
|
||||
$bIncludeChildClasses = $this->GetOptional('include_child_classes_attributes', static::DEFAULT_PARAM_INCLUDE_CHILD_CLASSES_ATTRIBUTES);
|
||||
|
||||
$aExcludeDefs = array();
|
||||
$sAttDefExclusionList = $this->Get('attribute_definition_exclusion_list');
|
||||
if (!empty($sAttDefExclusionList)) {
|
||||
foreach (explode(',', $sAttDefExclusionList) as $sAttDefName) {
|
||||
$sAttDefName = trim($sAttDefName);
|
||||
$aExcludeDefs[$sAttDefName] = $sAttDefName;
|
||||
}
|
||||
}
|
||||
$aExcludeDefs = array();
|
||||
$sAttDefExclusionList = $this->Get('attribute_definition_exclusion_list');
|
||||
if (!empty($sAttDefExclusionList)) {
|
||||
foreach (explode(',', $sAttDefExclusionList) as $sAttDefName) {
|
||||
$sAttDefName = trim($sAttDefName);
|
||||
$aExcludeDefs[$sAttDefName] = $sAttDefName;
|
||||
}
|
||||
}
|
||||
|
||||
$aAllowedDefs = array();
|
||||
$sAttDefList = $this->Get('attribute_definition_list');
|
||||
if (!empty($sAttDefList)) {
|
||||
foreach (explode(',', $sAttDefList) as $sAttDefName) {
|
||||
$sAttDefName = trim($sAttDefName);
|
||||
$aAllowedDefs[$sAttDefName] = $sAttDefName;
|
||||
}
|
||||
}
|
||||
$aAllowedDefs = array();
|
||||
$sAttDefList = $this->Get('attribute_definition_list');
|
||||
if (!empty($sAttDefList)) {
|
||||
foreach (explode(',', $sAttDefList) as $sAttDefName) {
|
||||
$sAttDefName = trim($sAttDefName);
|
||||
$aAllowedDefs[$sAttDefName] = $sAttDefName;
|
||||
}
|
||||
}
|
||||
|
||||
$aAllAttributes = array();
|
||||
if (!empty($sRootClass)) {
|
||||
$aClasses = array($sRootClass);
|
||||
if ($bIncludeChildClasses === true) {
|
||||
$aClasses = $aClasses + MetaModel::EnumChildClasses($sRootClass, ENUM_CHILD_CLASSES_EXCLUDETOP);
|
||||
}
|
||||
$aAllAttributes = array();
|
||||
if (!empty($sRootClass)) {
|
||||
$aClasses = array($sRootClass);
|
||||
if ($bIncludeChildClasses === true) {
|
||||
$aClasses = $aClasses + MetaModel::EnumChildClasses($sRootClass, ENUM_CHILD_CLASSES_EXCLUDETOP);
|
||||
}
|
||||
|
||||
foreach ($aClasses as $sClass) {
|
||||
foreach (MetaModel::GetAttributesList($sClass) as $sAttCode) {
|
||||
// Add attribute only if not already there (can be in leaf classes but not the root)
|
||||
if (!array_key_exists($sAttCode, $aAllAttributes)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
$sAttDefClass = get_class($oAttDef);
|
||||
foreach ($aClasses as $sClass) {
|
||||
foreach (MetaModel::GetAttributesList($sClass) as $sAttCode) {
|
||||
// Add attribute only if not already there (can be in leaf classes but not the root)
|
||||
if (!array_key_exists($sAttCode, $aAllAttributes)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
$sAttDefClass = get_class($oAttDef);
|
||||
|
||||
// Skip excluded attdefs
|
||||
if (isset($aExcludeDefs[$sAttDefClass])) {
|
||||
continue;
|
||||
}
|
||||
// Skip not allowed attdefs only if list specified
|
||||
if (!empty($aAllowedDefs) && !isset($aAllowedDefs[$sAttDefClass])) {
|
||||
continue;
|
||||
}
|
||||
// Skip excluded attdefs
|
||||
if (isset($aExcludeDefs[$sAttDefClass])) {
|
||||
continue;
|
||||
}
|
||||
// Skip not allowed attdefs only if list specified
|
||||
if (!empty($aAllowedDefs) && !isset($aAllowedDefs[$sAttDefClass])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$aAllAttributes[$sAttCode] = array(
|
||||
'classes' => array($sClass),
|
||||
);
|
||||
} else {
|
||||
$aAllAttributes[$sAttCode]['classes'][] = $sClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$aAllAttributes[$sAttCode] = array(
|
||||
'classes' => array($sClass),
|
||||
);
|
||||
} else {
|
||||
$aAllAttributes[$sAttCode]['classes'][] = $sClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aAllowedAttributes = array();
|
||||
foreach ($aAllAttributes as $sAttCode => $aAttData) {
|
||||
$iAttClassesCount = count($aAttData['classes']);
|
||||
$sAttFirstClass = $aAttData['classes'][0];
|
||||
$sAttLabel = MetaModel::GetLabel($sAttFirstClass, $sAttCode);
|
||||
$aAllowedAttributes = array();
|
||||
foreach ($aAllAttributes as $sAttCode => $aAttData) {
|
||||
$iAttClassesCount = count($aAttData['classes']);
|
||||
$sAttFirstClass = $aAttData['classes'][0];
|
||||
$sAttLabel = MetaModel::GetLabel($sAttFirstClass, $sAttCode);
|
||||
|
||||
if ($sAttFirstClass === $sRootClass) {
|
||||
$sLabel = Dict::Format('Core:AttributeClassAttCodeSet:ItemLabel:AttributeFromClass', $sAttCode, $sAttLabel);
|
||||
} elseif ($iAttClassesCount === 1) {
|
||||
$sLabel = Dict::Format('Core:AttributeClassAttCodeSet:ItemLabel:AttributeFromOneChildClass', $sAttCode, $sAttLabel, MetaModel::GetName($sAttFirstClass));
|
||||
} else {
|
||||
$sLabel = Dict::Format('Core:AttributeClassAttCodeSet:ItemLabel:AttributeFromSeveralChildClasses', $sAttCode, $sAttLabel);
|
||||
}
|
||||
$aAllowedAttributes[$sAttCode] = $sLabel;
|
||||
}
|
||||
// N°6460 Always sort on the labels, not on the datamodel definition order
|
||||
natcasesort($aAllowedAttributes);
|
||||
if ($sAttFirstClass === $sRootClass) {
|
||||
$sLabel = Dict::Format('Core:AttributeClassAttCodeSet:ItemLabel:AttributeFromClass', $sAttCode, $sAttLabel);
|
||||
} elseif ($iAttClassesCount === 1) {
|
||||
$sLabel = Dict::Format('Core:AttributeClassAttCodeSet:ItemLabel:AttributeFromOneChildClass', $sAttCode, $sAttLabel, MetaModel::GetName($sAttFirstClass));
|
||||
} else {
|
||||
$sLabel = Dict::Format('Core:AttributeClassAttCodeSet:ItemLabel:AttributeFromSeveralChildClasses', $sAttCode, $sAttLabel);
|
||||
}
|
||||
$aAllowedAttributes[$sAttCode] = $sLabel;
|
||||
}
|
||||
// N°6460 Always sort on the labels, not on the datamodel definition order
|
||||
natcasesort($aAllowedAttributes);
|
||||
|
||||
return $aAllowedAttributes;
|
||||
}
|
||||
return $aAllowedAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @param bool $bIgnoreErrors
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||
{
|
||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
$aArgs = array();
|
||||
if (!empty($oHostObj)) {
|
||||
$aArgs['this'] = $oHostObj;
|
||||
}
|
||||
$aAllowedAttributes = $this->GetAllowedValues($aArgs);
|
||||
$aInvalidAttCodes = array();
|
||||
if (is_string($proposedValue) && !empty($proposedValue)) {
|
||||
$aJsonFromWidget = json_decode($proposedValue, true);
|
||||
if (is_null($aJsonFromWidget)) {
|
||||
$proposedValue = trim($proposedValue);
|
||||
$aProposedValues = $this->FromStringToArray($proposedValue);
|
||||
$aValues = array();
|
||||
foreach ($aProposedValues as $sValue) {
|
||||
$sAttCode = trim($sValue);
|
||||
if (empty($aAllowedAttributes) || isset($aAllowedAttributes[$sAttCode])) {
|
||||
$aValues[$sAttCode] = $sAttCode;
|
||||
} else {
|
||||
$aInvalidAttCodes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
$oSet->SetValues($aValues);
|
||||
}
|
||||
} elseif ($proposedValue instanceof ormSet) {
|
||||
$oSet = $proposedValue;
|
||||
}
|
||||
if (!empty($aInvalidAttCodes) && !$bIgnoreErrors) {
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObj->Get($sTargetClass);
|
||||
throw new CoreUnexpectedValue("The attribute(s) " . implode(', ', $aInvalidAttCodes) . " are invalid for class {$sClass}");
|
||||
}
|
||||
/**
|
||||
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param DBObject $oHostObj
|
||||
*
|
||||
* @param bool $bIgnoreErrors
|
||||
*
|
||||
* @return mixed
|
||||
* @throws CoreException
|
||||
* @throws CoreUnexpectedValue
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||
{
|
||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
$aArgs = array();
|
||||
if (!empty($oHostObj)) {
|
||||
$aArgs['this'] = $oHostObj;
|
||||
}
|
||||
$aAllowedAttributes = $this->GetAllowedValues($aArgs);
|
||||
$aInvalidAttCodes = array();
|
||||
if (is_string($proposedValue) && !empty($proposedValue)) {
|
||||
$aJsonFromWidget = json_decode($proposedValue, true);
|
||||
if (is_null($aJsonFromWidget)) {
|
||||
$proposedValue = trim($proposedValue);
|
||||
$aProposedValues = $this->FromStringToArray($proposedValue);
|
||||
$aValues = array();
|
||||
foreach ($aProposedValues as $sValue) {
|
||||
$sAttCode = trim($sValue);
|
||||
if (empty($aAllowedAttributes) || isset($aAllowedAttributes[$sAttCode])) {
|
||||
$aValues[$sAttCode] = $sAttCode;
|
||||
} else {
|
||||
$aInvalidAttCodes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
$oSet->SetValues($aValues);
|
||||
}
|
||||
} elseif ($proposedValue instanceof ormSet) {
|
||||
$oSet = $proposedValue;
|
||||
}
|
||||
if (!empty($aInvalidAttCodes) && !$bIgnoreErrors) {
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObj->Get($sTargetClass);
|
||||
throw new CoreUnexpectedValue("The attribute(s) ".implode(', ', $aInvalidAttCodes)." are invalid for class {$sClass}");
|
||||
}
|
||||
|
||||
return $oSet;
|
||||
}
|
||||
return $oSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
if (!empty($oHostObject) && $bLocalize) {
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObject->Get($sTargetClass);
|
||||
/**
|
||||
* @param $value
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
if (!empty($oHostObject) && $bLocalize) {
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObject->Get($sTargetClass);
|
||||
|
||||
$aLocalizedValues = array();
|
||||
foreach ($value as $sAttCode) {
|
||||
try {
|
||||
$sAttClass = $sClass;
|
||||
$aLocalizedValues = array();
|
||||
foreach ($value as $sAttCode) {
|
||||
try {
|
||||
$sAttClass = $sClass;
|
||||
|
||||
// Look for the first class (current or children) that have this attcode
|
||||
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
|
||||
if (MetaModel::IsValidAttCode($sChildClass, $sAttCode)) {
|
||||
$sAttClass = $sChildClass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Look for the first class (current or children) that have this attcode
|
||||
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
|
||||
if (MetaModel::IsValidAttCode($sChildClass, $sAttCode)) {
|
||||
$sAttClass = $sChildClass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$sLabelForHtmlAttribute = utils::HtmlEntities(MetaModel::GetLabel($sAttClass, $sAttCode) . " ($sAttCode)");
|
||||
$aLocalizedValues[] = '<span class="attribute-set-item" data-code="' . $sAttCode . '" data-label="' . $sLabelForHtmlAttribute . '" data-description="" data-tooltip-content="' . $sLabelForHtmlAttribute . '">' . $sAttCode . '</span>';
|
||||
} catch (Exception $e) {
|
||||
// Ignore bad values
|
||||
}
|
||||
}
|
||||
$value = $aLocalizedValues;
|
||||
}
|
||||
$value = implode('', $value);
|
||||
}
|
||||
return '<span class="' . implode(' ', $this->aCSSClasses) . '">' . $value . '</span>';
|
||||
}
|
||||
$sLabelForHtmlAttribute = utils::HtmlEntities(MetaModel::GetLabel($sAttClass, $sAttCode)." ($sAttCode)");
|
||||
$aLocalizedValues[] = '<span class="attribute-set-item" data-code="'.$sAttCode.'" data-label="'.$sLabelForHtmlAttribute.'" data-description="" data-tooltip-content="'.$sLabelForHtmlAttribute.'">'.$sAttCode.'</span>';
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Ignore bad values
|
||||
}
|
||||
}
|
||||
$value = $aLocalizedValues;
|
||||
}
|
||||
$value = implode('', $value);
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return (empty($proposedValue));
|
||||
}
|
||||
return '<span class="'.implode(' ', $this->aCSSClasses).'">'.$value.'</span>';
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return (empty($proposedValue));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* An attribute that matches a class state
|
||||
@@ -7,71 +16,72 @@
|
||||
*/
|
||||
class AttributeClassState extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_field'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_field'));
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (isset($aArgs['this'])) {
|
||||
$oHostObj = $aArgs['this'];
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObj->Get($sTargetClass);
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (isset($aArgs['this'])) {
|
||||
$oHostObj = $aArgs['this'];
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObj->Get($sTargetClass);
|
||||
|
||||
$aAllowedStates = array();
|
||||
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
|
||||
$aValues = MetaModel::EnumStates($sChildClass);
|
||||
foreach (array_keys($aValues) as $sState) {
|
||||
$aAllowedStates[$sState] = $sState . ' (' . MetaModel::GetStateLabel($sChildClass, $sState) . ')';
|
||||
}
|
||||
}
|
||||
return $aAllowedStates;
|
||||
}
|
||||
$aAllowedStates = array();
|
||||
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
|
||||
$aValues = MetaModel::EnumStates($sChildClass);
|
||||
foreach (array_keys($aValues) as $sState) {
|
||||
$aAllowedStates[$sState] = $sState.' ('.MetaModel::GetStateLabel($sChildClass, $sState).')';
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return $aAllowedStates;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($oHostObject)) {
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObject->Get($sTargetClass);
|
||||
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
|
||||
$aValues = MetaModel::EnumStates($sChildClass);
|
||||
if (in_array($sValue, $aValues)) {
|
||||
$sLabelForHtmlAttribute = utils::EscapeHtml($sValue . ' (' . MetaModel::GetStateLabel($sChildClass, $sValue) . ')');
|
||||
$sHTML = '<span class="attribute-set-item" data-code="' . $sValue . '" data-label="' . $sLabelForHtmlAttribute . '" data-description="" data-tooltip-content="' . $sLabelForHtmlAttribute . '">' . $sValue . '</span>';
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $sHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($oHostObject)) {
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObject->Get($sTargetClass);
|
||||
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
|
||||
$aValues = MetaModel::EnumStates($sChildClass);
|
||||
if (in_array($sValue, $aValues)) {
|
||||
$sLabelForHtmlAttribute = utils::EscapeHtml($sValue.' ('.MetaModel::GetStateLabel($sChildClass, $sValue).')');
|
||||
$sHTML = '<span class="attribute-set-item" data-code="'.$sValue.'" data-label="'.$sLabelForHtmlAttribute.'" data-description="" data-tooltip-content="'.$sLabelForHtmlAttribute.'">'.$sValue.'</span>';
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
return $sHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,18 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOp;
|
||||
use CMDBChangeOpSetAttributeCustomFields;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use ormCustomFieldsValue;
|
||||
use Str;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Custom fields managed by an external implementation
|
||||
@@ -7,443 +21,451 @@
|
||||
*/
|
||||
class AttributeCustomFields extends AttributeDefinition
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("handler_class"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("handler_class"));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "CustomFields";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "CustomFields";
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function LoadFromClassTables()
|
||||
{
|
||||
return false;
|
||||
} // See ReadValue...
|
||||
public static function LoadFromClassTables()
|
||||
{
|
||||
return false;
|
||||
} // See ReadValue...
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode());
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode());
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DBObject $oHostObject
|
||||
* @param array|null $aValues
|
||||
*
|
||||
* @return CustomFieldsHandler
|
||||
*/
|
||||
public function GetHandler($aValues = null)
|
||||
{
|
||||
$sHandlerClass = $this->Get('handler_class');
|
||||
/** @var \TemplateFieldsHandler $oHandler */
|
||||
$oHandler = new $sHandlerClass($this->GetCode());
|
||||
if (!is_null($aValues)) {
|
||||
$oHandler->SetCurrentValues($aValues);
|
||||
}
|
||||
/**
|
||||
* @param array|null $aValues
|
||||
*
|
||||
* @return TemplateFieldsHandler
|
||||
*/
|
||||
public function GetHandler($aValues = null)
|
||||
{
|
||||
$sHandlerClass = $this->Get('handler_class');
|
||||
/** @var TemplateFieldsHandler $oHandler */
|
||||
$oHandler = new $sHandlerClass($this->GetCode());
|
||||
if (!is_null($aValues)) {
|
||||
$oHandler->SetCurrentValues($aValues);
|
||||
}
|
||||
|
||||
return $oHandler;
|
||||
}
|
||||
return $oHandler;
|
||||
}
|
||||
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
$sHandlerClass = $this->Get('handler_class');
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
$sHandlerClass = $this->Get('handler_class');
|
||||
|
||||
return $sHandlerClass::GetPrerequisiteAttributes($sClass);
|
||||
}
|
||||
return $sHandlerClass::GetPrerequisiteAttributes($sClass);
|
||||
}
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return $this->GetForTemplate($sValue, '', $oHostObj, true);
|
||||
}
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return $this->GetForTemplate($sValue, '', $oHostObj, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the string representation out of the values given by the form defined in GetDisplayForm
|
||||
*/
|
||||
public function ReadValueFromPostedForm($oHostObject, $sFormPrefix)
|
||||
{
|
||||
$aRawData = json_decode(utils::ReadPostedParam("attr_{$sFormPrefix}{$this->GetCode()}", '{}', 'raw_data'), true);
|
||||
if ($aRawData != null) {
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aRawData);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Makes the string representation out of the values given by the form defined in GetDisplayForm
|
||||
*/
|
||||
public function ReadValueFromPostedForm($oHostObject, $sFormPrefix)
|
||||
{
|
||||
$aRawData = json_decode(utils::ReadPostedParam("attr_{$sFormPrefix}{$this->GetCode()}", '{}', 'raw_data'), true);
|
||||
if ($aRawData != null) {
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aRawData);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObject)
|
||||
{
|
||||
if (is_object($proposedValue) && ($proposedValue instanceof ormCustomFieldsValue)) {
|
||||
if (false === $oHostObject->IsNew()) {
|
||||
// In that case we need additional keys : see \TemplateFieldsHandler::DoBuildForm
|
||||
$aRequestTemplateValues = $proposedValue->GetValues();
|
||||
if (false === array_key_exists('current_template_id', $aRequestTemplateValues)) {
|
||||
$aRequestTemplateValues['current_template_id'] = $aRequestTemplateValues['template_id'];
|
||||
$aRequestTemplateValues['current_template_data'] = $aRequestTemplateValues['template_data'];
|
||||
$proposedValue = new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aRequestTemplateValues);
|
||||
}
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObject)
|
||||
{
|
||||
if (is_object($proposedValue) && ($proposedValue instanceof ormCustomFieldsValue)) {
|
||||
if (false === $oHostObject->IsNew()) {
|
||||
// In that case we need additional keys : see \TemplateFieldsHandler::DoBuildForm
|
||||
$aRequestTemplateValues = $proposedValue->GetValues();
|
||||
if (false === array_key_exists('current_template_id', $aRequestTemplateValues)) {
|
||||
$aRequestTemplateValues['current_template_id'] = $aRequestTemplateValues['template_id'];
|
||||
$aRequestTemplateValues['current_template_data'] = $aRequestTemplateValues['template_data'];
|
||||
$proposedValue = new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aRequestTemplateValues);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($proposedValue->GetHostObject())) {
|
||||
// the object might not be set : for example in \AttributeCustomFields::FromJSONToValue we don't have the object available :(
|
||||
$proposedValue->SetHostObject($oHostObject);
|
||||
}
|
||||
if (is_null($proposedValue->GetHostObject())) {
|
||||
// the object might not be set : for example in \AttributeCustomFields::FromJSONToValue we don't have the object available :(
|
||||
$proposedValue->SetHostObject($oHostObject);
|
||||
}
|
||||
|
||||
return $proposedValue;
|
||||
}
|
||||
return $proposedValue;
|
||||
}
|
||||
|
||||
if (is_string($proposedValue)) {
|
||||
$aValues = json_decode($proposedValue, true);
|
||||
if (is_string($proposedValue)) {
|
||||
$aValues = json_decode($proposedValue, true);
|
||||
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aValues);
|
||||
}
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aValues);
|
||||
}
|
||||
|
||||
if (is_array($proposedValue)) {
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode(), $proposedValue);
|
||||
}
|
||||
if (is_array($proposedValue)) {
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode(), $proposedValue);
|
||||
}
|
||||
|
||||
if (is_null($proposedValue)) {
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode());
|
||||
}
|
||||
if (is_null($proposedValue)) {
|
||||
return new ormCustomFieldsValue($oHostObject, $this->GetCode());
|
||||
}
|
||||
|
||||
throw new Exception('Unexpected type for the value of a custom fields attribute: ' . gettype($proposedValue));
|
||||
}
|
||||
throw new Exception('Unexpected type for the value of a custom fields attribute: '.gettype($proposedValue));
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SubFormField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SubFormField';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to build the relevant form field
|
||||
*
|
||||
* When called first, $oFormField is null and will be created (eg. Make). Then when the ::parent is called and the
|
||||
* $oFormField is passed, MakeFormField behaves more like a Prepare.
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
$oFormField->SetForm($this->GetForm($oObject));
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
/**
|
||||
* Override to build the relevant form field
|
||||
*
|
||||
* When called first, $oFormField is null and will be created (eg. Make). Then when the ::parent is called and the
|
||||
* $oFormField is passed, MakeFormField behaves more like a Prepare.
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
$oFormField->SetForm($this->GetForm($oObject));
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DBObject $oHostObject
|
||||
* @param null $sFormPrefix
|
||||
*
|
||||
* @return Combodo\iTop\Form\Form
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetForm(DBObject $oHostObject, $sFormPrefix = null)
|
||||
{
|
||||
try {
|
||||
$oValue = $oHostObject->Get($this->GetCode());
|
||||
$oHandler = $this->GetHandler($oValue->GetValues());
|
||||
$sFormId = utils::IsNullOrEmptyString($sFormPrefix) ? 'cf_' . $this->GetCode() : $sFormPrefix . '_cf_' . $this->GetCode();
|
||||
$oHandler->BuildForm($oHostObject, $sFormId);
|
||||
$oForm = $oHandler->GetForm();
|
||||
} catch (Exception $e) {
|
||||
$oForm = new \Combodo\iTop\Form\Form('');
|
||||
$oField = new \Combodo\iTop\Form\Field\LabelField('');
|
||||
$oField->SetLabel('Custom field error: ' . $e->getMessage());
|
||||
$oForm->AddField($oField);
|
||||
$oForm->Finalize();
|
||||
}
|
||||
/**
|
||||
* @param DBObject $oHostObject
|
||||
* @param null $sFormPrefix
|
||||
*
|
||||
* @return Combodo\iTop\Form\Form
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetForm(DBObject $oHostObject, $sFormPrefix = null)
|
||||
{
|
||||
try {
|
||||
$oValue = $oHostObject->Get($this->GetCode());
|
||||
$oHandler = $this->GetHandler($oValue->GetValues());
|
||||
$sFormId = utils::IsNullOrEmptyString($sFormPrefix) ? 'cf_'.$this->GetCode() : $sFormPrefix.'_cf_'.$this->GetCode();
|
||||
$oHandler->BuildForm($oHostObject, $sFormId);
|
||||
$oForm = $oHandler->GetForm();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$oForm = new \Combodo\iTop\Form\Form('');
|
||||
$oField = new \Combodo\iTop\Form\Field\LabelField('');
|
||||
$oField->SetLabel('Custom field error: '.$e->getMessage());
|
||||
$oForm->AddField($oField);
|
||||
$oForm->Finalize();
|
||||
}
|
||||
|
||||
return $oForm;
|
||||
}
|
||||
return $oForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data from where it has been stored. This verb must be implemented as soon as LoadFromClassTables returns false
|
||||
* and LoadInObject returns true
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
*
|
||||
* @return mixed|null
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function ReadExternalValues(DBObject $oHostObject)
|
||||
{
|
||||
try {
|
||||
$oHandler = $this->GetHandler();
|
||||
$aValues = $oHandler->ReadValues($oHostObject);
|
||||
$oRet = new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aValues);
|
||||
} catch (Exception $e) {
|
||||
$oRet = new ormCustomFieldsValue($oHostObject, $this->GetCode());
|
||||
}
|
||||
/**
|
||||
* Read the data from where it has been stored. This verb must be implemented as soon as LoadFromClassTables returns false
|
||||
* and LoadInObject returns true
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
*
|
||||
* @return mixed|null
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function ReadExternalValues(DBObject $oHostObject)
|
||||
{
|
||||
try {
|
||||
$oHandler = $this->GetHandler();
|
||||
$aValues = $oHandler->ReadValues($oHostObject);
|
||||
$oRet = new ormCustomFieldsValue($oHostObject, $this->GetCode(), $aValues);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$oRet = new ormCustomFieldsValue($oHostObject, $this->GetCode());
|
||||
}
|
||||
|
||||
return $oRet;
|
||||
}
|
||||
return $oRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 3.1.0 N°6043 Move code contained in \AttributeCustomFields::WriteValue to this generic method
|
||||
*/
|
||||
public function WriteExternalValues(DBObject $oHostObject): void
|
||||
{
|
||||
$oValue = $oHostObject->Get($this->GetCode());
|
||||
if (!($oValue instanceof ormCustomFieldsValue)) {
|
||||
$oHandler = $this->GetHandler();
|
||||
$aValues = array();
|
||||
} else {
|
||||
// Pass the values through the form to make sure that they are correct
|
||||
$oHandler = $this->GetHandler($oValue->GetValues());
|
||||
$oHandler->BuildForm($oHostObject, '');
|
||||
$oForm = $oHandler->GetForm();
|
||||
$aValues = $oForm->GetCurrentValues();
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 3.1.0 N°6043 Move code contained in \AttributeCustomFields::WriteValue to this generic method
|
||||
*/
|
||||
public function WriteExternalValues(DBObject $oHostObject): void
|
||||
{
|
||||
$oValue = $oHostObject->Get($this->GetCode());
|
||||
if (!($oValue instanceof ormCustomFieldsValue)) {
|
||||
$oHandler = $this->GetHandler();
|
||||
$aValues = array();
|
||||
} else {
|
||||
// Pass the values through the form to make sure that they are correct
|
||||
$oHandler = $this->GetHandler($oValue->GetValues());
|
||||
$oHandler->BuildForm($oHostObject, '');
|
||||
$oForm = $oHandler->GetForm();
|
||||
$aValues = $oForm->GetCurrentValues();
|
||||
}
|
||||
|
||||
$oHandler->WriteValues($oHostObject, $aValues);
|
||||
}
|
||||
$oHandler->WriteValues($oHostObject, $aValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* The part of the current attribute in the object's signature, for the supplied value
|
||||
*
|
||||
* @param ormCustomFieldsValue $value The value of this attribute for the object
|
||||
*
|
||||
* @return string The "signature" for this field/attribute
|
||||
*/
|
||||
public function Fingerprint($value)
|
||||
{
|
||||
$oHandler = $this->GetHandler($value->GetValues());
|
||||
/**
|
||||
* The part of the current attribute in the object's signature, for the supplied value
|
||||
*
|
||||
* @param ormCustomFieldsValue $value The value of this attribute for the object
|
||||
*
|
||||
* @return string The "signature" for this field/attribute
|
||||
*/
|
||||
public function Fingerprint($value)
|
||||
{
|
||||
$oHandler = $this->GetHandler($value->GetValues());
|
||||
|
||||
return $oHandler->GetValueFingerprint();
|
||||
}
|
||||
return $oHandler->GetValueFingerprint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the validity of the data
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
* @param $value
|
||||
*
|
||||
* @return bool|string true or error message
|
||||
*/
|
||||
public function CheckValue(DBObject $oHostObject, $value)
|
||||
{
|
||||
try {
|
||||
$oHandler = $this->GetHandler($value->GetValues());
|
||||
$oHandler->BuildForm($oHostObject, '');
|
||||
$ret = $oHandler->Validate($oHostObject);
|
||||
} catch (Exception $e) {
|
||||
$ret = $e->getMessage();
|
||||
}
|
||||
/**
|
||||
* Check the validity of the data
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
* @param $value
|
||||
*
|
||||
* @return bool|string true or error message
|
||||
*/
|
||||
public function CheckValue(DBObject $oHostObject, $value)
|
||||
{
|
||||
try {
|
||||
$oHandler = $this->GetHandler($value->GetValues());
|
||||
$oHandler->BuildForm($oHostObject, '');
|
||||
$ret = $oHandler->Validate($oHostObject);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$ret = $e->getMessage();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup data upon object deletion (object id still available here)
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function DeleteExternalValues(DBObject $oHostObject): void
|
||||
{
|
||||
$oValue = $oHostObject->Get($this->GetCode());
|
||||
$oHandler = $this->GetHandler($oValue->GetValues());
|
||||
/**
|
||||
* Cleanup data upon object deletion (object id still available here)
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function DeleteExternalValues(DBObject $oHostObject): void
|
||||
{
|
||||
$oValue = $oHostObject->Get($this->GetCode());
|
||||
$oHandler = $this->GetHandler($oValue->GetValues());
|
||||
|
||||
$oHandler->DeleteValues($oHostObject);
|
||||
}
|
||||
$oHandler->DeleteValues($oHostObject);
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
try {
|
||||
/** @var \ormCustomFieldsValue $value */
|
||||
$sRet = $value->GetAsHTML($bLocalize);
|
||||
} catch (Exception $e) {
|
||||
$sRet = 'Custom field error: ' . utils::EscapeHtml($e->getMessage());
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
try {
|
||||
/** @var ormCustomFieldsValue $value */
|
||||
$sRet = $value->GetAsHTML($bLocalize);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sRet = 'Custom field error: '.utils::EscapeHtml($e->getMessage());
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetAsXML($bLocalize);
|
||||
} catch (Exception $e) {
|
||||
$sRet = Str::pure2xml('Custom field error: ' . $e->getMessage());
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetAsXML($bLocalize);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sRet = Str::pure2xml('Custom field error: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ormCustomFieldsValue $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return string
|
||||
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
|
||||
*/
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetAsCSV($sSeparator, $sTextQualifier, $bLocalize, $bConvertToPlainText);
|
||||
} catch (Exception $e) {
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, 'Custom field error: ' . $e->getMessage());
|
||||
$sRet = $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
}
|
||||
/**
|
||||
* @param ormCustomFieldsValue $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return string
|
||||
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
|
||||
*/
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetAsCSV($sSeparator, $sTextQualifier, $bLocalize, $bConvertToPlainText);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, 'Custom field error: '.$e->getMessage());
|
||||
$sRet = $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the available verbs for 'GetForTemplate'
|
||||
*/
|
||||
public function EnumTemplateVerbs()
|
||||
{
|
||||
$sHandlerClass = $this->Get('handler_class');
|
||||
/**
|
||||
* List the available verbs for 'GetForTemplate'
|
||||
*/
|
||||
public function EnumTemplateVerbs()
|
||||
{
|
||||
$sHandlerClass = $this->Get('handler_class');
|
||||
|
||||
return $sHandlerClass::EnumTemplateVerbs();
|
||||
}
|
||||
return $sHandlerClass::EnumTemplateVerbs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get various representations of the value, for insertion into a template (e.g. in Notifications)
|
||||
*
|
||||
* @param $value mixed The current value of the field
|
||||
* @param $sVerb string The verb specifying the representation of the value
|
||||
* @param $oHostObject DBObject The object
|
||||
* @param $bLocalize bool Whether or not to localize the value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetForTemplate($sVerb, $bLocalize);
|
||||
} catch (Exception $e) {
|
||||
$sRet = 'Custom field error: ' . $e->getMessage();
|
||||
}
|
||||
/**
|
||||
* Get various representations of the value, for insertion into a template (e.g. in Notifications)
|
||||
*
|
||||
* @param $value mixed The current value of the field
|
||||
* @param $sVerb string The verb specifying the representation of the value
|
||||
* @param $oHostObject DBObject The object
|
||||
* @param $bLocalize bool Whether or not to localize the value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetForTemplate($sVerb, $bLocalize);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sRet = 'Custom field error: '.$e->getMessage();
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param \ormCustomFieldsValue $value
|
||||
*
|
||||
* @return string|array
|
||||
*
|
||||
* @since 3.1.0 N°1150 now returns the value (was always returning null before)
|
||||
*/
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetForJSON();
|
||||
} catch (Exception $e) {
|
||||
$sRet = 'Custom field error: ' . $e->getMessage();
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param ormCustomFieldsValue $value
|
||||
*
|
||||
* @return string|array
|
||||
*
|
||||
* @since 3.1.0 N°1150 now returns the value (was always returning null before)
|
||||
*/
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
try {
|
||||
$sRet = $value->GetForJSON();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sRet = 'Custom field error: '.$e->getMessage();
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return ?\ormCustomFieldsValue with empty host object as we don't have it here (most consumers don't have an object in their context, for example in \RestUtils::GetObjectSetFromKey)
|
||||
* The host object will be set in {@see MakeRealValue}
|
||||
* All the necessary checks will be done in {@see CheckValue}
|
||||
*/
|
||||
public function FromJSONToValue($json)
|
||||
{
|
||||
return ormCustomFieldsValue::FromJSONToValue($json, $this);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return ?ormCustomFieldsValue with empty host object as we don't have it here (most consumers don't have an object in their context, for example in \RestUtils::GetObjectSetFromKey)
|
||||
* The host object will be set in {@see MakeRealValue}
|
||||
* All the necessary checks will be done in {@see CheckValue}
|
||||
*/
|
||||
public function FromJSONToValue($json)
|
||||
{
|
||||
return ormCustomFieldsValue::FromJSONToValue($json, $this);
|
||||
}
|
||||
|
||||
public function Equals($val1, $val2)
|
||||
{
|
||||
try {
|
||||
$bEquals = $val1->Equals($val2);
|
||||
} catch (Exception $e) {
|
||||
$bEquals = false;
|
||||
}
|
||||
public function Equals($val1, $val2)
|
||||
{
|
||||
try {
|
||||
$bEquals = $val1->Equals($val2);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$bEquals = false;
|
||||
}
|
||||
|
||||
return $bEquals;
|
||||
}
|
||||
return $bEquals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Protection against wrong value type
|
||||
if (false === ($proposedValue instanceof ormCustomFieldsValue)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Protection against wrong value type
|
||||
if (false === ($proposedValue instanceof ormCustomFieldsValue)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
|
||||
return count($proposedValue->GetValues()) > 0;
|
||||
}
|
||||
return count($proposedValue->GetValues()) > 0;
|
||||
}
|
||||
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
$oMyChangeOp->Set("prevdata", json_encode($original->GetValues()));
|
||||
}
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
$oMyChangeOp->Set("prevdata", json_encode($original->GetValues()));
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeCustomFields::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeCustomFields::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
|
||||
/**
|
||||
* Base class for all kind of DB attributes, with the exception of external keys
|
||||
@@ -7,18 +15,18 @@
|
||||
*/
|
||||
class AttributeDBField extends AttributeDBFieldVoid
|
||||
{
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("default_value", "is_null_allowed"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("default_value", "is_null_allowed"));
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->MakeRealValue($this->Get("default_value"), $oHostObject);
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->MakeRealValue($this->Get("default_value"), $oHostObject);
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use DBObject;
|
||||
|
||||
/**
|
||||
* Abstract class implementing default filters for a DB column
|
||||
@@ -7,140 +16,140 @@
|
||||
*/
|
||||
class AttributeDBFieldVoid extends AttributeDefinition
|
||||
{
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("allowed_values", "depends_on", "sql"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("allowed_values", "depends_on", "sql"));
|
||||
}
|
||||
|
||||
// To be overriden, used in GetSQLColumns
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return 'VARCHAR(255)'
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
// To be overriden, used in GetSQLColumns
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return 'VARCHAR(255)'
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
protected function GetSQLColSpec()
|
||||
{
|
||||
$default = $this->ScalarToSQL($this->GetDefaultValue());
|
||||
if (is_null($default)) {
|
||||
$sRet = '';
|
||||
} else {
|
||||
if (is_numeric($default)) {
|
||||
// Though it is a string in PHP, it will be considered as a numeric value in MySQL
|
||||
// Then it must not be quoted here, to preserve the compatibility with the value returned by CMDBSource::GetFieldSpec
|
||||
$sRet = " DEFAULT $default";
|
||||
} else {
|
||||
$sRet = " DEFAULT " . CMDBSource::Quote($default);
|
||||
}
|
||||
}
|
||||
protected function GetSQLColSpec()
|
||||
{
|
||||
$default = $this->ScalarToSQL($this->GetDefaultValue());
|
||||
if (is_null($default)) {
|
||||
$sRet = '';
|
||||
} else {
|
||||
if (is_numeric($default)) {
|
||||
// Though it is a string in PHP, it will be considered as a numeric value in MySQL
|
||||
// Then it must not be quoted here, to preserve the compatibility with the value returned by CMDBSource::GetFieldSpec
|
||||
$sRet = " DEFAULT $default";
|
||||
} else {
|
||||
$sRet = " DEFAULT ".CMDBSource::Quote($default);
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return $this->Get("allowed_values");
|
||||
}
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return $this->Get("allowed_values");
|
||||
}
|
||||
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
return $this->Get("depends_on");
|
||||
}
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
return $this->Get("depends_on");
|
||||
}
|
||||
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return !$this->IsMagic();
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return !$this->IsMagic();
|
||||
}
|
||||
|
||||
public function GetSQLExpr()
|
||||
{
|
||||
return $this->Get("sql");
|
||||
}
|
||||
public function GetSQLExpr()
|
||||
{
|
||||
return $this->Get("sql");
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->MakeRealValue("", $oHostObject);
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->MakeRealValue("", $oHostObject);
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
protected function ScalarToSQL($value)
|
||||
{
|
||||
return $value;
|
||||
} // format value as a valuable SQL literal (quoted outside)
|
||||
//
|
||||
protected function ScalarToSQL($value)
|
||||
{
|
||||
return $value;
|
||||
} // format value as a valuable SQL literal (quoted outside)
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $this->Get("sql");
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $this->Get("sql");
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$value = $this->MakeRealValue($aCols[$sPrefix . ''], null);
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$value = $this->MakeRealValue($aCols[$sPrefix.''], null);
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$aValues = array();
|
||||
$aValues[$this->Get("sql")] = $this->ScalarToSQL($value);
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$aValues = array();
|
||||
$aValues[$this->Get("sql")] = $this->ScalarToSQL($value);
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get("sql")] = $this->GetSQLCol($bFullSpec);
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get("sql")] = $this->GetSQLCol($bFullSpec);
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array("=" => "equals", "!=" => "differs from");
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array("=" => "equals", "!=" => "differs from");
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "=";
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "=";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr() . " != $sQValue";
|
||||
break;
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr() . " = $sQValue";
|
||||
}
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr()." != $sQValue";
|
||||
break;
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr()." = $sQValue";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +1,110 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use MetaModel;
|
||||
use RuntimeDashboard;
|
||||
use utils;
|
||||
|
||||
class AttributeDashboard extends AttributeDefinition
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(),
|
||||
array("definition_file", "is_user_editable"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(),
|
||||
array("definition_file", "is_user_editable"));
|
||||
}
|
||||
|
||||
public function GetDashboard()
|
||||
{
|
||||
$sAttCode = $this->GetCode();
|
||||
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $sAttCode);
|
||||
$sFilePath = APPROOT . 'env-' . utils::GetCurrentEnvironment() . '/' . $this->Get('definition_file');
|
||||
return RuntimeDashboard::GetDashboard($sFilePath, $sClass . '__' . $sAttCode);
|
||||
}
|
||||
public function GetDashboard()
|
||||
{
|
||||
$sAttCode = $this->GetCode();
|
||||
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $sAttCode);
|
||||
$sFilePath = APPROOT.'env-'.utils::GetCurrentEnvironment().'/'.$this->Get('definition_file');
|
||||
|
||||
public function IsUserEditable()
|
||||
{
|
||||
return $this->Get('is_user_editable');
|
||||
}
|
||||
return RuntimeDashboard::GetDashboard($sFilePath, $sClass.'__'.$sAttCode);
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsUserEditable()
|
||||
{
|
||||
return $this->Get('is_user_editable');
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// if this verb returns false, then GetValue must be implemented
|
||||
public static function LoadInObject()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetValue($oHostObject)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
// if this verb returns false, then GetValue must be implemented
|
||||
public static function LoadInObject()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Always return false for now, we don't consider a custom version of a dashboard
|
||||
return false;
|
||||
}
|
||||
public function GetValue($oHostObject)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Always return false for now, we don't consider a custom version of a dashboard
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use DateTimeFormat;
|
||||
use DBObject;
|
||||
|
||||
/**
|
||||
* Map a date+time column to an attribute
|
||||
@@ -7,99 +17,99 @@
|
||||
*/
|
||||
class AttributeDate extends AttributeDateTime
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_DATE;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_DATE;
|
||||
|
||||
public static $oDateFormat = null;
|
||||
public static $oDateFormat = null;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function GetFormat()
|
||||
{
|
||||
if (self::$oDateFormat == null) {
|
||||
AttributeDateTime::LoadFormatFromConfig();
|
||||
}
|
||||
public static function GetFormat()
|
||||
{
|
||||
if (self::$oDateFormat == null) {
|
||||
AttributeDateTime::LoadFormatFromConfig();
|
||||
}
|
||||
|
||||
return self::$oDateFormat;
|
||||
}
|
||||
return self::$oDateFormat;
|
||||
}
|
||||
|
||||
public static function SetFormat(DateTimeFormat $oDateFormat)
|
||||
{
|
||||
self::$oDateFormat = $oDateFormat;
|
||||
}
|
||||
public static function SetFormat(DateTimeFormat $oDateFormat)
|
||||
{
|
||||
self::$oDateFormat = $oDateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format string used for the date & time stored in memory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetInternalFormat()
|
||||
{
|
||||
return 'Y-m-d';
|
||||
}
|
||||
/**
|
||||
* Returns the format string used for the date & time stored in memory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetInternalFormat()
|
||||
{
|
||||
return 'Y-m-d';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format string used for the date & time written to MySQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetSQLFormat()
|
||||
{
|
||||
return 'Y-m-d';
|
||||
}
|
||||
/**
|
||||
* Returns the format string used for the date & time written to MySQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetSQLFormat()
|
||||
{
|
||||
return 'Y-m-d';
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Date";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Date";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "DATE";
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "DATE";
|
||||
}
|
||||
|
||||
public function GetImportColumns()
|
||||
{
|
||||
// Allow an empty string to be a valid value (synonym for "reset")
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'VARCHAR(10)' . CMDBSource::GetSqlStringColumnDefinition();
|
||||
public function GetImportColumns()
|
||||
{
|
||||
// Allow an empty string to be a valid value (synonym for "reset")
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'VARCHAR(10)'.CMDBSource::GetSqlStringColumnDefinition();
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override to specify Field class
|
||||
*
|
||||
* When called first, $oFormField is null and will be created (eg. Make). Then when the ::parent is called and the
|
||||
* $oFormField is passed, MakeFormField behave more like a Prepare.
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
$oFormField = parent::MakeFormField($oObject, $oFormField);
|
||||
$oFormField->SetDateOnly(true);
|
||||
/**
|
||||
* Override to specify Field class
|
||||
*
|
||||
* When called first, $oFormField is null and will be created (eg. Make). Then when the ::parent is called and the
|
||||
* $oFormField is passed, MakeFormField behave more like a Prepare.
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
$oFormField = parent::MakeFormField($oObject, $oFormField);
|
||||
$oFormField->SetDateOnly(true);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,27 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use BinaryExpression;
|
||||
use CMDBSource;
|
||||
use CoreUnexpectedValue;
|
||||
use DateTime;
|
||||
use DateTimeFormat;
|
||||
use DateTimeImmutable;
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use Expression;
|
||||
use FieldExpression;
|
||||
use IssueLog;
|
||||
use MetaModel;
|
||||
use Str;
|
||||
use utils;
|
||||
use VariableExpression;
|
||||
|
||||
/**
|
||||
* Map a date+time column to an attribute
|
||||
@@ -7,482 +30,490 @@
|
||||
*/
|
||||
class AttributeDateTime extends AttributeDBField
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_DATE_TIME;
|
||||
|
||||
public static $oFormat = null;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return DateTimeFormat
|
||||
*/
|
||||
public static function GetFormat()
|
||||
{
|
||||
if (self::$oFormat == null) {
|
||||
static::LoadFormatFromConfig();
|
||||
}
|
||||
|
||||
return self::$oFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the 3 settings: date format, time format and data_time format from the configuration
|
||||
*/
|
||||
public static function LoadFormatFromConfig()
|
||||
{
|
||||
$aFormats = MetaModel::GetConfig()->Get('date_and_time_format');
|
||||
$sLang = Dict::GetUserLanguage();
|
||||
$sDateFormat = isset($aFormats[$sLang]['date']) ? $aFormats[$sLang]['date'] : (isset($aFormats['default']['date']) ? $aFormats['default']['date'] : 'Y-m-d');
|
||||
$sTimeFormat = isset($aFormats[$sLang]['time']) ? $aFormats[$sLang]['time'] : (isset($aFormats['default']['time']) ? $aFormats['default']['time'] : 'H:i:s');
|
||||
$sDateAndTimeFormat = isset($aFormats[$sLang]['date_time']) ? $aFormats[$sLang]['date_time'] : (isset($aFormats['default']['date_time']) ? $aFormats['default']['date_time'] : '$date $time');
|
||||
|
||||
$sFullFormat = str_replace(array('$date', '$time'), array($sDateFormat, $sTimeFormat), $sDateAndTimeFormat);
|
||||
|
||||
self::SetFormat(new DateTimeFormat($sFullFormat));
|
||||
AttributeDate::SetFormat(new DateTimeFormat($sDateFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format string used for the date & time stored in memory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetInternalFormat()
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format string used for the date & time written to MySQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetSQLFormat()
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
public static function SetFormat(DateTimeFormat $oDateTimeFormat)
|
||||
{
|
||||
self::$oFormat = $oDateTimeFormat;
|
||||
}
|
||||
|
||||
public static function GetSQLTimeFormat()
|
||||
{
|
||||
return 'H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a search string coming from user input
|
||||
*
|
||||
* @param string $sSearchString
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ParseSearchString($sSearchString)
|
||||
{
|
||||
try {
|
||||
$oDateTime = $this->GetFormat()->Parse($sSearchString);
|
||||
$sSearchString = $oDateTime->format($this->GetInternalFormat());
|
||||
} catch (Exception $e) {
|
||||
$sFormatString = '!' . (string)AttributeDate::GetFormat(); // BEWARE: ! is needed to set non-parsed fields to zero !!!
|
||||
$oDateTime = DateTime::createFromFormat($sFormatString, $sSearchString);
|
||||
if ($oDateTime !== false) {
|
||||
$sSearchString = $oDateTime->format($this->GetInternalFormat());
|
||||
}
|
||||
}
|
||||
|
||||
return $sSearchString;
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\DateTimeField';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to specify Field class
|
||||
*
|
||||
* When called first, $oFormField is null and will be created (eg. Make). Then when the ::parent is called and the
|
||||
* $oFormField is passed, MakeFormField behave more like a Prepare.
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
$oFormField->SetPHPDateTimeFormat((string)$this->GetFormat());
|
||||
$oFormField->SetJSDateTimeFormat($this->GetFormat()->ToMomentJS());
|
||||
|
||||
$oFormField = parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
// After call to the parent as it sets the current value
|
||||
$oValue = $oObject->Get($this->GetCode());
|
||||
if ($oValue === $this->GetNullValue()) {
|
||||
$oValue = $this->GetDefaultValue($oObject);
|
||||
}
|
||||
$oFormField->SetCurrentValue($this->GetFormat()->Format($oValue));
|
||||
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function EnumTemplateVerbs()
|
||||
{
|
||||
return array(
|
||||
'' => 'Formatted representation',
|
||||
'raw' => 'Not formatted representation',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
switch ($sVerb) {
|
||||
case '':
|
||||
case 'text':
|
||||
return static::GetFormat()->format($value);
|
||||
break;
|
||||
case 'html':
|
||||
// Note: Not passing formatted value as the method will format it.
|
||||
return $this->GetAsHTML($value);
|
||||
break;
|
||||
case 'raw':
|
||||
return $value;
|
||||
break;
|
||||
default:
|
||||
return parent::GetForTemplate($value, $sVerb, $oHostObject, $bLocalize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "DateTime";
|
||||
}
|
||||
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return (string)static::GetFormat()->format($sValue);
|
||||
}
|
||||
|
||||
public function GetValueLabel($sValue, $oHostObj = null)
|
||||
{
|
||||
return (string)static::GetFormat()->format($sValue);
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "DATETIME";
|
||||
}
|
||||
|
||||
public function GetImportColumns()
|
||||
{
|
||||
// Allow an empty string to be a valid value (synonym for "reset")
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'VARCHAR(19)' . CMDBSource::GetSqlStringColumnDefinition();
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public static function GetAsUnixSeconds($value)
|
||||
{
|
||||
$oDeadlineDateTime = new DateTime($value);
|
||||
$iUnixSeconds = $oDeadlineDateTime->format('U');
|
||||
|
||||
return $iUnixSeconds;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
$sDefaultValue = $this->Get('default_value');
|
||||
if (utils::IsNotNullOrEmptyString($sDefaultValue)) {
|
||||
try {
|
||||
$sDefaultDate = Expression::FromOQL($sDefaultValue)->Evaluate([]);
|
||||
} catch (Exception $e) {
|
||||
try {
|
||||
$sDefaultDate = Expression::FromOQL('"' . $sDefaultValue . '"')->Evaluate([]);
|
||||
} catch (Exception $e) {
|
||||
IssueLog::Error("Invalid default value '$sDefaultValue' for field '{$this->GetCode()}' on class '{$this->GetHostClass()}', defaulting to null");
|
||||
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
}
|
||||
try {
|
||||
$oDate = new DateTimeImmutable($sDefaultDate);
|
||||
} catch (Exception $e) {
|
||||
IssueLog::Error("Invalid default value '$sDefaultValue' for field '{$this->GetCode()}' on class '{$this->GetHostClass()}', defaulting to null");
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
return $oDate->format($this->GetInternalFormat());
|
||||
}
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return static::GetFormat()->ToRegExpr();
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"=" => "equals",
|
||||
"!=" => "differs from",
|
||||
"<" => "before",
|
||||
"<=" => "before",
|
||||
">" => "after (strictly)",
|
||||
">=" => "after",
|
||||
"SameDay" => "same day (strip time)",
|
||||
"SameMonth" => "same year/month",
|
||||
"SameYear" => "same year",
|
||||
"Today" => "today",
|
||||
">|" => "after today + N days",
|
||||
"<|" => "before today + N days",
|
||||
"=|" => "equals today + N days",
|
||||
);
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
// Unless we implement a "same xxx, depending on given precision" !
|
||||
return "=";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
|
||||
switch ($sOpCode) {
|
||||
case '=':
|
||||
case '!=':
|
||||
case '<':
|
||||
case '<=':
|
||||
case '>':
|
||||
case '>=':
|
||||
return $this->GetSQLExpr() . " $sOpCode $sQValue";
|
||||
case 'SameDay':
|
||||
return "DATE(" . $this->GetSQLExpr() . ") = DATE($sQValue)";
|
||||
case 'SameMonth':
|
||||
return "DATE_FORMAT(" . $this->GetSQLExpr() . ", '%Y-%m') = DATE_FORMAT($sQValue, '%Y-%m')";
|
||||
case 'SameYear':
|
||||
return "MONTH(" . $this->GetSQLExpr() . ") = MONTH($sQValue)";
|
||||
case 'Today':
|
||||
return "DATE(" . $this->GetSQLExpr() . ") = CURRENT_DATE()";
|
||||
case '>|':
|
||||
return "DATE(" . $this->GetSQLExpr() . ") > DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
|
||||
case '<|':
|
||||
return "DATE(" . $this->GetSQLExpr() . ") < DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
|
||||
case '=|':
|
||||
return "DATE(" . $this->GetSQLExpr() . ") = DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
|
||||
default:
|
||||
return $this->GetSQLExpr() . " = $sQValue";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param int|DateTime|string $proposedValue possible values :
|
||||
* - timestamp ({@see DateTime::getTimestamp())
|
||||
* - {@see \DateTime} PHP object
|
||||
* - string, following the {@see GetInternalFormat} format.
|
||||
*
|
||||
* @throws \CoreUnexpectedValue if invalid value type or the string passed cannot be converted
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_numeric($proposedValue)) {
|
||||
return date(static::GetInternalFormat(), $proposedValue);
|
||||
}
|
||||
|
||||
if (is_object($proposedValue) && ($proposedValue instanceof DateTime)) {
|
||||
return $proposedValue->format(static::GetInternalFormat());
|
||||
}
|
||||
|
||||
if (is_string($proposedValue)) {
|
||||
if (($proposedValue === '') && $this->IsNullAllowed()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$oFormat = new DateTimeFormat(static::GetInternalFormat());
|
||||
$oFormat->Parse($proposedValue);
|
||||
} catch (Exception $e) {
|
||||
throw new CoreUnexpectedValue('Wrong format for date attribute ' . $this->GetCode() . ', expecting "' . $this->GetInternalFormat() . '" and got "' . $proposedValue . '"');
|
||||
}
|
||||
|
||||
return $proposedValue;
|
||||
}
|
||||
|
||||
throw new CoreUnexpectedValue('Wrong format for date attribute ' . $this->GetCode());
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2html(static::GetFormat()->format($value));
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2xml($value);
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (empty($sValue) || ($sValue === '0000-00-00 00:00:00') || ($sValue === '0000-00-00')) {
|
||||
return '';
|
||||
} else {
|
||||
if ((string)static::GetFormat() !== static::GetInternalFormat()) {
|
||||
// Format conversion
|
||||
$oDate = new DateTime($sValue);
|
||||
if ($oDate !== false) {
|
||||
$sValue = static::GetFormat()->format($oDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
|
||||
return $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string to find some smart search patterns and build the corresponding search/OQL condition
|
||||
* Each derived class is reponsible for defining and processing their own smart patterns, the base class
|
||||
* does nothing special, and just calls the default (loose) operator
|
||||
*
|
||||
* @param string $sSearchText The search string to analyze for smart patterns
|
||||
* @param FieldExpression $oField The FieldExpression representing the atttribute code in this OQL query
|
||||
* @param array $aParams Values of the query parameters
|
||||
* @param bool $bParseSearchString
|
||||
*
|
||||
* @return Expression The search condition to be added (AND) to the current search
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetSmartConditionExpression(
|
||||
$sSearchText, FieldExpression $oField, &$aParams, $bParseSearchString = false
|
||||
)
|
||||
{
|
||||
// Possible smart patterns
|
||||
$aPatterns = array(
|
||||
'between' => array('pattern' => '/^\[(.*),(.*)\]$/', 'operator' => 'n/a'),
|
||||
'greater than or equal' => array('pattern' => '/^>=(.*)$/', 'operator' => '>='),
|
||||
'greater than' => array('pattern' => '/^>(.*)$/', 'operator' => '>'),
|
||||
'less than or equal' => array('pattern' => '/^<=(.*)$/', 'operator' => '<='),
|
||||
'less than' => array('pattern' => '/^<(.*)$/', 'operator' => '<'),
|
||||
);
|
||||
|
||||
$sPatternFound = '';
|
||||
$aMatches = array();
|
||||
foreach ($aPatterns as $sPatName => $sPattern) {
|
||||
if (preg_match($sPattern['pattern'], $sSearchText, $aMatches)) {
|
||||
$sPatternFound = $sPatName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($sPatternFound) {
|
||||
case 'between':
|
||||
|
||||
$sParamName1 = $oField->GetParent() . '_' . $oField->GetName() . '_1';
|
||||
$oRightExpr = new VariableExpression($sParamName1);
|
||||
if ($bParseSearchString) {
|
||||
$aParams[$sParamName1] = $this->ParseSearchString($aMatches[1]);
|
||||
} else {
|
||||
$aParams[$sParamName1] = $aMatches[1];
|
||||
}
|
||||
$oCondition1 = new BinaryExpression($oField, '>=', $oRightExpr);
|
||||
|
||||
$sParamName2 = $oField->GetParent() . '_' . $oField->GetName() . '_2';
|
||||
$oRightExpr = new VariableExpression($sParamName2);
|
||||
if ($bParseSearchString) {
|
||||
$aParams[$sParamName2] = $this->ParseSearchString($aMatches[2]);
|
||||
} else {
|
||||
$aParams[$sParamName2] = $aMatches[2];
|
||||
}
|
||||
$oCondition2 = new BinaryExpression($oField, '<=', $oRightExpr);
|
||||
|
||||
$oNewCondition = new BinaryExpression($oCondition1, 'AND', $oCondition2);
|
||||
break;
|
||||
|
||||
case 'greater than':
|
||||
case 'greater than or equal':
|
||||
case 'less than':
|
||||
case 'less than or equal':
|
||||
$sSQLOperator = $aPatterns[$sPatternFound]['operator'];
|
||||
$sParamName = $oField->GetParent() . '_' . $oField->GetName();
|
||||
$oRightExpr = new VariableExpression($sParamName);
|
||||
if ($bParseSearchString) {
|
||||
$aParams[$sParamName] = $this->ParseSearchString($aMatches[1]);
|
||||
} else {
|
||||
$aParams[$sParamName] = $aMatches[1];
|
||||
}
|
||||
$oNewCondition = new BinaryExpression($oField, $sSQLOperator, $oRightExpr);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$oNewCondition = parent::GetSmartConditionExpression($sSearchText, $oField, $aParams);
|
||||
|
||||
}
|
||||
|
||||
return $oNewCondition;
|
||||
}
|
||||
|
||||
|
||||
public function GetHelpOnSmartSearch()
|
||||
{
|
||||
$sDict = parent::GetHelpOnSmartSearch();
|
||||
|
||||
$oFormat = static::GetFormat();
|
||||
$sExample = $oFormat->Format(new DateTime('2015-07-19 18:40:00'));
|
||||
|
||||
return vsprintf($sDict, array($oFormat->ToPlaceholder(), $sExample));
|
||||
}
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_DATE_TIME;
|
||||
|
||||
public static $oFormat = null;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return DateTimeFormat
|
||||
*/
|
||||
public static function GetFormat()
|
||||
{
|
||||
if (self::$oFormat == null) {
|
||||
static::LoadFormatFromConfig();
|
||||
}
|
||||
|
||||
return self::$oFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the 3 settings: date format, time format and data_time format from the configuration
|
||||
*/
|
||||
public static function LoadFormatFromConfig()
|
||||
{
|
||||
$aFormats = MetaModel::GetConfig()->Get('date_and_time_format');
|
||||
$sLang = Dict::GetUserLanguage();
|
||||
$sDateFormat = isset($aFormats[$sLang]['date']) ? $aFormats[$sLang]['date'] : (isset($aFormats['default']['date']) ? $aFormats['default']['date'] : 'Y-m-d');
|
||||
$sTimeFormat = isset($aFormats[$sLang]['time']) ? $aFormats[$sLang]['time'] : (isset($aFormats['default']['time']) ? $aFormats['default']['time'] : 'H:i:s');
|
||||
$sDateAndTimeFormat = isset($aFormats[$sLang]['date_time']) ? $aFormats[$sLang]['date_time'] : (isset($aFormats['default']['date_time']) ? $aFormats['default']['date_time'] : '$date $time');
|
||||
|
||||
$sFullFormat = str_replace(array('$date', '$time'), array($sDateFormat, $sTimeFormat), $sDateAndTimeFormat);
|
||||
|
||||
self::SetFormat(new DateTimeFormat($sFullFormat));
|
||||
AttributeDate::SetFormat(new DateTimeFormat($sDateFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format string used for the date & time stored in memory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetInternalFormat()
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format string used for the date & time written to MySQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetSQLFormat()
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
public static function SetFormat(DateTimeFormat $oDateTimeFormat)
|
||||
{
|
||||
self::$oFormat = $oDateTimeFormat;
|
||||
}
|
||||
|
||||
public static function GetSQLTimeFormat()
|
||||
{
|
||||
return 'H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a search string coming from user input
|
||||
*
|
||||
* @param string $sSearchString
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ParseSearchString($sSearchString)
|
||||
{
|
||||
try {
|
||||
$oDateTime = $this->GetFormat()->Parse($sSearchString);
|
||||
$sSearchString = $oDateTime->format($this->GetInternalFormat());
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sFormatString = '!'.(string)AttributeDate::GetFormat(); // BEWARE: ! is needed to set non-parsed fields to zero !!!
|
||||
$oDateTime = DateTime::createFromFormat($sFormatString, $sSearchString);
|
||||
if ($oDateTime !== false) {
|
||||
$sSearchString = $oDateTime->format($this->GetInternalFormat());
|
||||
}
|
||||
}
|
||||
|
||||
return $sSearchString;
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\DateTimeField';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to specify Field class
|
||||
*
|
||||
* When called first, $oFormField is null and will be created (eg. Make). Then when the ::parent is called and the
|
||||
* $oFormField is passed, MakeFormField behave more like a Prepare.
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
$oFormField->SetPHPDateTimeFormat((string)$this->GetFormat());
|
||||
$oFormField->SetJSDateTimeFormat($this->GetFormat()->ToMomentJS());
|
||||
|
||||
$oFormField = parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
// After call to the parent as it sets the current value
|
||||
$oValue = $oObject->Get($this->GetCode());
|
||||
if ($oValue === $this->GetNullValue()) {
|
||||
$oValue = $this->GetDefaultValue($oObject);
|
||||
}
|
||||
$oFormField->SetCurrentValue($this->GetFormat()->Format($oValue));
|
||||
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function EnumTemplateVerbs()
|
||||
{
|
||||
return array(
|
||||
'' => 'Formatted representation',
|
||||
'raw' => 'Not formatted representation',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
switch ($sVerb) {
|
||||
case '':
|
||||
case 'text':
|
||||
return static::GetFormat()->format($value);
|
||||
break;
|
||||
case 'html':
|
||||
// Note: Not passing formatted value as the method will format it.
|
||||
return $this->GetAsHTML($value);
|
||||
break;
|
||||
case 'raw':
|
||||
return $value;
|
||||
break;
|
||||
default:
|
||||
return parent::GetForTemplate($value, $sVerb, $oHostObject, $bLocalize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "DateTime";
|
||||
}
|
||||
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return (string)static::GetFormat()->format($sValue);
|
||||
}
|
||||
|
||||
public function GetValueLabel($sValue, $oHostObj = null)
|
||||
{
|
||||
return (string)static::GetFormat()->format($sValue);
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "DATETIME";
|
||||
}
|
||||
|
||||
public function GetImportColumns()
|
||||
{
|
||||
// Allow an empty string to be a valid value (synonym for "reset")
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'VARCHAR(19)'.CMDBSource::GetSqlStringColumnDefinition();
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public static function GetAsUnixSeconds($value)
|
||||
{
|
||||
$oDeadlineDateTime = new DateTime($value);
|
||||
$iUnixSeconds = $oDeadlineDateTime->format('U');
|
||||
|
||||
return $iUnixSeconds;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
$sDefaultValue = $this->Get('default_value');
|
||||
if (utils::IsNotNullOrEmptyString($sDefaultValue)) {
|
||||
try {
|
||||
$sDefaultDate = Expression::FromOQL($sDefaultValue)->Evaluate([]);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
try {
|
||||
$sDefaultDate = Expression::FromOQL('"'.$sDefaultValue.'"')->Evaluate([]);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
IssueLog::Error("Invalid default value '$sDefaultValue' for field '{$this->GetCode()}' on class '{$this->GetHostClass()}', defaulting to null");
|
||||
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
}
|
||||
try {
|
||||
$oDate = new DateTimeImmutable($sDefaultDate);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
IssueLog::Error("Invalid default value '$sDefaultValue' for field '{$this->GetCode()}' on class '{$this->GetHostClass()}', defaulting to null");
|
||||
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
|
||||
return $oDate->format($this->GetInternalFormat());
|
||||
}
|
||||
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return static::GetFormat()->ToRegExpr();
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"=" => "equals",
|
||||
"!=" => "differs from",
|
||||
"<" => "before",
|
||||
"<=" => "before",
|
||||
">" => "after (strictly)",
|
||||
">=" => "after",
|
||||
"SameDay" => "same day (strip time)",
|
||||
"SameMonth" => "same year/month",
|
||||
"SameYear" => "same year",
|
||||
"Today" => "today",
|
||||
">|" => "after today + N days",
|
||||
"<|" => "before today + N days",
|
||||
"=|" => "equals today + N days",
|
||||
);
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
// Unless we implement a "same xxx, depending on given precision" !
|
||||
return "=";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
|
||||
switch ($sOpCode) {
|
||||
case '=':
|
||||
case '!=':
|
||||
case '<':
|
||||
case '<=':
|
||||
case '>':
|
||||
case '>=':
|
||||
return $this->GetSQLExpr()." $sOpCode $sQValue";
|
||||
case 'SameDay':
|
||||
return "DATE(".$this->GetSQLExpr().") = DATE($sQValue)";
|
||||
case 'SameMonth':
|
||||
return "DATE_FORMAT(".$this->GetSQLExpr().", '%Y-%m') = DATE_FORMAT($sQValue, '%Y-%m')";
|
||||
case 'SameYear':
|
||||
return "MONTH(".$this->GetSQLExpr().") = MONTH($sQValue)";
|
||||
case 'Today':
|
||||
return "DATE(".$this->GetSQLExpr().") = CURRENT_DATE()";
|
||||
case '>|':
|
||||
return "DATE(".$this->GetSQLExpr().") > DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
|
||||
case '<|':
|
||||
return "DATE(".$this->GetSQLExpr().") < DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
|
||||
case '=|':
|
||||
return "DATE(".$this->GetSQLExpr().") = DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
|
||||
default:
|
||||
return $this->GetSQLExpr()." = $sQValue";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param int|DateTime|string $proposedValue possible values :
|
||||
* - timestamp ({@see DateTime::getTimestamp())
|
||||
* - {@see \DateTime} PHP object
|
||||
* - string, following the {@see GetInternalFormat} format.
|
||||
*
|
||||
* @throws CoreUnexpectedValue if invalid value type or the string passed cannot be converted
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_numeric($proposedValue)) {
|
||||
return date(static::GetInternalFormat(), $proposedValue);
|
||||
}
|
||||
|
||||
if (is_object($proposedValue) && ($proposedValue instanceof DateTime)) {
|
||||
return $proposedValue->format(static::GetInternalFormat());
|
||||
}
|
||||
|
||||
if (is_string($proposedValue)) {
|
||||
if (($proposedValue === '') && $this->IsNullAllowed()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$oFormat = new DateTimeFormat(static::GetInternalFormat());
|
||||
$oFormat->Parse($proposedValue);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw new CoreUnexpectedValue('Wrong format for date attribute '.$this->GetCode().', expecting "'.$this->GetInternalFormat().'" and got "'.$proposedValue.'"');
|
||||
}
|
||||
|
||||
return $proposedValue;
|
||||
}
|
||||
|
||||
throw new CoreUnexpectedValue('Wrong format for date attribute '.$this->GetCode());
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2html(static::GetFormat()->format($value));
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2xml($value);
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (empty($sValue) || ($sValue === '0000-00-00 00:00:00') || ($sValue === '0000-00-00')) {
|
||||
return '';
|
||||
} else {
|
||||
if ((string)static::GetFormat() !== static::GetInternalFormat()) {
|
||||
// Format conversion
|
||||
$oDate = new DateTime($sValue);
|
||||
if ($oDate !== false) {
|
||||
$sValue = static::GetFormat()->format($oDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
|
||||
return $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string to find some smart search patterns and build the corresponding search/OQL condition
|
||||
* Each derived class is reponsible for defining and processing their own smart patterns, the base class
|
||||
* does nothing special, and just calls the default (loose) operator
|
||||
*
|
||||
* @param string $sSearchText The search string to analyze for smart patterns
|
||||
* @param FieldExpression $oField The FieldExpression representing the atttribute code in this OQL query
|
||||
* @param array $aParams Values of the query parameters
|
||||
* @param bool $bParseSearchString
|
||||
*
|
||||
* @return Expression The search condition to be added (AND) to the current search
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function GetSmartConditionExpression(
|
||||
$sSearchText, FieldExpression $oField, &$aParams, $bParseSearchString = false
|
||||
)
|
||||
{
|
||||
// Possible smart patterns
|
||||
$aPatterns = array(
|
||||
'between' => array('pattern' => '/^\[(.*),(.*)\]$/', 'operator' => 'n/a'),
|
||||
'greater than or equal' => array('pattern' => '/^>=(.*)$/', 'operator' => '>='),
|
||||
'greater than' => array('pattern' => '/^>(.*)$/', 'operator' => '>'),
|
||||
'less than or equal' => array('pattern' => '/^<=(.*)$/', 'operator' => '<='),
|
||||
'less than' => array('pattern' => '/^<(.*)$/', 'operator' => '<'),
|
||||
);
|
||||
|
||||
$sPatternFound = '';
|
||||
$aMatches = array();
|
||||
foreach ($aPatterns as $sPatName => $sPattern) {
|
||||
if (preg_match($sPattern['pattern'], $sSearchText, $aMatches)) {
|
||||
$sPatternFound = $sPatName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($sPatternFound) {
|
||||
case 'between':
|
||||
|
||||
$sParamName1 = $oField->GetParent().'_'.$oField->GetName().'_1';
|
||||
$oRightExpr = new VariableExpression($sParamName1);
|
||||
if ($bParseSearchString) {
|
||||
$aParams[$sParamName1] = $this->ParseSearchString($aMatches[1]);
|
||||
} else {
|
||||
$aParams[$sParamName1] = $aMatches[1];
|
||||
}
|
||||
$oCondition1 = new BinaryExpression($oField, '>=', $oRightExpr);
|
||||
|
||||
$sParamName2 = $oField->GetParent().'_'.$oField->GetName().'_2';
|
||||
$oRightExpr = new VariableExpression($sParamName2);
|
||||
if ($bParseSearchString) {
|
||||
$aParams[$sParamName2] = $this->ParseSearchString($aMatches[2]);
|
||||
} else {
|
||||
$aParams[$sParamName2] = $aMatches[2];
|
||||
}
|
||||
$oCondition2 = new BinaryExpression($oField, '<=', $oRightExpr);
|
||||
|
||||
$oNewCondition = new BinaryExpression($oCondition1, 'AND', $oCondition2);
|
||||
break;
|
||||
|
||||
case 'greater than':
|
||||
case 'greater than or equal':
|
||||
case 'less than':
|
||||
case 'less than or equal':
|
||||
$sSQLOperator = $aPatterns[$sPatternFound]['operator'];
|
||||
$sParamName = $oField->GetParent().'_'.$oField->GetName();
|
||||
$oRightExpr = new VariableExpression($sParamName);
|
||||
if ($bParseSearchString) {
|
||||
$aParams[$sParamName] = $this->ParseSearchString($aMatches[1]);
|
||||
} else {
|
||||
$aParams[$sParamName] = $aMatches[1];
|
||||
}
|
||||
$oNewCondition = new BinaryExpression($oField, $sSQLOperator, $oRightExpr);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$oNewCondition = parent::GetSmartConditionExpression($sSearchText, $oField, $aParams);
|
||||
|
||||
}
|
||||
|
||||
return $oNewCondition;
|
||||
}
|
||||
|
||||
|
||||
public function GetHelpOnSmartSearch()
|
||||
{
|
||||
$sDict = parent::GetHelpOnSmartSearch();
|
||||
|
||||
$oFormat = static::GetFormat();
|
||||
$sExample = $oFormat->Format(new DateTime('2015-07-19 18:40:00'));
|
||||
|
||||
return vsprintf($sDict, array($oFormat->ToPlaceholder(), $sExample));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* A dead line stored as a date & time
|
||||
@@ -7,74 +16,74 @@
|
||||
*/
|
||||
class AttributeDeadline extends AttributeDateTime
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sResult = self::FormatDeadline($value);
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sResult = self::FormatDeadline($value);
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
public static function FormatDeadline($value)
|
||||
{
|
||||
$sResult = '';
|
||||
if ($value !== null) {
|
||||
$iValue = AttributeDateTime::GetAsUnixSeconds($value);
|
||||
$sDate = AttributeDateTime::GetFormat()->Format($value);
|
||||
$difference = $iValue - time();
|
||||
public static function FormatDeadline($value)
|
||||
{
|
||||
$sResult = '';
|
||||
if ($value !== null) {
|
||||
$iValue = AttributeDateTime::GetAsUnixSeconds($value);
|
||||
$sDate = AttributeDateTime::GetFormat()->Format($value);
|
||||
$difference = $iValue - time();
|
||||
|
||||
if ($difference >= 0) {
|
||||
$sDifference = self::FormatDuration($difference);
|
||||
} else {
|
||||
$sDifference = Dict::Format('UI:DeadlineMissedBy_duration', self::FormatDuration(-$difference));
|
||||
}
|
||||
$sFormat = MetaModel::GetConfig()->Get('deadline_format');
|
||||
$sResult = str_replace(array('$date$', '$difference$'), array($sDate, $sDifference), $sFormat);
|
||||
}
|
||||
if ($difference >= 0) {
|
||||
$sDifference = self::FormatDuration($difference);
|
||||
} else {
|
||||
$sDifference = Dict::Format('UI:DeadlineMissedBy_duration', self::FormatDuration(-$difference));
|
||||
}
|
||||
$sFormat = MetaModel::GetConfig()->Get('deadline_format');
|
||||
$sResult = str_replace(array('$date$', '$difference$'), array($sDate, $sDifference), $sFormat);
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
static function FormatDuration($duration)
|
||||
{
|
||||
$days = floor($duration / 86400);
|
||||
$hours = floor(($duration - (86400 * $days)) / 3600);
|
||||
$minutes = floor(($duration - (86400 * $days + 3600 * $hours)) / 60);
|
||||
static function FormatDuration($duration)
|
||||
{
|
||||
$days = floor($duration / 86400);
|
||||
$hours = floor(($duration - (86400 * $days)) / 3600);
|
||||
$minutes = floor(($duration - (86400 * $days + 3600 * $hours)) / 60);
|
||||
|
||||
if ($duration < 60) {
|
||||
// Less than 1 min
|
||||
$sResult = Dict::S('UI:Deadline_LessThan1Min');
|
||||
} else {
|
||||
if ($duration < 3600) {
|
||||
// less than 1 hour, display it in minutes
|
||||
$sResult = Dict::Format('UI:Deadline_Minutes', $minutes);
|
||||
} else {
|
||||
if ($duration < 86400) {
|
||||
// Less that 1 day, display it in hours/minutes
|
||||
$sResult = Dict::Format('UI:Deadline_Hours_Minutes', $hours, $minutes);
|
||||
} else {
|
||||
// Less that 1 day, display it in hours/minutes
|
||||
$sResult = Dict::Format('UI:Deadline_Days_Hours_Minutes', $days, $hours, $minutes);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($duration < 60) {
|
||||
// Less than 1 min
|
||||
$sResult = Dict::S('UI:Deadline_LessThan1Min');
|
||||
} else {
|
||||
if ($duration < 3600) {
|
||||
// less than 1 hour, display it in minutes
|
||||
$sResult = Dict::Format('UI:Deadline_Minutes', $minutes);
|
||||
} else {
|
||||
if ($duration < 86400) {
|
||||
// Less that 1 day, display it in hours/minutes
|
||||
$sResult = Dict::Format('UI:Deadline_Hours_Minutes', $hours, $minutes);
|
||||
} else {
|
||||
// Less that 1 day, display it in hours/minutes
|
||||
$sResult = Dict::Format('UI:Deadline_Days_Hours_Minutes', $days, $hours, $minutes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use CoreException;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Map a decimal value column (suitable for financial computations) to an attribute
|
||||
@@ -10,148 +20,150 @@
|
||||
*/
|
||||
class AttributeDecimal extends AttributeDBField
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_NUMERIC;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_NUMERIC;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('digits', 'decimals' /* including precision */));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('digits', 'decimals' /* including precision */));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "DECIMAL(" . $this->Get('digits') . "," . $this->Get('decimals') . ")" . ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "DECIMAL(".$this->Get('digits').",".$this->Get('decimals').")".($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
$iNbDigits = $this->Get('digits');
|
||||
$iPrecision = $this->Get('decimals');
|
||||
$iNbIntegerDigits = $iNbDigits - $iPrecision;
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
$iNbDigits = $this->Get('digits');
|
||||
$iPrecision = $this->Get('decimals');
|
||||
$iNbIntegerDigits = $iNbDigits - $iPrecision;
|
||||
|
||||
return "^[\-\+]?\d{1,$iNbIntegerDigits}(\.\d{0,$iPrecision})?$";
|
||||
}
|
||||
return "^[\-\+]?\d{1,$iNbIntegerDigits}(\.\d{0,$iPrecision})?$";
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function CheckFormat($value)
|
||||
{
|
||||
$sRegExp = $this->GetValidationPattern();
|
||||
return preg_match("/$sRegExp/", $value);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function CheckFormat($value)
|
||||
{
|
||||
$sRegExp = $this->GetValidationPattern();
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"!=" => "differs from",
|
||||
"=" => "equals",
|
||||
">" => "greater (strict) than",
|
||||
">=" => "greater than",
|
||||
"<" => "less (strict) than",
|
||||
"<=" => "less than",
|
||||
"in" => "in"
|
||||
);
|
||||
}
|
||||
return preg_match("/$sRegExp/", $value);
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
// Unless we implement an "equals approximately..." or "same order of magnitude"
|
||||
return "=";
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"!=" => "differs from",
|
||||
"=" => "equals",
|
||||
">" => "greater (strict) than",
|
||||
">=" => "greater than",
|
||||
"<" => "less (strict) than",
|
||||
"<=" => "less than",
|
||||
"in" => "in",
|
||||
);
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr() . " != $sQValue";
|
||||
break;
|
||||
case '>':
|
||||
return $this->GetSQLExpr() . " > $sQValue";
|
||||
break;
|
||||
case '>=':
|
||||
return $this->GetSQLExpr() . " >= $sQValue";
|
||||
break;
|
||||
case '<':
|
||||
return $this->GetSQLExpr() . " < $sQValue";
|
||||
break;
|
||||
case '<=':
|
||||
return $this->GetSQLExpr() . " <= $sQValue";
|
||||
break;
|
||||
case 'in':
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException("Expected an array for argument value (sOpCode='$sOpCode')");
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
// Unless we implement an "equals approximately..." or "same order of magnitude"
|
||||
return "=";
|
||||
}
|
||||
|
||||
return $this->GetSQLExpr() . " IN ('" . implode("', '", $value) . "')";
|
||||
break;
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr()." != $sQValue";
|
||||
break;
|
||||
case '>':
|
||||
return $this->GetSQLExpr()." > $sQValue";
|
||||
break;
|
||||
case '>=':
|
||||
return $this->GetSQLExpr()." >= $sQValue";
|
||||
break;
|
||||
case '<':
|
||||
return $this->GetSQLExpr()." < $sQValue";
|
||||
break;
|
||||
case '<=':
|
||||
return $this->GetSQLExpr()." <= $sQValue";
|
||||
break;
|
||||
case 'in':
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException("Expected an array for argument value (sOpCode='$sOpCode')");
|
||||
}
|
||||
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr() . " = \"$value\"";
|
||||
}
|
||||
}
|
||||
return $this->GetSQLExpr()." IN ('".implode("', '", $value)."')";
|
||||
break;
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr()." = \"$value\"";
|
||||
}
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return is_null($proposedValue);
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return is_null($proposedValue);
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
|
||||
return $this->ScalarToSQL($proposedValue);
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
assert(is_null($value) || preg_match('/' . $this->GetValidationPattern() . '/', $value));
|
||||
return $this->ScalarToSQL($proposedValue);
|
||||
}
|
||||
|
||||
if (!is_null($value) && ($value !== '')) {
|
||||
$value = sprintf("%1." . $this->Get('decimals') . "F", $value);
|
||||
}
|
||||
return $value; // null or string
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
assert(is_null($value) || preg_match('/'.$this->GetValidationPattern().'/', $value));
|
||||
|
||||
if (!is_null($value) && ($value !== '')) {
|
||||
$value = sprintf("%1.".$this->Get('decimals')."F", $value);
|
||||
}
|
||||
|
||||
return $value; // null or string
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use Str;
|
||||
|
||||
/**
|
||||
* Store a duration as a number of seconds
|
||||
@@ -7,124 +17,124 @@
|
||||
*/
|
||||
class AttributeDuration extends AttributeInteger
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Duration";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Duration";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11) UNSIGNED";
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11) UNSIGNED";
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '0';
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '0';
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if (!is_numeric($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if (((int)$proposedValue) < 0) {
|
||||
return null;
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if (!is_numeric($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if (((int)$proposedValue) < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2html(self::FormatDuration($value));
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2html(self::FormatDuration($value));
|
||||
}
|
||||
|
||||
public static function FormatDuration($duration)
|
||||
{
|
||||
$aDuration = self::SplitDuration($duration);
|
||||
public static function FormatDuration($duration)
|
||||
{
|
||||
$aDuration = self::SplitDuration($duration);
|
||||
|
||||
if ($duration < 60) {
|
||||
// Less than 1 min
|
||||
$sResult = Dict::Format('Core:Duration_Seconds', $aDuration['seconds']);
|
||||
} else {
|
||||
if ($duration < 3600) {
|
||||
// less than 1 hour, display it in minutes/seconds
|
||||
$sResult = Dict::Format('Core:Duration_Minutes_Seconds', $aDuration['minutes'], $aDuration['seconds']);
|
||||
} else {
|
||||
if ($duration < 86400) {
|
||||
// Less than 1 day, display it in hours/minutes/seconds
|
||||
$sResult = Dict::Format('Core:Duration_Hours_Minutes_Seconds', $aDuration['hours'],
|
||||
$aDuration['minutes'], $aDuration['seconds']);
|
||||
} else {
|
||||
// more than 1 day, display it in days/hours/minutes/seconds
|
||||
$sResult = Dict::Format('Core:Duration_Days_Hours_Minutes_Seconds', $aDuration['days'],
|
||||
$aDuration['hours'], $aDuration['minutes'], $aDuration['seconds']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($duration < 60) {
|
||||
// Less than 1 min
|
||||
$sResult = Dict::Format('Core:Duration_Seconds', $aDuration['seconds']);
|
||||
} else {
|
||||
if ($duration < 3600) {
|
||||
// less than 1 hour, display it in minutes/seconds
|
||||
$sResult = Dict::Format('Core:Duration_Minutes_Seconds', $aDuration['minutes'], $aDuration['seconds']);
|
||||
} else {
|
||||
if ($duration < 86400) {
|
||||
// Less than 1 day, display it in hours/minutes/seconds
|
||||
$sResult = Dict::Format('Core:Duration_Hours_Minutes_Seconds', $aDuration['hours'],
|
||||
$aDuration['minutes'], $aDuration['seconds']);
|
||||
} else {
|
||||
// more than 1 day, display it in days/hours/minutes/seconds
|
||||
$sResult = Dict::Format('Core:Duration_Days_Hours_Minutes_Seconds', $aDuration['days'],
|
||||
$aDuration['hours'], $aDuration['minutes'], $aDuration['seconds']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
static function SplitDuration($duration)
|
||||
{
|
||||
$duration = (int)$duration;
|
||||
$days = floor($duration / 86400);
|
||||
$hours = floor(($duration - (86400 * $days)) / 3600);
|
||||
$minutes = floor(($duration - (86400 * $days + 3600 * $hours)) / 60);
|
||||
$seconds = ($duration % 60); // modulo
|
||||
static function SplitDuration($duration)
|
||||
{
|
||||
$duration = (int)$duration;
|
||||
$days = floor($duration / 86400);
|
||||
$hours = floor(($duration - (86400 * $days)) / 3600);
|
||||
$minutes = floor(($duration - (86400 * $days + 3600 * $hours)) / 60);
|
||||
$seconds = ($duration % 60); // modulo
|
||||
|
||||
return array('days' => $days, 'hours' => $hours, 'minutes' => $minutes, 'seconds' => $seconds);
|
||||
}
|
||||
return array('days' => $days, 'hours' => $hours, 'minutes' => $minutes, 'seconds' => $seconds);
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\DurationField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\DurationField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
// Note : As of today, this attribute is -by nature- only supported in readonly mode, not edition
|
||||
$sAttCode = $this->GetCode();
|
||||
$oFormField->SetCurrentValue($oObject->Get($sAttCode));
|
||||
$oFormField->SetReadOnly(true);
|
||||
// Note : As of today, this attribute is -by nature- only supported in readonly mode, not edition
|
||||
$sAttCode = $this->GetCode();
|
||||
$oFormField->SetCurrentValue($oObject->Get($sAttCode));
|
||||
$oFormField->SetReadOnly(true);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Specialization of a string: email
|
||||
@@ -7,41 +15,41 @@
|
||||
*/
|
||||
class AttributeEmailAddress extends AttributeString
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return $this->GetOptional('validation_pattern', '^' . utils::GetConfig()->Get('email_validation_pattern') . '$');
|
||||
}
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return $this->GetOptional('validation_pattern', '^'.utils::GetConfig()->Get('email_validation_pattern').'$');
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\EmailField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\EmailField';
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$sUrlDecorationClass = utils::GetConfig()->Get('email_decoration_class');
|
||||
$sUrlDecorationClass = utils::GetConfig()->Get('email_decoration_class');
|
||||
|
||||
return '<a class="mailto" href="mailto:' . $sValue . '"><span class="text_decoration ' . $sUrlDecorationClass . '"></span>' . parent::GetAsHTML($sValue) . '</a>';
|
||||
}
|
||||
return '<a class="mailto" href="mailto:'.$sValue.'"><span class="text_decoration '.$sUrlDecorationClass.'"></span>'.parent::GetAsHTML($sValue).'</a>';
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,16 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOp;
|
||||
use CMDBChangeOpSetAttributeEncrypted;
|
||||
use DBObject;
|
||||
use MetaModel;
|
||||
use SimpleCrypt;
|
||||
|
||||
/**
|
||||
* Map a text column (size < 255) to an attribute that is encrypted in the database
|
||||
@@ -10,75 +22,75 @@
|
||||
*/
|
||||
class AttributeEncryptedString extends AttributeString implements iAttributeNoGroupBy
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TINYBLOB";
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TINYBLOB";
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string)$proposedValue;
|
||||
}
|
||||
return (string)$proposedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt the value when reading from the database
|
||||
*
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$oSimpleCrypt = new SimpleCrypt(MetaModel::GetConfig()->GetEncryptionLibrary());
|
||||
$sValue = $oSimpleCrypt->Decrypt(MetaModel::GetConfig()->GetEncryptionKey(), $aCols[$sPrefix]);
|
||||
/**
|
||||
* Decrypt the value when reading from the database
|
||||
*
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$oSimpleCrypt = new SimpleCrypt(MetaModel::GetConfig()->GetEncryptionLibrary());
|
||||
$sValue = $oSimpleCrypt->Decrypt(MetaModel::GetConfig()->GetEncryptionKey(), $aCols[$sPrefix]);
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt the value before storing it in the database
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$oSimpleCrypt = new SimpleCrypt(MetaModel::GetConfig()->GetEncryptionLibrary());
|
||||
$encryptedValue = $oSimpleCrypt->Encrypt(MetaModel::GetConfig()->GetEncryptionKey(), $value);
|
||||
/**
|
||||
* Encrypt the value before storing it in the database
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$oSimpleCrypt = new SimpleCrypt(MetaModel::GetConfig()->GetEncryptionLibrary());
|
||||
$encryptedValue = $oSimpleCrypt->Encrypt(MetaModel::GetConfig()->GetEncryptionKey(), $value);
|
||||
|
||||
$aValues = array();
|
||||
$aValues[$this->Get("sql")] = $encryptedValue;
|
||||
$aValues = array();
|
||||
$aValues[$this->Get("sql")] = $encryptedValue;
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
if (is_null($original)) {
|
||||
$original = '';
|
||||
}
|
||||
$oMyChangeOp->Set("prevstring", $original);
|
||||
}
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
if (is_null($original)) {
|
||||
$original = '';
|
||||
}
|
||||
$oMyChangeOp->Set("prevstring", $original);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeEncrypted::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeEncrypted::class;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\Application\UI\Base\Component\FieldBadge\FieldBadgeUIBlockFactory;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use MySQLException;
|
||||
use ormStyle;
|
||||
|
||||
/**
|
||||
* Map a enum column to an attribute
|
||||
@@ -7,393 +22,398 @@
|
||||
*/
|
||||
class AttributeEnum extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array('styled_values'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array('styled_values'));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sValue
|
||||
*
|
||||
* @return \ormStyle|null
|
||||
*/
|
||||
public function GetStyle(?string $sValue): ?ormStyle
|
||||
{
|
||||
if ($this->IsParam('styled_values')) {
|
||||
$aStyles = $this->Get('styled_values');
|
||||
if (array_key_exists($sValue, $aStyles)) {
|
||||
return $aStyles[$sValue];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param string|null $sValue
|
||||
*
|
||||
* @return ormStyle|null
|
||||
*/
|
||||
public function GetStyle(?string $sValue): ?ormStyle
|
||||
{
|
||||
if ($this->IsParam('styled_values')) {
|
||||
$aStyles = $this->Get('styled_values');
|
||||
if (array_key_exists($sValue, $aStyles)) {
|
||||
return $aStyles[$sValue];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->IsParam('default_style')) {
|
||||
return $this->Get('default_style');
|
||||
}
|
||||
if ($this->IsParam('default_style')) {
|
||||
return $this->Get('default_style');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
// Get the definition of the column, including the actual values present in the table
|
||||
return $this->GetSQLColHelper($bFullSpec, true);
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
// Get the definition of the column, including the actual values present in the table
|
||||
return $this->GetSQLColHelper($bFullSpec, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A more versatile version of GetSQLCol
|
||||
* @param bool $bFullSpec
|
||||
* @param bool $bIncludeActualValues
|
||||
* @param string $sSQLTableName The table where to look for the actual values (may be useful for data synchro tables)
|
||||
* @return string
|
||||
* @since 3.0.0
|
||||
*/
|
||||
protected function GetSQLColHelper($bFullSpec = false, $bIncludeActualValues = false, $sSQLTableName = null)
|
||||
{
|
||||
$oValDef = $this->GetValuesDef();
|
||||
if ($oValDef) {
|
||||
$aValues = CMDBSource::Quote(array_keys($oValDef->GetValues(array(), "")), true);
|
||||
} else {
|
||||
$aValues = array();
|
||||
}
|
||||
/**
|
||||
* A more versatile version of GetSQLCol
|
||||
*
|
||||
* @param bool $bFullSpec
|
||||
* @param bool $bIncludeActualValues
|
||||
* @param string $sSQLTableName The table where to look for the actual values (may be useful for data synchro tables)
|
||||
*
|
||||
* @return string
|
||||
* @since 3.0.0
|
||||
*/
|
||||
protected function GetSQLColHelper($bFullSpec = false, $bIncludeActualValues = false, $sSQLTableName = null)
|
||||
{
|
||||
$oValDef = $this->GetValuesDef();
|
||||
if ($oValDef) {
|
||||
$aValues = CMDBSource::Quote(array_keys($oValDef->GetValues(array(), "")), true);
|
||||
} else {
|
||||
$aValues = array();
|
||||
}
|
||||
|
||||
// Preserve the values already present in the database to ease migrations
|
||||
if ($bIncludeActualValues) {
|
||||
if ($sSQLTableName == null) {
|
||||
// No SQL table given, use the one of the attribute
|
||||
$sHostClass = $this->GetHostClass();
|
||||
$sSQLTableName = MetaModel::DBGetTable($sHostClass, $this->GetCode());
|
||||
}
|
||||
$aValues = array_unique(array_merge($aValues, $this->GetActualValuesInDB($sSQLTableName)));
|
||||
}
|
||||
// Preserve the values already present in the database to ease migrations
|
||||
if ($bIncludeActualValues) {
|
||||
if ($sSQLTableName == null) {
|
||||
// No SQL table given, use the one of the attribute
|
||||
$sHostClass = $this->GetHostClass();
|
||||
$sSQLTableName = MetaModel::DBGetTable($sHostClass, $this->GetCode());
|
||||
}
|
||||
$aValues = array_unique(array_merge($aValues, $this->GetActualValuesInDB($sSQLTableName)));
|
||||
}
|
||||
|
||||
if (count($aValues) > 0) {
|
||||
// The syntax used here do matters
|
||||
// In particular, I had to remove unnecessary spaces to
|
||||
// make sure that this string will match the field type returned by the DB
|
||||
// (used to perform a comparison between the current DB format and the data model)
|
||||
return "ENUM(" . implode(",", $aValues) . ")"
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
} else {
|
||||
return "VARCHAR(255)"
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? " DEFAULT ''" : ""); // ENUM() is not an allowed syntax!
|
||||
}
|
||||
}
|
||||
if (count($aValues) > 0) {
|
||||
// The syntax used here do matters
|
||||
// In particular, I had to remove unnecessary spaces to
|
||||
// make sure that this string will match the field type returned by the DB
|
||||
// (used to perform a comparison between the current DB format and the data model)
|
||||
return "ENUM(".implode(",", $aValues).")"
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
} else {
|
||||
return "VARCHAR(255)"
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? " DEFAULT ''" : ""); // ENUM() is not an allowed syntax!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.0.0
|
||||
* {@inheritDoc}
|
||||
* @see AttributeDefinition::GetImportColumns()
|
||||
*/
|
||||
public function GetImportColumns()
|
||||
{
|
||||
// Note: this is used by the Data Synchro to build the "data" table
|
||||
// Right now the function is not passed the "target" SQL table, but if we improve this in the future
|
||||
// we may call $this->GetSQLColHelper(true, true, $sDBTable); to take into account the actual 'enum' values
|
||||
// in this table
|
||||
return array($this->GetCode() => $this->GetSQLColHelper(false, false));
|
||||
}
|
||||
/**
|
||||
* @see AttributeDefinition::GetImportColumns()
|
||||
* @since 3.0.0
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function GetImportColumns()
|
||||
{
|
||||
// Note: this is used by the Data Synchro to build the "data" table
|
||||
// Right now the function is not passed the "target" SQL table, but if we improve this in the future
|
||||
// we may call $this->GetSQLColHelper(true, true, $sDBTable); to take into account the actual 'enum' values
|
||||
// in this table
|
||||
return array($this->GetCode() => $this->GetSQLColHelper(false, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of the actual 'enum' values present in the database
|
||||
* @return string[]
|
||||
* @since 3.0.0
|
||||
*/
|
||||
protected function GetActualValuesInDB(string $sDBTable)
|
||||
{
|
||||
$aValues = array();
|
||||
try {
|
||||
$sSQL = "SELECT DISTINCT `" . $this->GetSQLExpr() . "` AS value FROM `$sDBTable`;";
|
||||
$aValuesInDB = CMDBSource::QueryToArray($sSQL);
|
||||
foreach ($aValuesInDB as $aRow) {
|
||||
if ($aRow['value'] !== null) {
|
||||
$aValues[] = $aRow['value'];
|
||||
}
|
||||
}
|
||||
} catch (MySQLException $e) {
|
||||
// Never mind, maybe the table does not exist yet (new installation from scratch)
|
||||
// It seems more efficient to try and ignore errors than to test if the table & column really exists
|
||||
}
|
||||
return CMDBSource::Quote($aValues);
|
||||
}
|
||||
/**
|
||||
* Get the list of the actual 'enum' values present in the database
|
||||
*
|
||||
* @return string[]
|
||||
* @since 3.0.0
|
||||
*/
|
||||
protected function GetActualValuesInDB(string $sDBTable)
|
||||
{
|
||||
$aValues = array();
|
||||
try {
|
||||
$sSQL = "SELECT DISTINCT `".$this->GetSQLExpr()."` AS value FROM `$sDBTable`;";
|
||||
$aValuesInDB = CMDBSource::QueryToArray($sSQL);
|
||||
foreach ($aValuesInDB as $aRow) {
|
||||
if ($aRow['value'] !== null) {
|
||||
$aValues[] = $aRow['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySQLException $e) {
|
||||
// Never mind, maybe the table does not exist yet (new installation from scratch)
|
||||
// It seems more efficient to try and ignore errors than to test if the table & column really exists
|
||||
}
|
||||
|
||||
protected function GetSQLColSpec()
|
||||
{
|
||||
$default = $this->ScalarToSQL($this->GetDefaultValue());
|
||||
if (is_null($default)) {
|
||||
$sRet = '';
|
||||
} else {
|
||||
// ENUMs values are strings so the default value must be a string as well,
|
||||
// otherwise MySQL interprets the number as the zero-based index of the value in the list (i.e. the nth value in the list)
|
||||
$sRet = " DEFAULT " . CMDBSource::Quote($default);
|
||||
}
|
||||
return CMDBSource::Quote($aValues);
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
protected function GetSQLColSpec()
|
||||
{
|
||||
$default = $this->ScalarToSQL($this->GetDefaultValue());
|
||||
if (is_null($default)) {
|
||||
$sRet = '';
|
||||
} else {
|
||||
// ENUMs values are strings so the default value must be a string as well,
|
||||
// otherwise MySQL interprets the number as the zero-based index of the value in the list (i.e. the nth value in the list)
|
||||
$sRet = " DEFAULT ".CMDBSource::Quote($default);
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
// Note: for strings, the null value is an empty string and it is recorded as such in the DB
|
||||
// but that wasn't working for enums, because '' is NOT one of the allowed values
|
||||
// that's why a null value must be forced to a real null
|
||||
$value = parent::ScalarToSQL($value);
|
||||
if ($this->IsNull($value)) {
|
||||
return null;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
// Note: for strings, the null value is an empty string and it is recorded as such in the DB
|
||||
// but that wasn't working for enums, because '' is NOT one of the allowed values
|
||||
// that's why a null value must be forced to a real null
|
||||
$value = parent::ScalarToSQL($value);
|
||||
if ($this->IsNull($value)) {
|
||||
return null;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return parent::GetBasicFilterSQLExpr($sOpCode, $value);
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sLabel = Dict::S('Class:' . $this->GetHostClass() . '/Attribute:' . $this->GetCode() . '/Value:' . $sValue,
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sValue, null, true /*user lang*/);
|
||||
if (is_null($sLabel)) {
|
||||
$sDefault = str_replace('_', ' ', $sValue);
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sValue, $sDefault, false);
|
||||
}
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return parent::GetBasicFilterSQLExpr($sOpCode, $value);
|
||||
}
|
||||
|
||||
return $sLabel;
|
||||
}
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sLabel = Dict::S('Class:'.$this->GetHostClass().'/Attribute:'.$this->GetCode().'/Value:'.$sValue,
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, true /*user lang*/);
|
||||
if (is_null($sLabel)) {
|
||||
$sDefault = str_replace('_', ' ', $sValue);
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, $sDefault, false);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetValueDescription($sValue)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sDescription = Dict::S('Class:' . $this->GetHostClass() . '/Attribute:' . $this->GetCode() . '/Value:' . $sValue . '+',
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sDescription = Dict::S('Class:' . $this->GetHostClass() . '/Attribute:' . $this->GetCode() . '/Value:' . $sValue . '+',
|
||||
'', true /* user language only */);
|
||||
if (strlen($sDescription) == 0) {
|
||||
$sParentClass = MetaModel::GetParentClass($this->m_sHostClass);
|
||||
if ($sParentClass) {
|
||||
if (MetaModel::IsValidAttCode($sParentClass, $this->m_sCode)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sParentClass, $this->m_sCode);
|
||||
$sDescription = $oAttDef->GetValueDescription($sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
return $sDescription;
|
||||
}
|
||||
public function GetValueDescription($sValue)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sDescription = Dict::S('Class:'.$this->GetHostClass().'/Attribute:'.$this->GetCode().'/Value:'.$sValue.'+',
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sDescription = Dict::S('Class:'.$this->GetHostClass().'/Attribute:'.$this->GetCode().'/Value:'.$sValue.'+',
|
||||
'', true /* user language only */);
|
||||
if (strlen($sDescription) == 0) {
|
||||
$sParentClass = MetaModel::GetParentClass($this->m_sHostClass);
|
||||
if ($sParentClass) {
|
||||
if (MetaModel::IsValidAttCode($sParentClass, $this->m_sCode)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sParentClass, $this->m_sCode);
|
||||
$sDescription = $oAttDef->GetValueDescription($sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($bLocalize) {
|
||||
$sLabel = $this->GetValueLabel($sValue);
|
||||
// $sDescription = $this->GetValueDescription($sValue);
|
||||
$oStyle = $this->GetStyle($sValue);
|
||||
// later, we could imagine a detailed description in the title
|
||||
// $sRes = "<span title=\"$sDescription\">".parent::GetAsHtml($sLabel)."</span>";
|
||||
$oBadge = \Combodo\iTop\Application\UI\Base\Component\FieldBadge\FieldBadgeUIBlockFactory::MakeForField($sLabel, $oStyle);
|
||||
$oRenderer = new \Combodo\iTop\Renderer\BlockRenderer($oBadge);
|
||||
$sRes = $oRenderer->RenderHtml();
|
||||
} else {
|
||||
$sRes = parent::GetAsHtml($sValue, $oHostObject, $bLocalize);
|
||||
}
|
||||
return $sDescription;
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($bLocalize) {
|
||||
$sLabel = $this->GetValueLabel($sValue);
|
||||
// $sDescription = $this->GetValueDescription($sValue);
|
||||
$oStyle = $this->GetStyle($sValue);
|
||||
// later, we could imagine a detailed description in the title
|
||||
// $sRes = "<span title=\"$sDescription\">".parent::GetAsHtml($sLabel)."</span>";
|
||||
$oBadge = FieldBadgeUIBlockFactory::MakeForField($sLabel, $oStyle);
|
||||
$oRenderer = new BlockRenderer($oBadge);
|
||||
$sRes = $oRenderer->RenderHtml();
|
||||
} else {
|
||||
$sRes = parent::GetAsHtml($sValue, $oHostObject, $bLocalize);
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($value);
|
||||
} else {
|
||||
$sFinalValue = $value;
|
||||
}
|
||||
$sRes = parent::GetAsXML($sFinalValue, $oHostObject, $bLocalize);
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($value);
|
||||
} else {
|
||||
$sFinalValue = $value;
|
||||
}
|
||||
$sRes = parent::GetAsXML($sFinalValue, $oHostObject, $bLocalize);
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($sValue);
|
||||
} else {
|
||||
$sFinalValue = $sValue;
|
||||
}
|
||||
$sRes = parent::GetAsCSV($sFinalValue, $sSeparator, $sTextQualifier, $oHostObject, $bLocalize);
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
$sFinalValue = '';
|
||||
} elseif ($bLocalize) {
|
||||
$sFinalValue = $this->GetValueLabel($sValue);
|
||||
} else {
|
||||
$sFinalValue = $sValue;
|
||||
}
|
||||
$sRes = parent::GetAsCSV($sFinalValue, $sSeparator, $sTextQualifier, $oHostObject, $bLocalize);
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SelectField';
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
// Later : We should check $this->Get('display_style') and create a Radio / Select / ... regarding its value
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SelectField';
|
||||
}
|
||||
|
||||
$oFormField->SetChoices($this->GetAllowedValues($oObject->ToArgsForQuery()));
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
// Later : We should check $this->Get('display_style') and create a Radio / Select / ... regarding its value
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
$oFormField->SetChoices($this->GetAllowedValues($oObject->ToArgsForQuery()));
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
return '';
|
||||
} else {
|
||||
return $this->GetValueLabel($sValue);
|
||||
}
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
return '';
|
||||
} else {
|
||||
return $this->GetValueLabel($sValue);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$aRawValues = parent::GetAllowedValues($aArgs, $sContains);
|
||||
if (is_null($aRawValues)) {
|
||||
return null;
|
||||
}
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$aLocalizedValues[$sKey] = $this->GetValueLabel($sKey);
|
||||
}
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Sort by label only if necessary
|
||||
// See N°1646 and {@see \MFCompiler::CompileAttributeEnumValues()} for complete information as for why sort on labels is done at runtime while other sorting are done at compile time
|
||||
/** @var \ValueSetEnum $oValueSetDef */
|
||||
$oValueSetDef = $this->GetValuesDef();
|
||||
if ($oValueSetDef->IsSortedByValues()) {
|
||||
asort($aLocalizedValues);
|
||||
}
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$aRawValues = parent::GetAllowedValues($aArgs, $sContains);
|
||||
if (is_null($aRawValues)) {
|
||||
return null;
|
||||
}
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$aLocalizedValues[$sKey] = $this->GetValueLabel($sKey);
|
||||
}
|
||||
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
// Sort by label only if necessary
|
||||
// See N°1646 and {@see \MFCompiler::CompileAttributeEnumValues()} for complete information as for why sort on labels is done at runtime while other sorting are done at compile time
|
||||
/** @var \ValueSetEnum $oValueSetDef */
|
||||
$oValueSetDef = $this->GetValuesDef();
|
||||
if ($oValueSetDef->IsSortedByValues()) {
|
||||
asort($aLocalizedValues);
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* An enum can be localized
|
||||
*/
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
if ($bLocalizedValue) {
|
||||
// Lookup for the value matching the input
|
||||
//
|
||||
$sFoundValue = null;
|
||||
$aRawValues = parent::GetAllowedValues();
|
||||
if (!is_null($aRawValues)) {
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$sRefValue = $this->GetValueLabel($sKey);
|
||||
if ($sProposedValue == $sRefValue) {
|
||||
$sFoundValue = $sKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($sFoundValue)) {
|
||||
return null;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->MakeRealValue($sFoundValue, null);
|
||||
} else {
|
||||
return parent::MakeValueFromString($sProposedValue, $bLocalizedValue, $sSepItem, $sSepAttribute, $sSepValue,
|
||||
$sAttributeQualifier);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* An enum can be localized
|
||||
*/
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
if ($bLocalizedValue) {
|
||||
// Lookup for the value matching the input
|
||||
//
|
||||
$sFoundValue = null;
|
||||
$aRawValues = parent::GetAllowedValues();
|
||||
if (!is_null($aRawValues)) {
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$sRefValue = $this->GetValueLabel($sKey);
|
||||
if ($sProposedValue == $sRefValue) {
|
||||
$sFoundValue = $sKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($sFoundValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the input value to align it with the values supported
|
||||
* by this type of attribute. In this case: turns empty strings into nulls
|
||||
*
|
||||
* @param mixed $proposedValue The value to be set for the attribute
|
||||
*
|
||||
* @return mixed The actual value that will be set
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if ($proposedValue == '') {
|
||||
return null;
|
||||
}
|
||||
return $this->MakeRealValue($sFoundValue, null);
|
||||
} else {
|
||||
return parent::MakeValueFromString($sProposedValue, $bLocalizedValue, $sSepItem, $sSepAttribute, $sSepValue,
|
||||
$sAttributeQualifier);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::MakeRealValue($proposedValue, $oHostObj);
|
||||
}
|
||||
/**
|
||||
* Processes the input value to align it with the values supported
|
||||
* by this type of attribute. In this case: turns empty strings into nulls
|
||||
*
|
||||
* @param mixed $proposedValue The value to be set for the attribute
|
||||
*
|
||||
* @return mixed The actual value that will be set
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if ($proposedValue == '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetOrderByHint()
|
||||
{
|
||||
$aValues = $this->GetAllowedValues();
|
||||
return parent::MakeRealValue($proposedValue, $oHostObj);
|
||||
}
|
||||
|
||||
return Dict::Format('UI:OrderByHint_Values', implode(', ', $aValues));
|
||||
}
|
||||
public function GetOrderByHint()
|
||||
{
|
||||
$aValues = $this->GetAllowedValues();
|
||||
|
||||
return Dict::Format('UI:OrderByHint_Values', implode(', ', $aValues));
|
||||
}
|
||||
}
|
||||
@@ -1,230 +1,243 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use ormSet;
|
||||
use ValueSetEnumPadded;
|
||||
|
||||
/**
|
||||
* @since 2.7.0 N°985
|
||||
*/
|
||||
class AttributeEnumSet extends AttributeSet
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_TAG_SET;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_TAG_SET;
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('possible_values', 'is_null_allowed', 'max_items'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('possible_values', 'is_null_allowed', 'max_items'));
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
$aRawValues = $this->GetRawPossibleValues();
|
||||
$iMaxItems = $this->GetMaxItems();
|
||||
$aLengths = array();
|
||||
foreach (array_keys($aRawValues) as $sKey) {
|
||||
$aLengths[] = strlen($sKey);
|
||||
}
|
||||
rsort($aLengths, SORT_NUMERIC);
|
||||
$iMaxSize = 2;
|
||||
for ($i = 0; $i < min($iMaxItems, count($aLengths)); $i++) {
|
||||
$iMaxSize += $aLengths[$i] + 1;
|
||||
}
|
||||
return max(255, $iMaxSize);
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
$aRawValues = $this->GetRawPossibleValues();
|
||||
$iMaxItems = $this->GetMaxItems();
|
||||
$aLengths = array();
|
||||
foreach (array_keys($aRawValues) as $sKey) {
|
||||
$aLengths[] = strlen($sKey);
|
||||
}
|
||||
rsort($aLengths, SORT_NUMERIC);
|
||||
$iMaxSize = 2;
|
||||
for ($i = 0; $i < min($iMaxItems, count($aLengths)); $i++) {
|
||||
$iMaxSize += $aLengths[$i] + 1;
|
||||
}
|
||||
|
||||
private function GetRawPossibleValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
/** @var ValueSetEnumPadded $oValSetDef */
|
||||
$oValSetDef = $this->Get('possible_values');
|
||||
if (!$oValSetDef) {
|
||||
return array();
|
||||
}
|
||||
return max(255, $iMaxSize);
|
||||
}
|
||||
|
||||
return $oValSetDef->GetValues($aArgs, $sContains);
|
||||
}
|
||||
private function GetRawPossibleValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
/** @var ValueSetEnumPadded $oValSetDef */
|
||||
$oValSetDef = $this->Get('possible_values');
|
||||
if (!$oValSetDef) {
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetPossibleValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$aRawValues = $this->GetRawPossibleValues($aArgs, $sContains);
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$aLocalizedValues[$sKey] = $this->GetValueLabel($sKey);
|
||||
}
|
||||
return $oValSetDef->GetValues($aArgs, $sContains);
|
||||
}
|
||||
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
public function GetPossibleValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$aRawValues = $this->GetRawPossibleValues($aArgs, $sContains);
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$aLocalizedValues[$sKey] = $this->GetValueLabel($sKey);
|
||||
}
|
||||
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if ($sValue instanceof ormSet) {
|
||||
$sValue = implode(', ', $sValue->GetValues());
|
||||
}
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
|
||||
$aValues = $this->GetRawPossibleValues();
|
||||
if (is_array($aValues) && is_string($sValue) && isset($aValues[$sValue])) {
|
||||
$sValue = $aValues[$sValue];
|
||||
}
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if ($sValue instanceof ormSet) {
|
||||
$sValue = implode(', ', $sValue->GetValues());
|
||||
}
|
||||
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sLabel = Dict::S('Class:' . $this->GetHostClass() . '/Attribute:' . $this->GetCode() . '/Value:' . $sValue,
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sValue, null, true /*user lang*/);
|
||||
if (is_null($sLabel)) {
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sValue, null, false);
|
||||
if (is_null($sLabel)) {
|
||||
$sDefault = trim(str_replace('_', ' ', $sValue));
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/Value:' . $sDefault, $sDefault, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
$aValues = $this->GetRawPossibleValues();
|
||||
if (is_array($aValues) && is_string($sValue) && isset($aValues[$sValue])) {
|
||||
$sValue = $aValues[$sValue];
|
||||
}
|
||||
|
||||
return $sLabel;
|
||||
}
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sLabel = Dict::S('Class:'.$this->GetHostClass().'/Attribute:'.$this->GetCode().'/Value:'.$sValue,
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, true /*user lang*/);
|
||||
if (is_null($sLabel)) {
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, false);
|
||||
if (is_null($sLabel)) {
|
||||
$sDefault = trim(str_replace('_', ' ', $sValue));
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sDefault, $sDefault, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function GetValueDescription($sValue)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sDescription = Dict::S('Class:' . $this->GetHostClass() . '/Attribute:' . $this->GetCode() . '/Value:' . $sValue . '+',
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sDescription = Dict::S('Class:' . $this->GetHostClass() . '/Attribute:' . $this->GetCode() . '/Value:' . $sValue . '+',
|
||||
'', true /* user language only */);
|
||||
if (strlen($sDescription) == 0) {
|
||||
$sParentClass = MetaModel::GetParentClass($this->m_sHostClass);
|
||||
if ($sParentClass) {
|
||||
if (MetaModel::IsValidAttCode($sParentClass, $this->m_sCode)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sParentClass, $this->m_sCode);
|
||||
$sDescription = $oAttDef->GetValueDescription($sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
return $sDescription;
|
||||
}
|
||||
public function GetValueDescription($sValue)
|
||||
{
|
||||
if (is_null($sValue)) {
|
||||
// Unless a specific label is defined for the null value of this enum, use a generic "undefined" label
|
||||
$sDescription = Dict::S('Class:'.$this->GetHostClass().'/Attribute:'.$this->GetCode().'/Value:'.$sValue.'+',
|
||||
Dict::S('Enum:Undefined'));
|
||||
} else {
|
||||
$sDescription = Dict::S('Class:'.$this->GetHostClass().'/Attribute:'.$this->GetCode().'/Value:'.$sValue.'+',
|
||||
'', true /* user language only */);
|
||||
if (strlen($sDescription) == 0) {
|
||||
$sParentClass = MetaModel::GetParentClass($this->m_sHostClass);
|
||||
if ($sParentClass) {
|
||||
if (MetaModel::IsValidAttCode($sParentClass, $this->m_sCode)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sParentClass, $this->m_sCode);
|
||||
$sDescription = $oAttDef->GetValueDescription($sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($bLocalize) {
|
||||
if ($value instanceof ormSet) {
|
||||
$sRes = $this->GenerateViewHtmlForValues($value->GetValues());
|
||||
} else {
|
||||
$sLabel = $this->GetValueLabel($value);
|
||||
$sDescription = $this->GetValueDescription($value);
|
||||
$sRes = "<span title=\"$sDescription\">" . parent::GetAsHtml($sLabel) . "</span>";
|
||||
}
|
||||
} else {
|
||||
$sRes = parent::GetAsHtml($value, $oHostObject, $bLocalize);
|
||||
}
|
||||
return $sDescription;
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($bLocalize) {
|
||||
if ($value instanceof ormSet) {
|
||||
$sRes = $this->GenerateViewHtmlForValues($value->GetValues());
|
||||
} else {
|
||||
$sLabel = $this->GetValueLabel($value);
|
||||
$sDescription = $this->GetValueDescription($value);
|
||||
$sRes = "<span title=\"$sDescription\">".parent::GetAsHtml($sLabel)."</span>";
|
||||
}
|
||||
} else {
|
||||
$sRes = parent::GetAsHtml($value, $oHostObject, $bLocalize);
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ormSet $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return mixed|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true, $bConvertToPlainText = false)
|
||||
{
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
if (is_object($value) && ($value instanceof ormSet)) {
|
||||
$aValues = $value->GetValues();
|
||||
if ($bLocalize) {
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aValues as $sValue) {
|
||||
$aLocalizedValues[] = $this->GetValueLabel($sValue);
|
||||
}
|
||||
$aValues = $aLocalizedValues;
|
||||
}
|
||||
$sRes = implode($sSepItem, $aValues);
|
||||
} else {
|
||||
$sRes = '';
|
||||
}
|
||||
/**
|
||||
* @param ormSet $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return mixed|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true, $bConvertToPlainText = false)
|
||||
{
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
if (is_object($value) && ($value instanceof ormSet)) {
|
||||
$aValues = $value->GetValues();
|
||||
if ($bLocalize) {
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aValues as $sValue) {
|
||||
$aLocalizedValues[] = $this->GetValueLabel($sValue);
|
||||
}
|
||||
$aValues = $aLocalizedValues;
|
||||
}
|
||||
$sRes = implode($sSepItem, $aValues);
|
||||
} else {
|
||||
$sRes = '';
|
||||
}
|
||||
|
||||
return "{$sTextQualifier}{$sRes}{$sTextQualifier}";
|
||||
}
|
||||
return "{$sTextQualifier}{$sRes}{$sTextQualifier}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value from a given string (plain text, CSV import)
|
||||
*
|
||||
* @param string $sProposedValue
|
||||
* @param bool $bLocalizedValue
|
||||
* @param string $sSepItem
|
||||
* @param string $sSepAttribute
|
||||
* @param string $sSepValue
|
||||
* @param string $sAttributeQualifier
|
||||
*
|
||||
* @return mixed null if no match could be found
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function MakeValueFromString($sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null, $sAttributeQualifier = null)
|
||||
{
|
||||
if ($bLocalizedValue) {
|
||||
// Lookup for the values matching the input
|
||||
//
|
||||
$aValues = $this->FromStringToArray($sProposedValue);
|
||||
$aFoundValues = array();
|
||||
$aRawValues = $this->GetPossibleValues();
|
||||
foreach ($aValues as $sValue) {
|
||||
$bFound = false;
|
||||
foreach ($aRawValues as $sCode => $sRawValue) {
|
||||
if ($sValue == $sRawValue) {
|
||||
$aFoundValues[] = $sCode;
|
||||
$bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$bFound) {
|
||||
// Not found, break the import
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the value from a given string (plain text, CSV import)
|
||||
*
|
||||
* @param string $sProposedValue
|
||||
* @param bool $bLocalizedValue
|
||||
* @param string $sSepItem
|
||||
* @param string $sSepAttribute
|
||||
* @param string $sSepValue
|
||||
* @param string $sAttributeQualifier
|
||||
*
|
||||
* @return mixed null if no match could be found
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MakeValueFromString($sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null, $sAttributeQualifier = null)
|
||||
{
|
||||
if ($bLocalizedValue) {
|
||||
// Lookup for the values matching the input
|
||||
//
|
||||
$aValues = $this->FromStringToArray($sProposedValue);
|
||||
$aFoundValues = array();
|
||||
$aRawValues = $this->GetPossibleValues();
|
||||
foreach ($aValues as $sValue) {
|
||||
$bFound = false;
|
||||
foreach ($aRawValues as $sCode => $sRawValue) {
|
||||
if ($sValue == $sRawValue) {
|
||||
$aFoundValues[] = $sCode;
|
||||
$bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$bFound) {
|
||||
// Not found, break the import
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->MakeRealValue(implode(',', $aFoundValues), null);
|
||||
} else {
|
||||
return $this->MakeRealValue($sProposedValue, null, false);
|
||||
}
|
||||
}
|
||||
return $this->MakeRealValue(implode(',', $aFoundValues), null);
|
||||
} else {
|
||||
return $this->MakeRealValue($sProposedValue, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $proposedValue Search string used for MATCHES
|
||||
*
|
||||
* @param string $sDefaultSepItem word separator to extract items
|
||||
*
|
||||
* @return array of EnumSet codes
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function FromStringToArray($proposedValue, $sDefaultSepItem = ',')
|
||||
{
|
||||
$aValues = array();
|
||||
if (!empty($proposedValue)) {
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
// convert also other separators
|
||||
if ($sSepItem !== $sDefaultSepItem) {
|
||||
$proposedValue = str_replace($sDefaultSepItem, $sSepItem, $proposedValue);
|
||||
}
|
||||
foreach (explode($sSepItem, $proposedValue) as $sCode) {
|
||||
$sValue = trim($sCode);
|
||||
if (strlen($sValue) > 2) {
|
||||
$sLabel = $this->GetValueLabel($sValue);
|
||||
$aValues[$sLabel] = $sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
/**
|
||||
* @param string $proposedValue Search string used for MATCHES
|
||||
*
|
||||
* @param string $sDefaultSepItem word separator to extract items
|
||||
*
|
||||
* @return array of EnumSet codes
|
||||
* @throws Exception
|
||||
*/
|
||||
public function FromStringToArray($proposedValue, $sDefaultSepItem = ',')
|
||||
{
|
||||
$aValues = array();
|
||||
if (!empty($proposedValue)) {
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
// convert also other separators
|
||||
if ($sSepItem !== $sDefaultSepItem) {
|
||||
$proposedValue = str_replace($sDefaultSepItem, $sSepItem, $proposedValue);
|
||||
}
|
||||
foreach (explode($sSepItem, $proposedValue) as $sCode) {
|
||||
$sValue = trim($sCode);
|
||||
if (strlen($sValue) > 2) {
|
||||
$sLabel = $this->GetValueLabel($sValue);
|
||||
$aValues[$sLabel] = $sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function Equals($val1, $val2)
|
||||
{
|
||||
return $val1->Equals($val2);
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function Equals($val1, $val2)
|
||||
{
|
||||
return $val1->Equals($val2);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,20 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CoreException;
|
||||
use DBObject;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
use DBSearch;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use TemporaryObjectDescriptor;
|
||||
use ValueSetObjects;
|
||||
|
||||
/**
|
||||
* Map a foreign key to an attribute
|
||||
@@ -10,326 +26,329 @@
|
||||
*/
|
||||
class AttributeExternalKey extends AttributeDBFieldVoid
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_EXTERNAL_KEY;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_EXTERNAL_KEY;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the search widget type corresponding to this attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetSearchType()
|
||||
{
|
||||
try {
|
||||
$oRemoteAtt = $this->GetFinalAttDef();
|
||||
$sTargetClass = $oRemoteAtt->GetTargetClass();
|
||||
if (MetaModel::IsHierarchicalClass($sTargetClass)) {
|
||||
return self::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY;
|
||||
}
|
||||
/**
|
||||
* Return the search widget type corresponding to this attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetSearchType()
|
||||
{
|
||||
try {
|
||||
$oRemoteAtt = $this->GetFinalAttDef();
|
||||
$sTargetClass = $oRemoteAtt->GetTargetClass();
|
||||
if (MetaModel::IsHierarchicalClass($sTargetClass)) {
|
||||
return self::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY;
|
||||
}
|
||||
|
||||
return self::SEARCH_WIDGET_TYPE_EXTERNAL_KEY;
|
||||
} catch (CoreException $e) {
|
||||
}
|
||||
return self::SEARCH_WIDGET_TYPE_EXTERNAL_KEY;
|
||||
}
|
||||
catch (CoreException $e) {
|
||||
}
|
||||
|
||||
return self::SEARCH_WIDGET_TYPE_RAW;
|
||||
}
|
||||
return self::SEARCH_WIDGET_TYPE_RAW;
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("targetclass", "is_null_allowed", "on_target_delete"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("targetclass", "is_null_allowed", "on_target_delete"));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "ExtKey";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "ExtKey";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11)" . ($bFullSpec ? " DEFAULT 0" : "");
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11)".($bFullSpec ? " DEFAULT 0" : "");
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsExternalKey($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsExternalKey($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetTargetClass($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this->Get("targetclass");
|
||||
}
|
||||
public function GetTargetClass($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this->Get("targetclass");
|
||||
}
|
||||
|
||||
public function GetKeyAttDef($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
public function GetKeyAttDef($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetKeyAttCode()
|
||||
{
|
||||
return $this->GetCode();
|
||||
}
|
||||
public function GetKeyAttCode()
|
||||
{
|
||||
return $this->GetCode();
|
||||
}
|
||||
|
||||
public function GetDisplayStyle()
|
||||
{
|
||||
return $this->GetOptional('display_style', 'select');
|
||||
}
|
||||
public function GetDisplayStyle()
|
||||
{
|
||||
return $this->GetOptional('display_style', 'select');
|
||||
}
|
||||
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
if (MetaModel::GetConfig()->Get('disable_mandatory_ext_keys')) {
|
||||
return true;
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
if (MetaModel::GetConfig()->Get('disable_mandatory_ext_keys')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return parent::GetBasicFilterLooseOperator();
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return parent::GetBasicFilterLooseOperator();
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return parent::GetBasicFilterSQLExpr($sOpCode, $value);
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return parent::GetBasicFilterSQLExpr($sOpCode, $value);
|
||||
}
|
||||
|
||||
// overloaded here so that an ext key always have the answer to
|
||||
// "what are your possible values?"
|
||||
public function GetValuesDef()
|
||||
{
|
||||
$oValSetDef = $this->Get("allowed_values");
|
||||
if (!$oValSetDef) {
|
||||
// Let's propose every existing value
|
||||
$oValSetDef = new ValueSetObjects('SELECT ' . $this->GetTargetClass());
|
||||
}
|
||||
// overloaded here so that an ext key always have the answer to
|
||||
// "what are your possible values?"
|
||||
public function GetValuesDef()
|
||||
{
|
||||
$oValSetDef = $this->Get("allowed_values");
|
||||
if (!$oValSetDef) {
|
||||
// Let's propose every existing value
|
||||
$oValSetDef = new ValueSetObjects('SELECT '.$this->GetTargetClass());
|
||||
}
|
||||
|
||||
return $oValSetDef;
|
||||
}
|
||||
return $oValSetDef;
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
//throw new Exception("GetAllowedValues on ext key has been deprecated");
|
||||
try {
|
||||
return parent::GetAllowedValues($aArgs, $sContains);
|
||||
} catch (Exception $e) {
|
||||
// Some required arguments could not be found, enlarge to any existing value
|
||||
$oValSetDef = new ValueSetObjects('SELECT ' . $this->GetTargetClass());
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
//throw new Exception("GetAllowedValues on ext key has been deprecated");
|
||||
try {
|
||||
return parent::GetAllowedValues($aArgs, $sContains);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Some required arguments could not be found, enlarge to any existing value
|
||||
$oValSetDef = new ValueSetObjects('SELECT '.$this->GetTargetClass());
|
||||
|
||||
return $oValSetDef->GetValues($aArgs, $sContains);
|
||||
}
|
||||
}
|
||||
return $oValSetDef->GetValues($aArgs, $sContains);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAllowedValuesForSelect($aArgs = array(), $sContains = '')
|
||||
{
|
||||
//$this->GetValuesDef();
|
||||
$oValSetDef = new ValueSetObjects('SELECT ' . $this->GetTargetClass());
|
||||
return $oValSetDef->GetValuesForAutocomplete($aArgs, $sContains);
|
||||
}
|
||||
public function GetAllowedValuesForSelect($aArgs = array(), $sContains = '')
|
||||
{
|
||||
//$this->GetValuesDef();
|
||||
$oValSetDef = new ValueSetObjects('SELECT '.$this->GetTargetClass());
|
||||
|
||||
return $oValSetDef->GetValuesForAutocomplete($aArgs, $sContains);
|
||||
}
|
||||
|
||||
|
||||
public function GetAllowedValuesAsObjectSet($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
$oSet = $oValSetDef->ToObjectSet($aArgs, $sContains, $iAdditionalValue);
|
||||
public function GetAllowedValuesAsObjectSet($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
$oSet = $oValSetDef->ToObjectSet($aArgs, $sContains, $iAdditionalValue);
|
||||
|
||||
return $oSet;
|
||||
}
|
||||
return $oSet;
|
||||
}
|
||||
|
||||
public function GetAllowedValuesAsFilter($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
return DBObjectSearch::FromOQL($this->GetValuesDef()->GetFilterExpression());
|
||||
}
|
||||
public function GetAllowedValuesAsFilter($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
return DBObjectSearch::FromOQL($this->GetValuesDef()->GetFilterExpression());
|
||||
}
|
||||
|
||||
public function GetDeletionPropagationOption()
|
||||
{
|
||||
return $this->Get("on_target_delete");
|
||||
}
|
||||
public function GetDeletionPropagationOption()
|
||||
{
|
||||
return $this->Get("on_target_delete");
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == 0);
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return ((int)$proposedValue) !== 0;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return ((int)$proposedValue) !== 0;
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return 0;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return 0;
|
||||
}
|
||||
if (MetaModel::IsValidObject($proposedValue)) {
|
||||
return $proposedValue->GetKey();
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return 0;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return 0;
|
||||
}
|
||||
if (MetaModel::IsValidObject($proposedValue)) {
|
||||
return $proposedValue->GetKey();
|
||||
}
|
||||
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
|
||||
/** @inheritdoc @since 3.1 */
|
||||
public function WriteExternalValues(DBObject $oHostObject): void
|
||||
{
|
||||
$sTargetKey = $oHostObject->Get($this->GetCode());
|
||||
$oFilter = DBSearch::FromOQL('SELECT `' . TemporaryObjectDescriptor::class . '` WHERE item_class=:class AND item_id=:id');
|
||||
$oSet = new DBObjectSet($oFilter, [], ['class' => $this->GetTargetClass(), 'id' => $sTargetKey]);
|
||||
while ($oTemporaryObjectDescriptor = $oSet->Fetch()) {
|
||||
$oTemporaryObjectDescriptor->Set('host_class', get_class($oHostObject));
|
||||
$oTemporaryObjectDescriptor->Set('host_id', $oHostObject->GetKey());
|
||||
$oTemporaryObjectDescriptor->Set('host_att_code', $this->GetCode());
|
||||
$oTemporaryObjectDescriptor->DBUpdate();
|
||||
}
|
||||
}
|
||||
/** @inheritdoc @since 3.1 */
|
||||
public function WriteExternalValues(DBObject $oHostObject): void
|
||||
{
|
||||
$sTargetKey = $oHostObject->Get($this->GetCode());
|
||||
$oFilter = DBSearch::FromOQL('SELECT `'.TemporaryObjectDescriptor::class.'` WHERE item_class=:class AND item_id=:id');
|
||||
$oSet = new DBObjectSet($oFilter, [], ['class' => $this->GetTargetClass(), 'id' => $sTargetKey]);
|
||||
while ($oTemporaryObjectDescriptor = $oSet->Fetch()) {
|
||||
$oTemporaryObjectDescriptor->Set('host_class', get_class($oHostObject));
|
||||
$oTemporaryObjectDescriptor->Set('host_id', $oHostObject->GetKey());
|
||||
$oTemporaryObjectDescriptor->Set('host_att_code', $this->GetCode());
|
||||
$oTemporaryObjectDescriptor->DBUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public function GetMaximumComboLength()
|
||||
{
|
||||
return $this->GetOptional('max_combo_length', MetaModel::GetConfig()->Get('max_combo_length'));
|
||||
}
|
||||
public function GetMaximumComboLength()
|
||||
{
|
||||
return $this->GetOptional('max_combo_length', MetaModel::GetConfig()->Get('max_combo_length'));
|
||||
}
|
||||
|
||||
public function GetMinAutoCompleteChars()
|
||||
{
|
||||
return $this->GetOptional('min_autocomplete_chars', MetaModel::GetConfig()->Get('min_autocomplete_chars'));
|
||||
}
|
||||
public function GetMinAutoCompleteChars()
|
||||
{
|
||||
return $this->GetOptional('min_autocomplete_chars', MetaModel::GetConfig()->Get('min_autocomplete_chars'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function GetMaxAutoCompleteResults(): int
|
||||
{
|
||||
return MetaModel::GetConfig()->Get('max_autocomplete_results');
|
||||
}
|
||||
/**
|
||||
* @return int
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function GetMaxAutoCompleteResults(): int
|
||||
{
|
||||
return MetaModel::GetConfig()->Get('max_autocomplete_results');
|
||||
}
|
||||
|
||||
public function AllowTargetCreation()
|
||||
{
|
||||
return $this->GetOptional('allow_target_creation', MetaModel::GetConfig()->Get('allow_target_creation'));
|
||||
}
|
||||
public function AllowTargetCreation()
|
||||
{
|
||||
return $this->GetOptional('allow_target_creation', MetaModel::GetConfig()->Get('allow_target_creation'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the corresponding "link" attribute on the target class, if any
|
||||
*
|
||||
* @return null | AttributeDefinition
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetMirrorLinkAttribute()
|
||||
{
|
||||
$oRet = null;
|
||||
$sRemoteClass = $this->GetTargetClass();
|
||||
foreach (MetaModel::ListAttributeDefs($sRemoteClass) as $sRemoteAttCode => $oRemoteAttDef) {
|
||||
if (!$oRemoteAttDef->IsLinkSet()) {
|
||||
continue;
|
||||
}
|
||||
if (!is_subclass_of($this->GetHostClass(),
|
||||
$oRemoteAttDef->GetLinkedClass()) && $oRemoteAttDef->GetLinkedClass() != $this->GetHostClass()) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetExtKeyToMe() != $this->GetCode()) {
|
||||
continue;
|
||||
}
|
||||
$oRet = $oRemoteAttDef;
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* Find the corresponding "link" attribute on the target class, if any
|
||||
*
|
||||
* @return null | AttributeDefinition
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetMirrorLinkAttribute()
|
||||
{
|
||||
$oRet = null;
|
||||
$sRemoteClass = $this->GetTargetClass();
|
||||
foreach (MetaModel::ListAttributeDefs($sRemoteClass) as $sRemoteAttCode => $oRemoteAttDef) {
|
||||
if (!$oRemoteAttDef->IsLinkSet()) {
|
||||
continue;
|
||||
}
|
||||
if (!is_subclass_of($this->GetHostClass(),
|
||||
$oRemoteAttDef->GetLinkedClass()) && $oRemoteAttDef->GetLinkedClass() != $this->GetHostClass()) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetExtKeyToMe() != $this->GetCode()) {
|
||||
continue;
|
||||
}
|
||||
$oRet = $oRemoteAttDef;
|
||||
break;
|
||||
}
|
||||
|
||||
return $oRet;
|
||||
}
|
||||
return $oRet;
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SelectObjectField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SelectObjectField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
/** @var \Combodo\iTop\Form\Field\Field $oFormField */
|
||||
if ($oFormField === null) {
|
||||
// Later : We should check $this->Get('display_style') and create a Radio / Select / ... regarding its value
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
/** @var \Combodo\iTop\Form\Field\Field $oFormField */
|
||||
if ($oFormField === null) {
|
||||
// Later : We should check $this->Get('display_style') and create a Radio / Select / ... regarding its value
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
|
||||
// Setting params
|
||||
$oFormField->SetMaximumComboLength($this->GetMaximumComboLength());
|
||||
$oFormField->SetMinAutoCompleteChars($this->GetMinAutoCompleteChars());
|
||||
$oFormField->SetMaxAutoCompleteResults($this->GetMaxAutoCompleteResults());
|
||||
$oFormField->SetHierarchical(MetaModel::IsHierarchicalClass($this->GetTargetClass()));
|
||||
// Setting choices regarding the field dependencies
|
||||
$aFieldDependencies = $this->GetPrerequisiteAttributes();
|
||||
if (!empty($aFieldDependencies)) {
|
||||
$oTmpAttDef = $this;
|
||||
$oTmpField = $oFormField;
|
||||
$oFormField->SetOnFinalizeCallback(function () use ($oTmpField, $oTmpAttDef, $oObject) {
|
||||
/** @var $oTmpField \Combodo\iTop\Form\Field\Field */
|
||||
/** @var $oTmpAttDef \AttributeDefinition */
|
||||
/** @var $oObject \DBObject */
|
||||
// Setting params
|
||||
$oFormField->SetMaximumComboLength($this->GetMaximumComboLength());
|
||||
$oFormField->SetMinAutoCompleteChars($this->GetMinAutoCompleteChars());
|
||||
$oFormField->SetMaxAutoCompleteResults($this->GetMaxAutoCompleteResults());
|
||||
$oFormField->SetHierarchical(MetaModel::IsHierarchicalClass($this->GetTargetClass()));
|
||||
// Setting choices regarding the field dependencies
|
||||
$aFieldDependencies = $this->GetPrerequisiteAttributes();
|
||||
if (!empty($aFieldDependencies)) {
|
||||
$oTmpAttDef = $this;
|
||||
$oTmpField = $oFormField;
|
||||
$oFormField->SetOnFinalizeCallback(function () use ($oTmpField, $oTmpAttDef, $oObject) {
|
||||
/** @var $oTmpField \Combodo\iTop\Form\Field\Field */
|
||||
/** @var $oTmpAttDef \AttributeDefinition */
|
||||
/** @var $oObject \DBObject */
|
||||
|
||||
// We set search object only if it has not already been set (overrided)
|
||||
if ($oTmpField->GetSearch() === null) {
|
||||
$oSearch = DBSearch::FromOQL($oTmpAttDef->GetValuesDef()->GetFilterExpression());
|
||||
$oSearch->SetInternalParams(array('this' => $oObject));
|
||||
$oTmpField->SetSearch($oSearch);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$oSearch = DBSearch::FromOQL($this->GetValuesDef()->GetFilterExpression());
|
||||
$oSearch->SetInternalParams(array('this' => $oObject));
|
||||
$oFormField->SetSearch($oSearch);
|
||||
}
|
||||
// We set search object only if it has not already been set (overrided)
|
||||
if ($oTmpField->GetSearch() === null) {
|
||||
$oSearch = DBSearch::FromOQL($oTmpAttDef->GetValuesDef()->GetFilterExpression());
|
||||
$oSearch->SetInternalParams(array('this' => $oObject));
|
||||
$oTmpField->SetSearch($oSearch);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$oSearch = DBSearch::FromOQL($this->GetValuesDef()->GetFilterExpression());
|
||||
$oSearch->SetInternalParams(array('this' => $oObject));
|
||||
$oFormField->SetSearch($oSearch);
|
||||
}
|
||||
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_null($oHostObject)) {
|
||||
return $oHostObject->GetAsHTML($this->GetCode(), $oHostObject);
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_null($oHostObject)) {
|
||||
return $oHostObject->GetAsHTML($this->GetCode(), $oHostObject);
|
||||
}
|
||||
|
||||
return DBObject::MakeHyperLink($this->GetTargetClass(), $sValue);
|
||||
}
|
||||
return DBObject::MakeHyperLink($this->GetTargetClass(), $sValue);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use MetaModel;
|
||||
use Str;
|
||||
|
||||
/**
|
||||
* The attribute dedicated to the finalclass automatic attribute
|
||||
@@ -7,191 +17,192 @@
|
||||
*/
|
||||
class AttributeFinalClass extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
public $m_sValue;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
public $m_sValue;
|
||||
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aParams["allowed_values"] = null;
|
||||
parent::__construct($sCode, $aParams);
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aParams["allowed_values"] = null;
|
||||
parent::__construct($sCode, $aParams);
|
||||
|
||||
$this->m_sValue = $this->Get("default_value");
|
||||
}
|
||||
$this->m_sValue = $this->Get("default_value");
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function SetFixedValue($sValue)
|
||||
{
|
||||
$this->m_sValue = $sValue;
|
||||
}
|
||||
public function SetFixedValue($sValue)
|
||||
{
|
||||
$this->m_sValue = $sValue;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->m_sValue;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->m_sValue;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
if ($bLocalize) {
|
||||
return MetaModel::GetName($sValue);
|
||||
} else {
|
||||
return $sValue;
|
||||
}
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
if ($bLocalize) {
|
||||
return MetaModel::GetName($sValue);
|
||||
} else {
|
||||
return $sValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An enum can be localized
|
||||
*
|
||||
* @param string $sProposedValue
|
||||
* @param bool $bLocalizedValue
|
||||
* @param string $sSepItem
|
||||
* @param string $sSepAttribute
|
||||
* @param string $sSepValue
|
||||
* @param string $sAttributeQualifier
|
||||
*
|
||||
* @return mixed|null|string
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
if ($bLocalizedValue) {
|
||||
// Lookup for the value matching the input
|
||||
//
|
||||
$sFoundValue = null;
|
||||
$aRawValues = self::GetAllowedValues();
|
||||
if (!is_null($aRawValues)) {
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
if ($sProposedValue == $sValue) {
|
||||
$sFoundValue = $sKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($sFoundValue)) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* An enum can be localized
|
||||
*
|
||||
* @param string $sProposedValue
|
||||
* @param bool $bLocalizedValue
|
||||
* @param string $sSepItem
|
||||
* @param string $sSepAttribute
|
||||
* @param string $sSepValue
|
||||
* @param string $sAttributeQualifier
|
||||
*
|
||||
* @return mixed|null|string
|
||||
* @throws CoreException
|
||||
* @throws OQLException
|
||||
*/
|
||||
public function MakeValueFromString(
|
||||
$sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null,
|
||||
$sAttributeQualifier = null
|
||||
)
|
||||
{
|
||||
if ($bLocalizedValue) {
|
||||
// Lookup for the value matching the input
|
||||
//
|
||||
$sFoundValue = null;
|
||||
$aRawValues = self::GetAllowedValues();
|
||||
if (!is_null($aRawValues)) {
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
if ($sProposedValue == $sValue) {
|
||||
$sFoundValue = $sKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($sFoundValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->MakeRealValue($sFoundValue, null);
|
||||
} else {
|
||||
return parent::MakeValueFromString($sProposedValue, $bLocalizedValue, $sSepItem, $sSepAttribute, $sSepValue,
|
||||
$sAttributeQualifier);
|
||||
}
|
||||
}
|
||||
return $this->MakeRealValue($sFoundValue, null);
|
||||
} else {
|
||||
return parent::MakeValueFromString($sProposedValue, $bLocalizedValue, $sSepItem, $sSepAttribute, $sSepValue,
|
||||
$sAttributeQualifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Because this is sometimes used to get a localized/string version of an attribute...
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
// Because this is sometimes used to get a localized/string version of an attribute...
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return MetaModel::GetName($sValue);
|
||||
}
|
||||
return MetaModel::GetName($sValue);
|
||||
}
|
||||
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
// JSON values are NOT localized
|
||||
return $value;
|
||||
}
|
||||
public function GetForJSON($value)
|
||||
{
|
||||
// JSON values are NOT localized
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return string
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if ($bLocalize && $value != '') {
|
||||
$sRawValue = MetaModel::GetName($value);
|
||||
} else {
|
||||
$sRawValue = $value;
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return string
|
||||
* @throws CoreException
|
||||
* @throws DictExceptionMissingString
|
||||
*/
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if ($bLocalize && $value != '') {
|
||||
$sRawValue = MetaModel::GetName($value);
|
||||
} else {
|
||||
$sRawValue = $value;
|
||||
}
|
||||
|
||||
return parent::GetAsCSV($sRawValue, $sSeparator, $sTextQualifier, null, false, $bConvertToPlainText);
|
||||
}
|
||||
return parent::GetAsCSV($sRawValue, $sSeparator, $sTextQualifier, null, false, $bConvertToPlainText);
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
if ($bLocalize) {
|
||||
$sRawValue = MetaModel::GetName($value);
|
||||
} else {
|
||||
$sRawValue = $value;
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
if ($bLocalize) {
|
||||
$sRawValue = MetaModel::GetName($value);
|
||||
} else {
|
||||
$sRawValue = $value;
|
||||
}
|
||||
|
||||
return Str::pure2xml($sRawValue);
|
||||
}
|
||||
return Str::pure2xml($sRawValue);
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return MetaModel::GetName($sValue);
|
||||
}
|
||||
return MetaModel::GetName($sValue);
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$aRawValues = MetaModel::EnumChildClasses($this->GetHostClass(), ENUM_CHILD_CLASSES_ALL);
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sClass) {
|
||||
$aLocalizedValues[$sClass] = MetaModel::GetName($sClass);
|
||||
}
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$aRawValues = MetaModel::EnumChildClasses($this->GetHostClass(), ENUM_CHILD_CLASSES_ALL);
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sClass) {
|
||||
$aLocalizedValues[$sClass] = MetaModel::GetName($sClass);
|
||||
}
|
||||
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @since 2.7.0 N°2272 OQL perf finalclass in all intermediary tables
|
||||
*/
|
||||
public function CopyOnAllTables()
|
||||
{
|
||||
$sClass = self::GetHostClass();
|
||||
if (MetaModel::IsLeafClass($sClass)) {
|
||||
// Leaf class, no finalclass
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @return bool
|
||||
* @since 2.7.0 N°2272 OQL perf finalclass in all intermediary tables
|
||||
*/
|
||||
public function CopyOnAllTables()
|
||||
{
|
||||
$sClass = self::GetHostClass();
|
||||
if (MetaModel::IsLeafClass($sClass)) {
|
||||
// Leaf class, no finalclass
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,16 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use Str;
|
||||
|
||||
/**
|
||||
* The attribute dedicated to the friendly name automatic attribute (not written)
|
||||
@@ -7,193 +19,193 @@
|
||||
*/
|
||||
class AttributeFriendlyName extends AttributeDefinition
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
public $m_sValue;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
public $m_sValue;
|
||||
|
||||
public function __construct($sCode)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aParams = array();
|
||||
$aParams["default_value"] = '';
|
||||
parent::__construct($sCode, $aParams);
|
||||
public function __construct($sCode)
|
||||
{
|
||||
$this->m_sCode = $sCode;
|
||||
$aParams = array();
|
||||
$aParams["default_value"] = '';
|
||||
parent::__construct($sCode, $aParams);
|
||||
|
||||
$this->m_sValue = $this->Get("default_value");
|
||||
}
|
||||
$this->m_sValue = $this->Get("default_value");
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
// Code duplicated with AttributeObsolescenceFlag
|
||||
$aAttributes = $this->GetOptional("depends_on", array());
|
||||
$oExpression = $this->GetOQLExpression();
|
||||
foreach ($oExpression->ListRequiredFields() as $sAttCode) {
|
||||
if (!in_array($sAttCode, $aAttributes)) {
|
||||
$aAttributes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
// Code duplicated with AttributeObsolescenceFlag
|
||||
$aAttributes = $this->GetOptional("depends_on", array());
|
||||
$oExpression = $this->GetOQLExpression();
|
||||
foreach ($oExpression->ListRequiredFields() as $sAttCode) {
|
||||
if (!in_array($sAttCode, $aAttributes)) {
|
||||
$aAttributes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
|
||||
return $aAttributes;
|
||||
}
|
||||
return $aAttributes;
|
||||
}
|
||||
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->GetCode(); // Warning AttributeComputedFieldVoid does not have any sql property
|
||||
}
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->GetCode(); // Warning AttributeComputedFieldVoid does not have any sql property
|
||||
}
|
||||
|
||||
return array('' => $sPrefix);
|
||||
}
|
||||
return array('' => $sPrefix);
|
||||
}
|
||||
|
||||
public static function IsBasedOnOQLExpression()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsBasedOnOQLExpression()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetOQLExpression()
|
||||
{
|
||||
return MetaModel::GetNameExpression($this->GetHostClass());
|
||||
}
|
||||
public function GetOQLExpression()
|
||||
{
|
||||
return MetaModel::GetNameExpression($this->GetHostClass());
|
||||
}
|
||||
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sLabel = parent::GetLabel('');
|
||||
if (strlen($sLabel) == 0) {
|
||||
$sLabel = Dict::S('Core:FriendlyName-Label');
|
||||
}
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sLabel = parent::GetLabel('');
|
||||
if (strlen($sLabel) == 0) {
|
||||
$sLabel = Dict::S('Core:FriendlyName-Label');
|
||||
}
|
||||
|
||||
return $sLabel;
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sLabel = parent::GetDescription('');
|
||||
if (strlen($sLabel) == 0) {
|
||||
$sLabel = Dict::S('Core:FriendlyName-Description');
|
||||
}
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sLabel = parent::GetDescription('');
|
||||
if (strlen($sLabel) == 0) {
|
||||
$sLabel = Dict::S('Core:FriendlyName-Description');
|
||||
}
|
||||
|
||||
return $sLabel;
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$sValue = $aCols[$sPrefix];
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$sValue = $aCols[$sPrefix];
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function SetFixedValue($sValue)
|
||||
{
|
||||
$this->m_sValue = $sValue;
|
||||
}
|
||||
public function SetFixedValue($sValue)
|
||||
{
|
||||
$this->m_sValue = $sValue;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->m_sValue;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->m_sValue;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2html((string)$sValue);
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2html((string)$sValue);
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
|
||||
return $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
}
|
||||
return $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
}
|
||||
|
||||
static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\StringField';
|
||||
}
|
||||
static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\StringField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
$oFormField->SetReadOnly(true);
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
$oFormField->SetReadOnly(true);
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
// Do not display friendly names in the history of change
|
||||
public function DescribeChangeAsHTML($sOldValue, $sNewValue, $sLabel = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
// Do not display friendly names in the history of change
|
||||
public function DescribeChangeAsHTML($sOldValue, $sNewValue, $sLabel = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array("=" => "equals", "!=" => "differs from");
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array("=" => "equals", "!=" => "differs from");
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "Contains";
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "Contains";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '=':
|
||||
case '!=':
|
||||
return $this->GetSQLExpr() . " $sOpCode $sQValue";
|
||||
case 'Contains':
|
||||
return $this->GetSQLExpr() . " LIKE " . CMDBSource::Quote("%$value%");
|
||||
case 'NotLike':
|
||||
return $this->GetSQLExpr() . " NOT LIKE $sQValue";
|
||||
case 'Like':
|
||||
default:
|
||||
return $this->GetSQLExpr() . " LIKE $sQValue";
|
||||
}
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '=':
|
||||
case '!=':
|
||||
return $this->GetSQLExpr()." $sOpCode $sQValue";
|
||||
case 'Contains':
|
||||
return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("%$value%");
|
||||
case 'NotLike':
|
||||
return $this->GetSQLExpr()." NOT LIKE $sQValue";
|
||||
case 'Like':
|
||||
default:
|
||||
return $this->GetSQLExpr()." LIKE $sQValue";
|
||||
}
|
||||
}
|
||||
|
||||
public function IsPartOfFingerprint()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsPartOfFingerprint()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
/**
|
||||
* Map a text column (size > ?), containing HTML code, to an attribute
|
||||
@@ -7,45 +13,45 @@
|
||||
*/
|
||||
class AttributeHTML extends AttributeLongText
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get('sql')] = $this->GetSQLCol();
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns[$this->Get('sql') . '_format'] = "ENUM('text','html')";
|
||||
if ($bFullSpec) {
|
||||
$aColumns[$this->Get('sql') . '_format'] .= " DEFAULT 'html'"; // default 'html' is for migrating old records
|
||||
}
|
||||
}
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get('sql')] = $this->GetSQLCol();
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns[$this->Get('sql').'_format'] = "ENUM('text','html')";
|
||||
if ($bFullSpec) {
|
||||
$aColumns[$this->Get('sql').'_format'] .= " DEFAULT 'html'"; // default 'html' is for migrating old records
|
||||
}
|
||||
}
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual formatting of the text: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'html'); // Defaults to HTML
|
||||
}
|
||||
/**
|
||||
* The actual formatting of the text: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'html'); // Defaults to HTML
|
||||
}
|
||||
}
|
||||
@@ -1,186 +1,194 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObjectSearch;
|
||||
|
||||
/**
|
||||
* Special kind of External Key to manage a hierarchy of objects
|
||||
*/
|
||||
class AttributeHierarchicalKey extends AttributeExternalKey
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY;
|
||||
|
||||
protected $m_sTargetClass;
|
||||
protected $m_sTargetClass;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
$aParams = parent::ListExpectedParams();
|
||||
$idx = array_search('targetclass', $aParams);
|
||||
unset($aParams[$idx]);
|
||||
$idx = array_search('jointype', $aParams);
|
||||
unset($aParams[$idx]);
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
$aParams = parent::ListExpectedParams();
|
||||
$idx = array_search('targetclass', $aParams);
|
||||
unset($aParams[$idx]);
|
||||
$idx = array_search('jointype', $aParams);
|
||||
unset($aParams[$idx]);
|
||||
|
||||
return $aParams; // Later: mettre les bons parametres ici !!
|
||||
}
|
||||
return $aParams; // Later: mettre les bons parametres ici !!
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "ExtKey";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "ExtKey";
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* The target class is the class for which the attribute has been defined first
|
||||
*/
|
||||
public function SetHostClass($sHostClass)
|
||||
{
|
||||
if (!isset($this->m_sTargetClass)) {
|
||||
$this->m_sTargetClass = $sHostClass;
|
||||
}
|
||||
parent::SetHostClass($sHostClass);
|
||||
}
|
||||
/*
|
||||
* The target class is the class for which the attribute has been defined first
|
||||
*/
|
||||
public function SetHostClass($sHostClass)
|
||||
{
|
||||
if (!isset($this->m_sTargetClass)) {
|
||||
$this->m_sTargetClass = $sHostClass;
|
||||
}
|
||||
parent::SetHostClass($sHostClass);
|
||||
}
|
||||
|
||||
public static function IsHierarchicalKey()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsHierarchicalKey()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetTargetClass($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this->m_sTargetClass;
|
||||
}
|
||||
public function GetTargetClass($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this->m_sTargetClass;
|
||||
}
|
||||
|
||||
public function GetKeyAttDef($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
public function GetKeyAttDef($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetKeyAttCode()
|
||||
{
|
||||
return $this->GetCode();
|
||||
}
|
||||
public function GetKeyAttCode()
|
||||
{
|
||||
return $this->GetCode();
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return parent::GetBasicFilterLooseOperator();
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return parent::GetBasicFilterLooseOperator();
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'INT(11)' . ($bFullSpec ? ' DEFAULT 0' : '');
|
||||
$aColumns[$this->GetSQLLeft()] = 'INT(11)' . ($bFullSpec ? ' DEFAULT 0' : '');
|
||||
$aColumns[$this->GetSQLRight()] = 'INT(11)' . ($bFullSpec ? ' DEFAULT 0' : '');
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'INT(11)'.($bFullSpec ? ' DEFAULT 0' : '');
|
||||
$aColumns[$this->GetSQLLeft()] = 'INT(11)'.($bFullSpec ? ' DEFAULT 0' : '');
|
||||
$aColumns[$this->GetSQLRight()] = 'INT(11)'.($bFullSpec ? ' DEFAULT 0' : '');
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetSQLRight()
|
||||
{
|
||||
return $this->GetCode() . '_right';
|
||||
}
|
||||
public function GetSQLRight()
|
||||
{
|
||||
return $this->GetCode().'_right';
|
||||
}
|
||||
|
||||
public function GetSQLLeft()
|
||||
{
|
||||
return $this->GetCode() . '_left';
|
||||
}
|
||||
public function GetSQLLeft()
|
||||
{
|
||||
return $this->GetCode().'_left';
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
$aValues[$this->GetCode()] = $value;
|
||||
} else {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode()] = $value[$this->GetCode()];
|
||||
$aValues[$this->GetSQLRight()] = $value[$this->GetSQLRight()];
|
||||
$aValues[$this->GetSQLLeft()] = $value[$this->GetSQLLeft()];
|
||||
}
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
$aValues[$this->GetCode()] = $value;
|
||||
} else {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode()] = $value[$this->GetCode()];
|
||||
$aValues[$this->GetSQLRight()] = $value[$this->GetSQLRight()];
|
||||
$aValues[$this->GetSQLLeft()] = $value[$this->GetSQLLeft()];
|
||||
}
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$oFilter = $this->GetHierachicalFilter($aArgs, $sContains);
|
||||
if ($oFilter) {
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
$oValSetDef->SetCondition($oFilter);
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$oFilter = $this->GetHierachicalFilter($aArgs, $sContains);
|
||||
if ($oFilter) {
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
$oValSetDef->SetCondition($oFilter);
|
||||
|
||||
return $oValSetDef->GetValues($aArgs, $sContains);
|
||||
} else {
|
||||
return parent::GetAllowedValues($aArgs, $sContains);
|
||||
}
|
||||
}
|
||||
return $oValSetDef->GetValues($aArgs, $sContains);
|
||||
} else {
|
||||
return parent::GetAllowedValues($aArgs, $sContains);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAllowedValuesAsObjectSet($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
$oFilter = $this->GetHierachicalFilter($aArgs, $sContains, $iAdditionalValue);
|
||||
if ($oFilter) {
|
||||
$oValSetDef->SetCondition($oFilter);
|
||||
}
|
||||
$oSet = $oValSetDef->ToObjectSet($aArgs, $sContains, $iAdditionalValue);
|
||||
public function GetAllowedValuesAsObjectSet($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
$oFilter = $this->GetHierachicalFilter($aArgs, $sContains, $iAdditionalValue);
|
||||
if ($oFilter) {
|
||||
$oValSetDef->SetCondition($oFilter);
|
||||
}
|
||||
$oSet = $oValSetDef->ToObjectSet($aArgs, $sContains, $iAdditionalValue);
|
||||
|
||||
return $oSet;
|
||||
}
|
||||
return $oSet;
|
||||
}
|
||||
|
||||
public function GetAllowedValuesAsFilter($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
$oFilter = $this->GetHierachicalFilter($aArgs, $sContains, $iAdditionalValue);
|
||||
if ($oFilter) {
|
||||
return $oFilter;
|
||||
}
|
||||
public function GetAllowedValuesAsFilter($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
$oFilter = $this->GetHierachicalFilter($aArgs, $sContains, $iAdditionalValue);
|
||||
if ($oFilter) {
|
||||
return $oFilter;
|
||||
}
|
||||
|
||||
return parent::GetAllowedValuesAsFilter($aArgs, $sContains, $iAdditionalValue);
|
||||
}
|
||||
return parent::GetAllowedValuesAsFilter($aArgs, $sContains, $iAdditionalValue);
|
||||
}
|
||||
|
||||
private function GetHierachicalFilter($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
if (array_key_exists('this', $aArgs)) {
|
||||
// Hierarchical keys have one more constraint: the "parent value" cannot be
|
||||
// "under" themselves
|
||||
$iRootId = $aArgs['this']->GetKey();
|
||||
if ($iRootId > 0) // ignore objects that do no exist in the database...
|
||||
{
|
||||
$sClass = $this->m_sTargetClass;
|
||||
private function GetHierachicalFilter($aArgs = array(), $sContains = '', $iAdditionalValue = null)
|
||||
{
|
||||
if (array_key_exists('this', $aArgs)) {
|
||||
// Hierarchical keys have one more constraint: the "parent value" cannot be
|
||||
// "under" themselves
|
||||
$iRootId = $aArgs['this']->GetKey();
|
||||
if ($iRootId > 0) // ignore objects that do no exist in the database...
|
||||
{
|
||||
$sClass = $this->m_sTargetClass;
|
||||
|
||||
return DBObjectSearch::FromOQL("SELECT $sClass AS node JOIN $sClass AS root ON node." . $this->GetCode() . " NOT BELOW root.id WHERE root.id = $iRootId");
|
||||
}
|
||||
}
|
||||
return DBObjectSearch::FromOQL("SELECT $sClass AS node JOIN $sClass AS root ON node.".$this->GetCode()." NOT BELOW root.id WHERE root.id = $iRootId");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the corresponding "link" attribute on the target class, if any
|
||||
*
|
||||
* @return null | AttributeDefinition
|
||||
*/
|
||||
public function GetMirrorLinkAttribute()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Find the corresponding "link" attribute on the target class, if any
|
||||
*
|
||||
* @return null | AttributeDefinition
|
||||
*/
|
||||
public function GetMirrorLinkAttribute()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
/**
|
||||
* Specialization of a string: IP address
|
||||
@@ -7,33 +13,33 @@
|
||||
*/
|
||||
class AttributeIPAddress extends AttributeString
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
$sNum = '(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])';
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
$sNum = '(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])';
|
||||
|
||||
return "^($sNum\\.$sNum\\.$sNum\\.$sNum)$";
|
||||
}
|
||||
return "^($sNum\\.$sNum\\.$sNum\\.$sNum)$";
|
||||
}
|
||||
|
||||
public function GetOrderBySQLExpressions($sClassAlias)
|
||||
{
|
||||
// Note: This is the responsibility of this function to place backticks around column aliases
|
||||
return array('INET_ATON(`' . $sClassAlias . $this->GetCode() . '`)');
|
||||
}
|
||||
public function GetOrderBySQLExpressions($sClassAlias)
|
||||
{
|
||||
// Note: This is the responsibility of this function to place backticks around column aliases
|
||||
return array('INET_ATON(`'.$sClassAlias.$this->GetCode().'`)');
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use HTMLSanitizer;
|
||||
use ormDocument;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* An image is a specific type of document, it is stored as several columns in the database
|
||||
@@ -7,188 +18,190 @@
|
||||
*/
|
||||
class AttributeImage extends AttributeBlob
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function Get($sParamName)
|
||||
{
|
||||
$oParamValue = parent::Get($sParamName);
|
||||
public function Get($sParamName)
|
||||
{
|
||||
$oParamValue = parent::Get($sParamName);
|
||||
|
||||
if ($sParamName === 'default_image') {
|
||||
/** @noinspection NestedPositiveIfStatementsInspection */
|
||||
if (!empty($oParamValue)) {
|
||||
return utils::GetAbsoluteUrlModulesRoot() . $oParamValue;
|
||||
}
|
||||
}
|
||||
if ($sParamName === 'default_image') {
|
||||
/** @noinspection NestedPositiveIfStatementsInspection */
|
||||
if (!empty($oParamValue)) {
|
||||
return utils::GetAbsoluteUrlModulesRoot().$oParamValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $oParamValue;
|
||||
}
|
||||
return $oParamValue;
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Image";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Image";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see AttributeBlob::MakeRealValue()
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
$oDoc = parent::MakeRealValue($proposedValue, $oHostObj);
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see AttributeBlob::MakeRealValue()
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
$oDoc = parent::MakeRealValue($proposedValue, $oHostObj);
|
||||
|
||||
if (($oDoc instanceof ormDocument)
|
||||
&& (false === $oDoc->IsEmpty())
|
||||
&& ($oDoc->GetMimeType() === 'image/svg+xml')) {
|
||||
$sCleanSvg = HTMLSanitizer::Sanitize($oDoc->GetData(), 'svg_sanitizer');
|
||||
$oDoc = new ormDocument($sCleanSvg, $oDoc->GetMimeType(), $oDoc->GetFileName());
|
||||
}
|
||||
if (($oDoc instanceof ormDocument)
|
||||
&& (false === $oDoc->IsEmpty())
|
||||
&& ($oDoc->GetMimeType() === 'image/svg+xml')) {
|
||||
$sCleanSvg = HTMLSanitizer::Sanitize($oDoc->GetData(), 'svg_sanitizer');
|
||||
$oDoc = new ormDocument($sCleanSvg, $oDoc->GetMimeType(), $oDoc->GetFileName());
|
||||
}
|
||||
|
||||
// The validation of the MIME Type is done by CheckFormat below
|
||||
return $oDoc;
|
||||
}
|
||||
// The validation of the MIME Type is done by CheckFormat below
|
||||
return $oDoc;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormDocument('', '', '');
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return new ormDocument('', '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the supplied ormDocument actually contains an image
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see AttributeDefinition::CheckFormat()
|
||||
*/
|
||||
public function CheckFormat($value)
|
||||
{
|
||||
if ($value instanceof ormDocument && !$value->IsEmpty()) {
|
||||
return ($value->GetMainMimeType() == 'image');
|
||||
}
|
||||
/**
|
||||
* Check that the supplied ormDocument actually contains an image
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see AttributeDefinition::CheckFormat()
|
||||
*/
|
||||
public function CheckFormat($value)
|
||||
{
|
||||
if ($value instanceof ormDocument && !$value->IsEmpty()) {
|
||||
return ($value->GetMainMimeType() == 'image');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ormDocument $value
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @see edit_image.js for JS generated markup in form edition
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sRet = '';
|
||||
$bIsCustomImage = false;
|
||||
/**
|
||||
* @see edit_image.js for JS generated markup in form edition
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @param ormDocument $value
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sRet = '';
|
||||
$bIsCustomImage = false;
|
||||
|
||||
$iMaxWidth = $this->Get('display_max_width');
|
||||
$sMaxWidthPx = $iMaxWidth . 'px';
|
||||
$iMaxHeight = $this->Get('display_max_height');
|
||||
$sMaxHeightPx = $iMaxHeight . 'px';
|
||||
$iMaxWidth = $this->Get('display_max_width');
|
||||
$sMaxWidthPx = $iMaxWidth.'px';
|
||||
$iMaxHeight = $this->Get('display_max_height');
|
||||
$sMaxHeightPx = $iMaxHeight.'px';
|
||||
|
||||
$sDefaultImageUrl = $this->Get('default_image');
|
||||
if ($sDefaultImageUrl !== null) {
|
||||
$sRet = $this->GetHtmlForImageUrl($sDefaultImageUrl, $sMaxWidthPx, $sMaxHeightPx);
|
||||
}
|
||||
$sDefaultImageUrl = $this->Get('default_image');
|
||||
if ($sDefaultImageUrl !== null) {
|
||||
$sRet = $this->GetHtmlForImageUrl($sDefaultImageUrl, $sMaxWidthPx, $sMaxHeightPx);
|
||||
}
|
||||
|
||||
$sCustomImageUrl = $this->GetAttributeImageFileUrl($value, $oHostObject);
|
||||
if ($sCustomImageUrl !== null) {
|
||||
$bIsCustomImage = true;
|
||||
$sRet = $this->GetHtmlForImageUrl($sCustomImageUrl, $sMaxWidthPx, $sMaxHeightPx);
|
||||
}
|
||||
$sCustomImageUrl = $this->GetAttributeImageFileUrl($value, $oHostObject);
|
||||
if ($sCustomImageUrl !== null) {
|
||||
$bIsCustomImage = true;
|
||||
$sRet = $this->GetHtmlForImageUrl($sCustomImageUrl, $sMaxWidthPx, $sMaxHeightPx);
|
||||
}
|
||||
|
||||
$sCssClasses = 'ibo-input-image--image-view attribute-image';
|
||||
$sCssClasses .= ' ' . (($bIsCustomImage) ? 'attribute-image-custom' : 'attribute-image-default');
|
||||
$sCssClasses = 'ibo-input-image--image-view attribute-image';
|
||||
$sCssClasses .= ' '.(($bIsCustomImage) ? 'attribute-image-custom' : 'attribute-image-default');
|
||||
|
||||
// Important: If you change this, mind updating edit_image.js as well
|
||||
return '<div class="' . $sCssClasses . '" style="max-width: min(' . $sMaxWidthPx . ',100%); max-height: min(' . $sMaxHeightPx . ',100%); aspect-ratio: ' . $iMaxWidth . ' / ' . $iMaxHeight . '">' . $sRet . '</div>';
|
||||
}
|
||||
// Important: If you change this, mind updating edit_image.js as well
|
||||
return '<div class="'.$sCssClasses.'" style="max-width: min('.$sMaxWidthPx.',100%); max-height: min('.$sMaxHeightPx.',100%); aspect-ratio: '.$iMaxWidth.' / '.$iMaxHeight.'">'.$sRet.'</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUrl
|
||||
* @param int $iMaxWidthPx
|
||||
* @param int $iMaxHeightPx
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 2.6.0 new private method
|
||||
* @since 2.7.0 change visibility to protected
|
||||
*/
|
||||
protected function GetHtmlForImageUrl($sUrl, $iMaxWidthPx, $iMaxHeightPx)
|
||||
{
|
||||
return '<img src="' . $sUrl . '" style="max-width: min(' . $iMaxWidthPx . ',100%); max-height: min(' . $iMaxHeightPx . ',100%)">';
|
||||
}
|
||||
/**
|
||||
* @param string $sUrl
|
||||
* @param int $iMaxWidthPx
|
||||
* @param int $iMaxHeightPx
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 2.6.0 new private method
|
||||
* @since 2.7.0 change visibility to protected
|
||||
*/
|
||||
protected function GetHtmlForImageUrl($sUrl, $iMaxWidthPx, $iMaxHeightPx)
|
||||
{
|
||||
return '<img src="'.$sUrl.'" style="max-width: min('.$iMaxWidthPx.',100%); max-height: min('.$iMaxHeightPx.',100%)">';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ormDocument $value
|
||||
* @param \DBObject $oHostObject
|
||||
*
|
||||
* @return null|string
|
||||
*
|
||||
* @since 2.6.0 new private method
|
||||
* @since 2.7.0 change visibility to protected
|
||||
*/
|
||||
protected function GetAttributeImageFileUrl($value, $oHostObject)
|
||||
{
|
||||
if (!is_object($value)) {
|
||||
return null;
|
||||
}
|
||||
if ($value->IsEmpty()) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param ormDocument $value
|
||||
* @param DBObject $oHostObject
|
||||
*
|
||||
* @return null|string
|
||||
*
|
||||
* @since 2.6.0 new private method
|
||||
* @since 2.7.0 change visibility to protected
|
||||
*/
|
||||
protected function GetAttributeImageFileUrl($value, $oHostObject)
|
||||
{
|
||||
if (!is_object($value)) {
|
||||
return null;
|
||||
}
|
||||
if ($value->IsEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$bExistingImageModified = ($oHostObject->IsModified() && (array_key_exists($this->GetCode(), $oHostObject->ListChanges())));
|
||||
if ($oHostObject->IsNew() || ($bExistingImageModified)) {
|
||||
// If the object is modified (or not yet stored in the database) we must serve the content of the image directly inline
|
||||
// otherwise (if we just give an URL) the browser will be given the wrong content... and may cache it
|
||||
return 'data:' . $value->GetMimeType() . ';base64,' . base64_encode($value->GetData());
|
||||
}
|
||||
$bExistingImageModified = ($oHostObject->IsModified() && (array_key_exists($this->GetCode(), $oHostObject->ListChanges())));
|
||||
if ($oHostObject->IsNew() || ($bExistingImageModified)) {
|
||||
// If the object is modified (or not yet stored in the database) we must serve the content of the image directly inline
|
||||
// otherwise (if we just give an URL) the browser will be given the wrong content... and may cache it
|
||||
return 'data:'.$value->GetMimeType().';base64,'.base64_encode($value->GetData());
|
||||
}
|
||||
|
||||
return $value->GetDisplayURL(get_class($oHostObject), $oHostObject->GetKey(), $this->GetCode());
|
||||
}
|
||||
return $value->GetDisplayURL(get_class($oHostObject), $oHostObject->GetKey(), $this->GetCode());
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\ImageField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\ImageField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
// Generating urls
|
||||
$value = $oObject->Get($this->GetCode());
|
||||
if (is_object($value) && !$value->IsEmpty()) {
|
||||
$oFormField->SetDownloadUrl($value->GetDownloadURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
$oFormField->SetDisplayUrl($value->GetDisplayURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
} else {
|
||||
$oDefaultImage = $this->Get('default_image');
|
||||
if (is_object($oDefaultImage) && !$oDefaultImage->IsEmpty()) {
|
||||
$oFormField->SetDownloadUrl($oDefaultImage);
|
||||
$oFormField->SetDisplayUrl($oDefaultImage);
|
||||
}
|
||||
}
|
||||
// Generating urls
|
||||
$value = $oObject->Get($this->GetCode());
|
||||
if (is_object($value) && !$value->IsEmpty()) {
|
||||
$oFormField->SetDownloadUrl($value->GetDownloadURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
$oFormField->SetDisplayUrl($value->GetDisplayURL(get_class($oObject), $oObject->GetKey(), $this->GetCode()));
|
||||
} else {
|
||||
$oDefaultImage = $this->Get('default_image');
|
||||
if (is_object($oDefaultImage) && !$oDefaultImage->IsEmpty()) {
|
||||
$oFormField->SetDownloadUrl($oDefaultImage);
|
||||
$oFormField->SetDisplayUrl($oDefaultImage);
|
||||
}
|
||||
}
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use CoreException;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Map an integer column to an attribute
|
||||
@@ -7,132 +17,132 @@
|
||||
*/
|
||||
class AttributeInteger extends AttributeDBField
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_NUMERIC;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_NUMERIC;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11)" . ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11)".($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return "^[0-9]+$";
|
||||
}
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return "^[0-9]+$";
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"!=" => "differs from",
|
||||
"=" => "equals",
|
||||
">" => "greater (strict) than",
|
||||
">=" => "greater than",
|
||||
"<" => "less (strict) than",
|
||||
"<=" => "less than",
|
||||
"in" => "in"
|
||||
);
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"!=" => "differs from",
|
||||
"=" => "equals",
|
||||
">" => "greater (strict) than",
|
||||
">=" => "greater than",
|
||||
"<" => "less (strict) than",
|
||||
"<=" => "less than",
|
||||
"in" => "in",
|
||||
);
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
// Unless we implement an "equals approximately..." or "same order of magnitude"
|
||||
return "=";
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
// Unless we implement an "equals approximately..." or "same order of magnitude"
|
||||
return "=";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr() . " != $sQValue";
|
||||
break;
|
||||
case '>':
|
||||
return $this->GetSQLExpr() . " > $sQValue";
|
||||
break;
|
||||
case '>=':
|
||||
return $this->GetSQLExpr() . " >= $sQValue";
|
||||
break;
|
||||
case '<':
|
||||
return $this->GetSQLExpr() . " < $sQValue";
|
||||
break;
|
||||
case '<=':
|
||||
return $this->GetSQLExpr() . " <= $sQValue";
|
||||
break;
|
||||
case 'in':
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException("Expected an array for argument value (sOpCode='$sOpCode')");
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr()." != $sQValue";
|
||||
break;
|
||||
case '>':
|
||||
return $this->GetSQLExpr()." > $sQValue";
|
||||
break;
|
||||
case '>=':
|
||||
return $this->GetSQLExpr()." >= $sQValue";
|
||||
break;
|
||||
case '<':
|
||||
return $this->GetSQLExpr()." < $sQValue";
|
||||
break;
|
||||
case '<=':
|
||||
return $this->GetSQLExpr()." <= $sQValue";
|
||||
break;
|
||||
case 'in':
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException("Expected an array for argument value (sOpCode='$sOpCode')");
|
||||
}
|
||||
|
||||
return $this->GetSQLExpr() . " IN ('" . implode("', '", $value) . "')";
|
||||
break;
|
||||
return $this->GetSQLExpr()." IN ('".implode("', '", $value)."')";
|
||||
break;
|
||||
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr() . " = \"$value\"";
|
||||
}
|
||||
}
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr()." = \"$value\"";
|
||||
}
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return is_null($proposedValue);
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return is_null($proposedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return null;
|
||||
} // 0 is transformed into '' !
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return null;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return null;
|
||||
} // 0 is transformed into '' !
|
||||
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
assert(is_numeric($value) || is_null($value));
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
assert(is_numeric($value) || is_null($value));
|
||||
|
||||
return $value; // supposed to be an int
|
||||
}
|
||||
return $value; // supposed to be an int
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CoreException;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Set of objects linked to an object (n-n), and being part of its definition
|
||||
@@ -7,90 +17,90 @@
|
||||
*/
|
||||
class AttributeLinkedSetIndirect extends AttributeLinkedSet
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("ext_key_to_remote"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("ext_key_to_remote"));
|
||||
}
|
||||
|
||||
public function IsIndirect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsIndirect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetExtKeyToRemote()
|
||||
{
|
||||
return $this->Get('ext_key_to_remote');
|
||||
}
|
||||
public function GetExtKeyToRemote()
|
||||
{
|
||||
return $this->Get('ext_key_to_remote');
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "LinkedSet";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "LinkedSet";
|
||||
}
|
||||
|
||||
public function DuplicatesAllowed()
|
||||
{
|
||||
return $this->GetOptional("duplicates", false);
|
||||
} // The same object may be linked several times... or not...
|
||||
public function DuplicatesAllowed()
|
||||
{
|
||||
return $this->GetOptional("duplicates", false);
|
||||
} // The same object may be linked several times... or not...
|
||||
|
||||
public function GetTrackingLevel()
|
||||
{
|
||||
return $this->GetOptional('tracking_level',
|
||||
MetaModel::GetConfig()->Get('tracking_level_linked_set_indirect_default'));
|
||||
}
|
||||
public function GetTrackingLevel()
|
||||
{
|
||||
return $this->GetOptional('tracking_level',
|
||||
MetaModel::GetConfig()->Get('tracking_level_linked_set_indirect_default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the corresponding "link" attribute on the target class, if any
|
||||
*
|
||||
* @return null | AttributeDefinition
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetMirrorLinkAttribute()
|
||||
{
|
||||
$oRet = null;
|
||||
/** @var \AttributeExternalKey $oExtKeyToRemote */
|
||||
$oExtKeyToRemote = MetaModel::GetAttributeDef($this->GetLinkedClass(), $this->GetExtKeyToRemote());
|
||||
$sRemoteClass = $oExtKeyToRemote->GetTargetClass();
|
||||
foreach (MetaModel::ListAttributeDefs($sRemoteClass) as $sRemoteAttCode => $oRemoteAttDef) {
|
||||
if (!$oRemoteAttDef instanceof AttributeLinkedSetIndirect) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetLinkedClass() != $this->GetLinkedClass()) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetExtKeyToMe() != $this->GetExtKeyToRemote()) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetExtKeyToRemote() != $this->GetExtKeyToMe()) {
|
||||
continue;
|
||||
}
|
||||
$oRet = $oRemoteAttDef;
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* Find the corresponding "link" attribute on the target class, if any
|
||||
*
|
||||
* @return null | AttributeDefinition
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function GetMirrorLinkAttribute()
|
||||
{
|
||||
$oRet = null;
|
||||
/** @var \AttributeExternalKey $oExtKeyToRemote */
|
||||
$oExtKeyToRemote = MetaModel::GetAttributeDef($this->GetLinkedClass(), $this->GetExtKeyToRemote());
|
||||
$sRemoteClass = $oExtKeyToRemote->GetTargetClass();
|
||||
foreach (MetaModel::ListAttributeDefs($sRemoteClass) as $sRemoteAttCode => $oRemoteAttDef) {
|
||||
if (!$oRemoteAttDef instanceof AttributeLinkedSetIndirect) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetLinkedClass() != $this->GetLinkedClass()) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetExtKeyToMe() != $this->GetExtKeyToRemote()) {
|
||||
continue;
|
||||
}
|
||||
if ($oRemoteAttDef->GetExtKeyToRemote() != $this->GetExtKeyToMe()) {
|
||||
continue;
|
||||
}
|
||||
$oRet = $oRemoteAttDef;
|
||||
break;
|
||||
}
|
||||
|
||||
return $oRet;
|
||||
}
|
||||
return $oRet;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public static function IsBulkModifyCompatible(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/** @inheritDoc */
|
||||
public static function IsBulkModifyCompatible(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOpSetAttributeHTML;
|
||||
use CMDBChangeOpSetAttributeLongText;
|
||||
use CMDBSource;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Map a log to an attribute
|
||||
@@ -7,39 +18,39 @@
|
||||
*/
|
||||
class AttributeLongText extends AttributeText
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "LONGTEXT" . CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "LONGTEXT".CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
// Is there a way to know the current limitation for mysql?
|
||||
// See mysql_field_len()
|
||||
return 65535 * 1024; // Limited... still 64 MB!
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
// Is there a way to know the current limitation for mysql?
|
||||
// See mysql_field_len()
|
||||
return 65535 * 1024; // Limited... still 64 MB!
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return ($this->GetFormat() === 'html')
|
||||
? CMDBChangeOpSetAttributeHTML::class
|
||||
: CMDBChangeOpSetAttributeLongText::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return ($this->GetFormat() === 'html')
|
||||
? CMDBChangeOpSetAttributeHTML::class
|
||||
: CMDBChangeOpSetAttributeLongText::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* A meta enum is an aggregation of enum from subclasses into an enum of a base class
|
||||
@@ -9,129 +18,129 @@
|
||||
*/
|
||||
class AttributeMetaEnum extends AttributeEnum
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array('allowed_values', 'sql', 'default_value', 'mapping');
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array('allowed_values', 'sql', 'default_value', 'mapping');
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false; // Well... this actually depends on the mapping
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false; // Well... this actually depends on the mapping
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
if (is_null($sClass)) {
|
||||
$sClass = $this->GetHostClass();
|
||||
}
|
||||
$aMappingData = $this->GetMapRule($sClass);
|
||||
if ($aMappingData == null) {
|
||||
$aRet = array();
|
||||
} else {
|
||||
$aRet = array($aMappingData['attcode']);
|
||||
}
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
if (is_null($sClass)) {
|
||||
$sClass = $this->GetHostClass();
|
||||
}
|
||||
$aMappingData = $this->GetMapRule($sClass);
|
||||
if ($aMappingData == null) {
|
||||
$aRet = array();
|
||||
} else {
|
||||
$aRet = array($aMappingData['attcode']);
|
||||
}
|
||||
|
||||
return $aRet;
|
||||
}
|
||||
return $aRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload the standard so as to leave the data unsorted
|
||||
*
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
if (!$oValSetDef) {
|
||||
return null;
|
||||
}
|
||||
$aRawValues = $oValSetDef->GetValueList();
|
||||
/**
|
||||
* Overload the standard so as to leave the data unsorted
|
||||
*
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
$oValSetDef = $this->GetValuesDef();
|
||||
if (!$oValSetDef) {
|
||||
return null;
|
||||
}
|
||||
$aRawValues = $oValSetDef->GetValueList();
|
||||
|
||||
if (is_null($aRawValues)) {
|
||||
return null;
|
||||
}
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$aLocalizedValues[$sKey] = $this->GetValueLabel($sKey);
|
||||
}
|
||||
if (is_null($aRawValues)) {
|
||||
return null;
|
||||
}
|
||||
$aLocalizedValues = array();
|
||||
foreach ($aRawValues as $sKey => $sValue) {
|
||||
$aLocalizedValues[$sKey] = $this->GetValueLabel($sKey);
|
||||
}
|
||||
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
return $aLocalizedValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the meta value for the given object.
|
||||
* See also MetaModel::RebuildMetaEnums() that must be maintained when MapValue changes
|
||||
*
|
||||
* @param $oObject
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MapValue($oObject)
|
||||
{
|
||||
$aMappingData = $this->GetMapRule(get_class($oObject));
|
||||
if ($aMappingData == null) {
|
||||
$sRet = $this->GetDefaultValue();
|
||||
} else {
|
||||
$sAttCode = $aMappingData['attcode'];
|
||||
$value = $oObject->Get($sAttCode);
|
||||
if (array_key_exists($value, $aMappingData['values'])) {
|
||||
$sRet = $aMappingData['values'][$value];
|
||||
} elseif ($this->GetDefaultValue() != '') {
|
||||
$sRet = $this->GetDefaultValue();
|
||||
} else {
|
||||
throw new Exception('AttributeMetaEnum::MapValue(): mapping not found for value "' . $value . '" in ' . get_class($oObject) . ', on attribute ' . MetaModel::GetAttributeOrigin($this->GetHostClass(),
|
||||
$this->GetCode()) . '::' . $this->GetCode());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the meta value for the given object.
|
||||
* See also MetaModel::RebuildMetaEnums() that must be maintained when MapValue changes
|
||||
*
|
||||
* @param $oObject
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MapValue($oObject)
|
||||
{
|
||||
$aMappingData = $this->GetMapRule(get_class($oObject));
|
||||
if ($aMappingData == null) {
|
||||
$sRet = $this->GetDefaultValue();
|
||||
} else {
|
||||
$sAttCode = $aMappingData['attcode'];
|
||||
$value = $oObject->Get($sAttCode);
|
||||
if (array_key_exists($value, $aMappingData['values'])) {
|
||||
$sRet = $aMappingData['values'][$value];
|
||||
} elseif ($this->GetDefaultValue() != '') {
|
||||
$sRet = $this->GetDefaultValue();
|
||||
} else {
|
||||
throw new Exception('AttributeMetaEnum::MapValue(): mapping not found for value "'.$value.'" in '.get_class($oObject).', on attribute '.MetaModel::GetAttributeOrigin($this->GetHostClass(),
|
||||
$this->GetCode()).'::'.$this->GetCode());
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function GetMapRule($sClass)
|
||||
{
|
||||
$aMappings = $this->Get('mapping');
|
||||
if (array_key_exists($sClass, $aMappings)) {
|
||||
$aMappingData = $aMappings[$sClass];
|
||||
} else {
|
||||
$sParent = MetaModel::GetParentClass($sClass);
|
||||
if (is_null($sParent)) {
|
||||
$aMappingData = null;
|
||||
} else {
|
||||
$aMappingData = $this->GetMapRule($sParent);
|
||||
}
|
||||
}
|
||||
public function GetMapRule($sClass)
|
||||
{
|
||||
$aMappings = $this->Get('mapping');
|
||||
if (array_key_exists($sClass, $aMappings)) {
|
||||
$aMappingData = $aMappings[$sClass];
|
||||
} else {
|
||||
$sParent = MetaModel::GetParentClass($sClass);
|
||||
if (is_null($sParent)) {
|
||||
$aMappingData = null;
|
||||
} else {
|
||||
$aMappingData = $this->GetMapRule($sParent);
|
||||
}
|
||||
}
|
||||
|
||||
return $aMappingData;
|
||||
}
|
||||
return $aMappingData;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Specialization of a string: OQL expression
|
||||
@@ -7,27 +15,27 @@
|
||||
*/
|
||||
class AttributeOQL extends AttributeText
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "OQLExpression";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "OQLExpression";
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* An external key for which the class is defined as the value of another attribute
|
||||
@@ -7,101 +17,101 @@
|
||||
*/
|
||||
class AttributeObjectKey extends AttributeDBFieldVoid
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_EXTERNAL_KEY;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_EXTERNAL_KEY;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_attcode', 'is_null_allowed'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('class_attcode', 'is_null_allowed'));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11)" . ($bFullSpec ? " DEFAULT 0" : "");
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "INT(11)".($bFullSpec ? " DEFAULT 0" : "");
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return parent::GetBasicFilterOperators();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return parent::GetBasicFilterLooseOperator();
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return parent::GetBasicFilterLooseOperator();
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return parent::GetBasicFilterSQLExpr($sOpCode, $value);
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return parent::GetBasicFilterSQLExpr($sOpCode, $value);
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == 0);
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return ((int)$proposedValue) !== 0;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return ((int)$proposedValue) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param int|DBObject $proposedValue Object key or valid ({@see MetaModel::IsValidObject()}) datamodel object
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return 0;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return 0;
|
||||
}
|
||||
if (MetaModel::IsValidObject($proposedValue)) {
|
||||
return $proposedValue->GetKey();
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param int|DBObject $proposedValue Object key or valid ({@see MetaModel::IsValidObject()}) datamodel object
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return 0;
|
||||
}
|
||||
if ($proposedValue === '') {
|
||||
return 0;
|
||||
}
|
||||
if (MetaModel::IsValidObject($proposedValue)) {
|
||||
return $proposedValue->GetKey();
|
||||
}
|
||||
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Dict;
|
||||
use Exception;
|
||||
|
||||
class AttributeObsolescenceDate extends AttributeDate
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceDate/Label', $sDefault);
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceDate/Label', $sDefault);
|
||||
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceDate/Label+', $sDefault);
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceDate/Label+', $sDefault);
|
||||
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +1,134 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
|
||||
class AttributeObsolescenceFlag extends AttributeBoolean
|
||||
{
|
||||
public function __construct($sCode)
|
||||
{
|
||||
parent::__construct($sCode, array(
|
||||
"allowed_values" => null,
|
||||
"sql" => $sCode,
|
||||
"default_value" => "",
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array()
|
||||
));
|
||||
}
|
||||
public function __construct($sCode)
|
||||
{
|
||||
parent::__construct($sCode, array(
|
||||
"allowed_values" => null,
|
||||
"sql" => $sCode,
|
||||
"default_value" => "",
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array(),
|
||||
));
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsMagic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the attribute value is built after other attributes by the mean of an expression (obtained via
|
||||
* GetOQLExpression)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsBasedOnOQLExpression()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Returns true if the attribute value is built after other attributes by the mean of an expression (obtained via
|
||||
* GetOQLExpression)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsBasedOnOQLExpression()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetOQLExpression()
|
||||
{
|
||||
return MetaModel::GetObsolescenceExpression($this->GetHostClass());
|
||||
}
|
||||
public function GetOQLExpression()
|
||||
{
|
||||
return MetaModel::GetObsolescenceExpression($this->GetHostClass());
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
return array();
|
||||
} // returns column/spec pairs (1 in most of the cases), for STRUCTURING (DB creation)
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
return array();
|
||||
} // returns column/spec pairs (1 in most of the cases), for STRUCTURING (DB creation)
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
return array();
|
||||
} // returns column/value pairs (1 in most of the cases), for WRITING (Insert, Update)
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
return array();
|
||||
} // returns column/value pairs (1 in most of the cases), for WRITING (Insert, Update)
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
// Code duplicated with AttributeFriendlyName
|
||||
$aAttributes = $this->GetOptional("depends_on", array());
|
||||
$oExpression = $this->GetOQLExpression();
|
||||
foreach ($oExpression->ListRequiredFields() as $sClass => $sAttCode) {
|
||||
if (!in_array($sAttCode, $aAttributes)) {
|
||||
$aAttributes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
return $aAttributes;
|
||||
}
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
// Code duplicated with AttributeFriendlyName
|
||||
$aAttributes = $this->GetOptional("depends_on", array());
|
||||
$oExpression = $this->GetOQLExpression();
|
||||
foreach ($oExpression->ListRequiredFields() as $sClass => $sAttCode) {
|
||||
if (!in_array($sAttCode, $aAttributes)) {
|
||||
$aAttributes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
|
||||
public function IsDirectField()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return $aAttributes;
|
||||
}
|
||||
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsDirectField()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetSQLExpr()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->MakeRealValue(false, $oHostObject);
|
||||
}
|
||||
public function GetSQLExpr()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return $this->MakeRealValue(false, $oHostObject);
|
||||
}
|
||||
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceFlag/Label', $sDefault);
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceFlag/Label', $sDefault);
|
||||
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceFlag/Label+', $sDefault);
|
||||
return parent::GetLabel($sDefault);
|
||||
}
|
||||
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sDefault = Dict::S('Core:AttributeObsolescenceFlag/Label+', $sDefault);
|
||||
|
||||
return parent::GetDescription($sDefault);
|
||||
}
|
||||
}
|
||||
@@ -1,233 +1,247 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOp;
|
||||
use CMDBChangeOpSetAttributeOneWayPassword;
|
||||
use CMDBSource;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use ormPassword;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* One way encrypted (hashed) password
|
||||
*/
|
||||
class AttributeOneWayPassword extends AttributeDefinition implements iAttributeNoGroupBy
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("depends_on"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("depends_on"));
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "One Way Password";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "One Way Password";
|
||||
}
|
||||
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->GetOptional("is_null_allowed", false);
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->GetOptional("is_null_allowed", false);
|
||||
}
|
||||
|
||||
// Facilitate things: allow the user to Set the value from a string or from an ormPassword (already encrypted)
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
$oPassword = $proposedValue;
|
||||
if (is_object($oPassword)) {
|
||||
$oPassword = clone $proposedValue;
|
||||
} else {
|
||||
$oPassword = new ormPassword('', '');
|
||||
$oPassword->SetPassword($proposedValue);
|
||||
}
|
||||
// Facilitate things: allow the user to Set the value from a string or from an ormPassword (already encrypted)
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
$oPassword = $proposedValue;
|
||||
if (is_object($oPassword)) {
|
||||
$oPassword = clone $proposedValue;
|
||||
} else {
|
||||
$oPassword = new ormPassword('', '');
|
||||
$oPassword->SetPassword($proposedValue);
|
||||
}
|
||||
|
||||
return $oPassword;
|
||||
}
|
||||
return $oPassword;
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->GetCode(); // Warning: AttributeOneWayPassword does not have any sql property so code = sql !
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix . '_hash';
|
||||
$aColumns['_salt'] = $sPrefix . '_salt';
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->GetCode(); // Warning: AttributeOneWayPassword does not have any sql property so code = sql !
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix.'_hash';
|
||||
$aColumns['_salt'] = $sPrefix.'_salt';
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!array_key_exists($sPrefix, $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$hashed = isset($aCols[$sPrefix]) ? $aCols[$sPrefix] : '';
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!array_key_exists($sPrefix, $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$hashed = isset($aCols[$sPrefix]) ? $aCols[$sPrefix] : '';
|
||||
|
||||
if (!array_key_exists($sPrefix . '_salt', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '" . $sPrefix . "_salt' from {$sAvailable}");
|
||||
}
|
||||
$sSalt = isset($aCols[$sPrefix . '_salt']) ? $aCols[$sPrefix . '_salt'] : '';
|
||||
if (!array_key_exists($sPrefix.'_salt', $aCols)) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '".$sPrefix."_salt' from {$sAvailable}");
|
||||
}
|
||||
$sSalt = isset($aCols[$sPrefix.'_salt']) ? $aCols[$sPrefix.'_salt'] : '';
|
||||
|
||||
$value = new ormPassword($hashed, $sSalt);
|
||||
$value = new ormPassword($hashed, $sSalt);
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
// #@# Optimization: do not load blobs anytime
|
||||
// As per mySQL doc, selecting blob columns will prevent mySQL from
|
||||
// using memory in case a temporary table has to be created
|
||||
// (temporary tables created on disk)
|
||||
// We will have to remove the blobs from the list of attributes when doing the select
|
||||
// then the use of Get() should finalize the load
|
||||
if ($value instanceof ormPassword) {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode() . '_hash'] = $value->GetHash();
|
||||
$aValues[$this->GetCode() . '_salt'] = $value->GetSalt();
|
||||
} else {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode() . '_hash'] = '';
|
||||
$aValues[$this->GetCode() . '_salt'] = '';
|
||||
}
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
// #@# Optimization: do not load blobs anytime
|
||||
// As per mySQL doc, selecting blob columns will prevent mySQL from
|
||||
// using memory in case a temporary table has to be created
|
||||
// (temporary tables created on disk)
|
||||
// We will have to remove the blobs from the list of attributes when doing the select
|
||||
// then the use of Get() should finalize the load
|
||||
if ($value instanceof ormPassword) {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode().'_hash'] = $value->GetHash();
|
||||
$aValues[$this->GetCode().'_salt'] = $value->GetSalt();
|
||||
} else {
|
||||
$aValues = array();
|
||||
$aValues[$this->GetCode().'_hash'] = '';
|
||||
$aValues[$this->GetCode().'_salt'] = '';
|
||||
}
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode() . '_hash'] = 'TINYBLOB';
|
||||
$aColumns[$this->GetCode() . '_salt'] = 'TINYBLOB';
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode().'_hash'] = 'TINYBLOB';
|
||||
$aColumns[$this->GetCode().'_salt'] = 'TINYBLOB';
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetImportColumns()
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'TINYTEXT' . CMDBSource::GetSqlStringColumnDefinition();
|
||||
public function GetImportColumns()
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->GetCode()] = 'TINYTEXT'.CMDBSource::GetSqlStringColumnDefinition();
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function FromImportToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!isset($aCols[$sPrefix])) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$sClearPwd = $aCols[$sPrefix];
|
||||
public function FromImportToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
if (!isset($aCols[$sPrefix])) {
|
||||
$sAvailable = implode(', ', array_keys($aCols));
|
||||
throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
|
||||
}
|
||||
$sClearPwd = $aCols[$sPrefix];
|
||||
|
||||
$oPassword = new ormPassword('', '');
|
||||
$oPassword->SetPassword($sClearPwd);
|
||||
$oPassword = new ormPassword('', '');
|
||||
$oPassword->SetPassword($sClearPwd);
|
||||
|
||||
return $oPassword;
|
||||
}
|
||||
return $oPassword;
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return '=';
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return 'true';
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
return 'true';
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $value->GetAsHTML();
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $value->GetAsHTML();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
return ''; // Not exportable in CSV
|
||||
}
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
return ''; // Not exportable in CSV
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return ''; // Not exportable in XML
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return ''; // Not exportable in XML
|
||||
}
|
||||
|
||||
public function GetValueLabel($sValue, $oHostObj = null)
|
||||
{
|
||||
// Don't display anything in "group by" reports
|
||||
return '*****';
|
||||
}
|
||||
public function GetValueLabel($sValue, $oHostObj = null)
|
||||
{
|
||||
// Don't display anything in "group by" reports
|
||||
return '*****';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Protection against wrong value type
|
||||
if (false === ($proposedValue instanceof ormPassword)) {
|
||||
// On object creation, the attribute value is "" instead of an ormPassword...
|
||||
if (is_string($proposedValue)) {
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
// Protection against wrong value type
|
||||
if (false === ($proposedValue instanceof ormPassword)) {
|
||||
// On object creation, the attribute value is "" instead of an ormPassword...
|
||||
if (is_string($proposedValue)) {
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
|
||||
return $proposedValue->IsEmpty() === false;
|
||||
}
|
||||
return $proposedValue->IsEmpty() === false;
|
||||
}
|
||||
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
if (is_null($original)) {
|
||||
$original = '';
|
||||
}
|
||||
$oMyChangeOp->Set("prev_pwd", $original);
|
||||
}
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
if (is_null($original)) {
|
||||
$original = '';
|
||||
}
|
||||
$oMyChangeOp->Set("prev_pwd", $original);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeOneWayPassword::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeOneWayPassword::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use Exception;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Map a varchar column (size < ?) to an attribute that must never be shown to the user
|
||||
@@ -7,59 +17,59 @@
|
||||
*/
|
||||
class AttributePassword extends AttributeString implements iAttributeNoGroupBy
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Password";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Password";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "VARCHAR(64)"
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "VARCHAR(64)"
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (utils::IsNullOrEmptyString($sValue)) {
|
||||
return '';
|
||||
} else {
|
||||
return '******';
|
||||
}
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (utils::IsNullOrEmptyString($sValue)) {
|
||||
return '';
|
||||
} else {
|
||||
return '******';
|
||||
}
|
||||
}
|
||||
|
||||
public function IsPartOfFingerprint()
|
||||
{
|
||||
return false;
|
||||
} // Cannot reliably compare two encrypted passwords since the same password will be encrypted in diffferent manners depending on the random 'salt'
|
||||
public function IsPartOfFingerprint()
|
||||
{
|
||||
return false;
|
||||
} // Cannot reliably compare two encrypted passwords since the same password will be encrypted in diffferent manners depending on the random 'salt'
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Display an integer between 0 and 100 as a percentage / horizontal bar graph
|
||||
@@ -7,47 +15,47 @@
|
||||
*/
|
||||
class AttributePercentage extends AttributeInteger
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_NUMERIC;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_NUMERIC;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$iWidth = 5; // Total width of the percentage bar graph, in em...
|
||||
$iValue = (int)$sValue;
|
||||
if ($iValue > 100) {
|
||||
$iValue = 100;
|
||||
} else {
|
||||
if ($iValue < 0) {
|
||||
$iValue = 0;
|
||||
}
|
||||
}
|
||||
if ($iValue > 90) {
|
||||
$sColor = "#cc3300";
|
||||
} else {
|
||||
if ($iValue > 50) {
|
||||
$sColor = "#cccc00";
|
||||
} else {
|
||||
$sColor = "#33cc00";
|
||||
}
|
||||
}
|
||||
$iPercentWidth = ($iWidth * $iValue) / 100;
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$iWidth = 5; // Total width of the percentage bar graph, in em...
|
||||
$iValue = (int)$sValue;
|
||||
if ($iValue > 100) {
|
||||
$iValue = 100;
|
||||
} else {
|
||||
if ($iValue < 0) {
|
||||
$iValue = 0;
|
||||
}
|
||||
}
|
||||
if ($iValue > 90) {
|
||||
$sColor = "#cc3300";
|
||||
} else {
|
||||
if ($iValue > 50) {
|
||||
$sColor = "#cccc00";
|
||||
} else {
|
||||
$sColor = "#33cc00";
|
||||
}
|
||||
}
|
||||
$iPercentWidth = ($iWidth * $iValue) / 100;
|
||||
|
||||
return "<div style=\"width:{$iWidth}em;-moz-border-radius: 3px;-webkit-border-radius: 3px;border-radius: 3px;display:inline-block;border: 1px #ccc solid;\"><div style=\"width:{$iPercentWidth}em; display:inline-block;background-color:$sColor;\"> </div></div> $sValue %";
|
||||
}
|
||||
return "<div style=\"width:{$iWidth}em;-moz-border-radius: 3px;-webkit-border-radius: 3px;border-radius: 3px;display:inline-block;border: 1px #ccc solid;\"><div style=\"width:{$iPercentWidth}em; display:inline-block;background-color:$sColor;\"> </div></div> $sValue %";
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Specialization of a string: phone number
|
||||
@@ -7,45 +16,45 @@
|
||||
*/
|
||||
class AttributePhoneNumber extends AttributeString
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return $this->GetOptional('validation_pattern',
|
||||
'^' . utils::GetConfig()->Get('phone_number_validation_pattern') . '$');
|
||||
}
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return $this->GetOptional('validation_pattern',
|
||||
'^'.utils::GetConfig()->Get('phone_number_validation_pattern').'$');
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\PhoneField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\PhoneField';
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$sUrlDecorationClass = utils::GetConfig()->Get('phone_number_decoration_class');
|
||||
$sUrlPattern = utils::GetConfig()->Get('phone_number_url_pattern');
|
||||
$sUrl = sprintf($sUrlPattern, $sValue);
|
||||
$sUrlDecorationClass = utils::GetConfig()->Get('phone_number_decoration_class');
|
||||
$sUrlPattern = utils::GetConfig()->Get('phone_number_url_pattern');
|
||||
$sUrl = sprintf($sUrlPattern, $sValue);
|
||||
|
||||
return '<a class="tel" href="' . $sUrl . '"><span class="text_decoration ' . $sUrlDecorationClass . '"></span>' . parent::GetAsHTML($sValue) . '</a>';
|
||||
}
|
||||
return '<a class="tel" href="'.$sUrl.'"><span class="text_decoration '.$sUrlDecorationClass.'"></span>'.parent::GetAsHTML($sValue).'</a>';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,108 +1,118 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CoreException;
|
||||
use Exception;
|
||||
use Str;
|
||||
|
||||
class AttributePropertySet extends AttributeTable
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "PropertySet";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "PropertySet";
|
||||
}
|
||||
|
||||
// Facilitate things: allow the user to Set the value from a string
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (!is_array($proposedValue)) {
|
||||
return array('?' => (string)$proposedValue);
|
||||
}
|
||||
// Facilitate things: allow the user to Set the value from a string
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (!is_array($proposedValue)) {
|
||||
return array('?' => (string)$proposedValue);
|
||||
}
|
||||
|
||||
return $proposedValue;
|
||||
}
|
||||
return $proposedValue;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException('Expecting an array', array('found' => get_class($value)));
|
||||
}
|
||||
if (count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException('Expecting an array', array('found' => get_class($value)));
|
||||
}
|
||||
if (count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$sRes = "<TABLE class=\"listResults\">";
|
||||
$sRes .= "<TBODY>";
|
||||
foreach ($value as $sProperty => $sValue) {
|
||||
if ($sProperty == 'auth_pwd') {
|
||||
$sValue = '*****';
|
||||
}
|
||||
$sRes .= "<TR>";
|
||||
$sCell = str_replace("\n", "<br>\n", Str::pure2html(@(string)$sValue));
|
||||
$sRes .= "<TD class=\"label\">$sProperty</TD><TD>$sCell</TD>";
|
||||
$sRes .= "</TR>";
|
||||
}
|
||||
$sRes .= "</TBODY>";
|
||||
$sRes .= "</TABLE>";
|
||||
$sRes = "<TABLE class=\"listResults\">";
|
||||
$sRes .= "<TBODY>";
|
||||
foreach ($value as $sProperty => $sValue) {
|
||||
if ($sProperty == 'auth_pwd') {
|
||||
$sValue = '*****';
|
||||
}
|
||||
$sRes .= "<TR>";
|
||||
$sCell = str_replace("\n", "<br>\n", Str::pure2html(@(string)$sValue));
|
||||
$sRes .= "<TD class=\"label\">$sProperty</TD><TD>$sCell</TD>";
|
||||
$sRes .= "</TR>";
|
||||
}
|
||||
$sRes .= "</TBODY>";
|
||||
$sRes .= "</TABLE>";
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (!is_array($value) || count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
if (!is_array($value) || count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$aRes = array();
|
||||
foreach ($value as $sProperty => $sValue) {
|
||||
if ($sProperty == 'auth_pwd') {
|
||||
$sValue = '*****';
|
||||
}
|
||||
$sFrom = array(',', '=');
|
||||
$sTo = array('\,', '\=');
|
||||
$aRes[] = $sProperty . '=' . str_replace($sFrom, $sTo, (string)$sValue);
|
||||
}
|
||||
$sRaw = implode(',', $aRes);
|
||||
$aRes = array();
|
||||
foreach ($value as $sProperty => $sValue) {
|
||||
if ($sProperty == 'auth_pwd') {
|
||||
$sValue = '*****';
|
||||
}
|
||||
$sFrom = array(',', '=');
|
||||
$sTo = array('\,', '\=');
|
||||
$aRes[] = $sProperty.'='.str_replace($sFrom, $sTo, (string)$sValue);
|
||||
}
|
||||
$sRaw = implode(',', $aRes);
|
||||
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, $sRaw);
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, $sRaw);
|
||||
|
||||
return $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
}
|
||||
return $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value) || count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value) || count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$sRes = "";
|
||||
foreach ($value as $sProperty => $sValue) {
|
||||
if ($sProperty == 'auth_pwd') {
|
||||
$sValue = '*****';
|
||||
}
|
||||
$sRes .= "<property id=\"$sProperty\">";
|
||||
$sRes .= Str::pure2xml((string)$sValue);
|
||||
$sRes .= "</property>";
|
||||
}
|
||||
$sRes = "";
|
||||
foreach ($value as $sProperty => $sValue) {
|
||||
if ($sProperty == 'auth_pwd') {
|
||||
$sValue = '*****';
|
||||
}
|
||||
$sRes .= "<property id=\"$sProperty\">";
|
||||
$sRes .= Str::pure2xml((string)$sValue);
|
||||
$sRes .= "</property>";
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
}
|
||||
@@ -1,169 +1,191 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use CoreException;
|
||||
use CoreUnexpectedValue;
|
||||
use DBSearch;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
use MetaModel;
|
||||
use OQLException;
|
||||
use ormSet;
|
||||
use utils;
|
||||
|
||||
class AttributeQueryAttCodeSet extends AttributeSet
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
public function __construct($sCode, array $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
$this->aCSSClasses[] = 'attribute-query-attcode-set';
|
||||
}
|
||||
public function __construct($sCode, array $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
$this->aCSSClasses[] = 'attribute-query-attcode-set';
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('query_field'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('query_field'));
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TEXT" . CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TEXT".CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 65535;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 65535;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a class array indexed by alias
|
||||
* @param $oHostObj
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function GetClassList($oHostObj)
|
||||
{
|
||||
try {
|
||||
$sQueryField = $this->Get('query_field');
|
||||
$sQuery = $oHostObj->Get($sQueryField);
|
||||
if (empty($sQuery)) {
|
||||
return array();
|
||||
}
|
||||
$oFilter = DBSearch::FromOQL($sQuery);
|
||||
return $oFilter->GetSelectedClasses();
|
||||
/**
|
||||
* Get a class array indexed by alias
|
||||
*
|
||||
* @param $oHostObj
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function GetClassList($oHostObj)
|
||||
{
|
||||
try {
|
||||
$sQueryField = $this->Get('query_field');
|
||||
$sQuery = $oHostObj->Get($sQueryField);
|
||||
if (empty($sQuery)) {
|
||||
return array();
|
||||
}
|
||||
$oFilter = DBSearch::FromOQL($sQuery);
|
||||
|
||||
} catch (OQLException $e) {
|
||||
IssueLog::Warning($e->getMessage());
|
||||
}
|
||||
return array();
|
||||
}
|
||||
return $oFilter->GetSelectedClasses();
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (isset($aArgs['this'])) {
|
||||
$oHostObj = $aArgs['this'];
|
||||
$aClasses = $this->GetClassList($oHostObj);
|
||||
}
|
||||
catch (OQLException $e) {
|
||||
IssueLog::Warning($e->getMessage());
|
||||
}
|
||||
|
||||
$aAllowedAttributes = array();
|
||||
$aAllAttributes = array();
|
||||
return array();
|
||||
}
|
||||
|
||||
if ((count($aClasses) == 1) && (array_keys($aClasses)[0] == array_values($aClasses)[0])) {
|
||||
$sClass = reset($aClasses);
|
||||
$aAttributes = MetaModel::GetAttributesList($sClass);
|
||||
foreach ($aAttributes as $sAttCode) {
|
||||
$aAllowedAttributes[$sAttCode] = "$sAttCode (" . MetaModel::GetLabel($sClass, $sAttCode) . ')';
|
||||
}
|
||||
} else {
|
||||
if (!empty($aClasses)) {
|
||||
ksort($aClasses);
|
||||
foreach ($aClasses as $sAlias => $sClass) {
|
||||
$aAttributes = MetaModel::GetAttributesList($sClass);
|
||||
foreach ($aAttributes as $sAttCode) {
|
||||
$aAllAttributes[] = array('alias' => $sAlias, 'class' => $sClass, 'att_code' => $sAttCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($aAllAttributes as $aFullAttCode) {
|
||||
$sAttCode = $aFullAttCode['alias'] . '.' . $aFullAttCode['att_code'];
|
||||
$sClass = $aFullAttCode['class'];
|
||||
$sLabel = "$sAttCode (" . MetaModel::GetLabel($sClass, $aFullAttCode['att_code']) . ')';
|
||||
$aAllowedAttributes[$sAttCode] = $sLabel;
|
||||
}
|
||||
}
|
||||
return $aAllowedAttributes;
|
||||
}
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (isset($aArgs['this'])) {
|
||||
$oHostObj = $aArgs['this'];
|
||||
$aClasses = $this->GetClassList($oHostObj);
|
||||
|
||||
return null;
|
||||
}
|
||||
$aAllowedAttributes = array();
|
||||
$aAllAttributes = array();
|
||||
|
||||
/**
|
||||
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @param bool $bIgnoreErrors
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \OQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||
{
|
||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
$aArgs = array();
|
||||
if (!empty($oHostObj)) {
|
||||
$aArgs['this'] = $oHostObj;
|
||||
}
|
||||
$aAllowedAttributes = $this->GetAllowedValues($aArgs);
|
||||
$aInvalidAttCodes = array();
|
||||
if (is_string($proposedValue) && !empty($proposedValue)) {
|
||||
$proposedValue = trim($proposedValue);
|
||||
$aProposedValues = $this->FromStringToArray($proposedValue);
|
||||
$aValues = array();
|
||||
foreach ($aProposedValues as $sValue) {
|
||||
$sAttCode = trim($sValue);
|
||||
if (empty($aAllowedAttributes) || isset($aAllowedAttributes[$sAttCode])) {
|
||||
$aValues[$sAttCode] = $sAttCode;
|
||||
} else {
|
||||
$aInvalidAttCodes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
$oSet->SetValues($aValues);
|
||||
} elseif ($proposedValue instanceof ormSet) {
|
||||
$oSet = $proposedValue;
|
||||
}
|
||||
if (!empty($aInvalidAttCodes) && !$bIgnoreErrors) {
|
||||
throw new CoreUnexpectedValue("The attribute(s) " . implode(', ', $aInvalidAttCodes) . " are invalid");
|
||||
}
|
||||
if ((count($aClasses) == 1) && (array_keys($aClasses)[0] == array_values($aClasses)[0])) {
|
||||
$sClass = reset($aClasses);
|
||||
$aAttributes = MetaModel::GetAttributesList($sClass);
|
||||
foreach ($aAttributes as $sAttCode) {
|
||||
$aAllowedAttributes[$sAttCode] = "$sAttCode (".MetaModel::GetLabel($sClass, $sAttCode).')';
|
||||
}
|
||||
} else {
|
||||
if (!empty($aClasses)) {
|
||||
ksort($aClasses);
|
||||
foreach ($aClasses as $sAlias => $sClass) {
|
||||
$aAttributes = MetaModel::GetAttributesList($sClass);
|
||||
foreach ($aAttributes as $sAttCode) {
|
||||
$aAllAttributes[] = array('alias' => $sAlias, 'class' => $sClass, 'att_code' => $sAttCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($aAllAttributes as $aFullAttCode) {
|
||||
$sAttCode = $aFullAttCode['alias'].'.'.$aFullAttCode['att_code'];
|
||||
$sClass = $aFullAttCode['class'];
|
||||
$sLabel = "$sAttCode (".MetaModel::GetLabel($sClass, $aFullAttCode['att_code']).')';
|
||||
$aAllowedAttributes[$sAttCode] = $sLabel;
|
||||
}
|
||||
}
|
||||
|
||||
return $oSet;
|
||||
}
|
||||
return $aAllowedAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
if (!empty($oHostObject) && $bLocalize) {
|
||||
$aArgs['this'] = $oHostObject;
|
||||
$aAllowedAttributes = $this->GetAllowedValues($aArgs);
|
||||
/**
|
||||
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param DBObject $oHostObj
|
||||
*
|
||||
* @param bool $bIgnoreErrors
|
||||
*
|
||||
* @return mixed
|
||||
* @throws CoreException
|
||||
* @throws CoreUnexpectedValue
|
||||
* @throws OQLException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||
{
|
||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
$aArgs = array();
|
||||
if (!empty($oHostObj)) {
|
||||
$aArgs['this'] = $oHostObj;
|
||||
}
|
||||
$aAllowedAttributes = $this->GetAllowedValues($aArgs);
|
||||
$aInvalidAttCodes = array();
|
||||
if (is_string($proposedValue) && !empty($proposedValue)) {
|
||||
$proposedValue = trim($proposedValue);
|
||||
$aProposedValues = $this->FromStringToArray($proposedValue);
|
||||
$aValues = array();
|
||||
foreach ($aProposedValues as $sValue) {
|
||||
$sAttCode = trim($sValue);
|
||||
if (empty($aAllowedAttributes) || isset($aAllowedAttributes[$sAttCode])) {
|
||||
$aValues[$sAttCode] = $sAttCode;
|
||||
} else {
|
||||
$aInvalidAttCodes[] = $sAttCode;
|
||||
}
|
||||
}
|
||||
$oSet->SetValues($aValues);
|
||||
} elseif ($proposedValue instanceof ormSet) {
|
||||
$oSet = $proposedValue;
|
||||
}
|
||||
if (!empty($aInvalidAttCodes) && !$bIgnoreErrors) {
|
||||
throw new CoreUnexpectedValue("The attribute(s) ".implode(', ', $aInvalidAttCodes)." are invalid");
|
||||
}
|
||||
|
||||
$aLocalizedValues = array();
|
||||
foreach ($value as $sAttCode) {
|
||||
if (isset($aAllowedAttributes[$sAttCode])) {
|
||||
$sLabelForHtmlAttribute = utils::HtmlEntities($aAllowedAttributes[$sAttCode]);
|
||||
$aLocalizedValues[] = '<span class="attribute-set-item" data-code="' . $sAttCode . '" data-label="' . $sLabelForHtmlAttribute . '" data-description="" data-tooltip-content="' . $sLabelForHtmlAttribute . '">' . $sAttCode . '</span>';
|
||||
}
|
||||
}
|
||||
$value = $aLocalizedValues;
|
||||
}
|
||||
$value = implode('', $value);
|
||||
}
|
||||
return $oSet;
|
||||
}
|
||||
|
||||
return '<span class="' . implode(' ', $this->aCSSClasses) . '">' . $value . '</span>';
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
if (!empty($oHostObject) && $bLocalize) {
|
||||
$aArgs['this'] = $oHostObject;
|
||||
$aAllowedAttributes = $this->GetAllowedValues($aArgs);
|
||||
|
||||
$aLocalizedValues = array();
|
||||
foreach ($value as $sAttCode) {
|
||||
if (isset($aAllowedAttributes[$sAttCode])) {
|
||||
$sLabelForHtmlAttribute = utils::HtmlEntities($aAllowedAttributes[$sAttCode]);
|
||||
$aLocalizedValues[] = '<span class="attribute-set-item" data-code="'.$sAttCode.'" data-label="'.$sLabelForHtmlAttribute.'" data-description="" data-tooltip-content="'.$sLabelForHtmlAttribute.'">'.$sAttCode.'</span>';
|
||||
}
|
||||
}
|
||||
$value = $aLocalizedValues;
|
||||
}
|
||||
$value = implode('', $value);
|
||||
}
|
||||
|
||||
return '<span class="'.implode(' ', $this->aCSSClasses).'">'.$value.'</span>';
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
use CoreException;
|
||||
use DBObject;
|
||||
use DictExceptionMissingString;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Holds the setting for the redundancy on a specific relation
|
||||
@@ -11,435 +26,435 @@
|
||||
*/
|
||||
class AttributeRedundancySettings extends AttributeDBField
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array(
|
||||
'sql',
|
||||
'relation_code',
|
||||
'from_class',
|
||||
'neighbour_id',
|
||||
'enabled',
|
||||
'enabled_mode',
|
||||
'min_up',
|
||||
'min_up_type',
|
||||
'min_up_mode'
|
||||
);
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array(
|
||||
'sql',
|
||||
'relation_code',
|
||||
'from_class',
|
||||
'neighbour_id',
|
||||
'enabled',
|
||||
'enabled_mode',
|
||||
'min_up',
|
||||
'min_up_type',
|
||||
'min_up_mode',
|
||||
);
|
||||
}
|
||||
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetPrerequisiteAttributes($sClass = null)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "RedundancySetting";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "RedundancySetting";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "VARCHAR(20)"
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "VARCHAR(20)"
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return "^[0-9]{1,3}|[0-9]{1,2}%|disabled$";
|
||||
}
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return "^[0-9]{1,3}|[0-9]{1,2}%|disabled$";
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
$sRet = 'disabled';
|
||||
if ($this->Get('enabled')) {
|
||||
if ($this->Get('min_up_type') == 'count') {
|
||||
$sRet = (string)$this->Get('min_up');
|
||||
} else // percent
|
||||
{
|
||||
$sRet = $this->Get('min_up') . '%';
|
||||
}
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
$sRet = 'disabled';
|
||||
if ($this->Get('enabled')) {
|
||||
if ($this->Get('min_up_type') == 'count') {
|
||||
$sRet = (string)$this->Get('min_up');
|
||||
} else // percent
|
||||
{
|
||||
$sRet = $this->Get('min_up').'%';
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == '');
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == '');
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return '';
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (string)$proposedValue;
|
||||
}
|
||||
return (string)$proposedValue;
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
throw new CoreException('Expected the attribute value to be a string', array(
|
||||
'found_type' => gettype($value),
|
||||
'value' => $value,
|
||||
'class' => $this->GetHostClass(),
|
||||
'attribute' => $this->GetCode()
|
||||
));
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
throw new CoreException('Expected the attribute value to be a string', array(
|
||||
'found_type' => gettype($value),
|
||||
'value' => $value,
|
||||
'class' => $this->GetHostClass(),
|
||||
'attribute' => $this->GetCode(),
|
||||
));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetRelationQueryData()
|
||||
{
|
||||
foreach (MetaModel::EnumRelationQueries($this->GetHostClass(), $this->Get('relation_code'),
|
||||
false) as $sDummy => $aQueryInfo) {
|
||||
if ($aQueryInfo['sFromClass'] == $this->Get('from_class')) {
|
||||
if ($aQueryInfo['sNeighbour'] == $this->Get('neighbour_id')) {
|
||||
return $aQueryInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
public function GetRelationQueryData()
|
||||
{
|
||||
foreach (MetaModel::EnumRelationQueries($this->GetHostClass(), $this->Get('relation_code'),
|
||||
false) as $sDummy => $aQueryInfo) {
|
||||
if ($aQueryInfo['sFromClass'] == $this->Get('from_class')) {
|
||||
if ($aQueryInfo['sNeighbour'] == $this->Get('neighbour_id')) {
|
||||
return $aQueryInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the user option label
|
||||
*
|
||||
* @param string $sUserOption possible values : disabled|cout|percent
|
||||
* @param string $sDefault
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetUserOptionFormat($sUserOption, $sDefault = null)
|
||||
{
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/' . $sUserOption, null, true /*user lang*/);
|
||||
if (is_null($sLabel)) {
|
||||
// If no default value is specified, let's define the most relevant one for developping purposes
|
||||
if (is_null($sDefault)) {
|
||||
$sDefault = str_replace('_', ' ', $this->m_sCode . ':' . $sUserOption . '(%1$s)');
|
||||
}
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:' . $this->m_sCode . '/' . $sUserOption, $sDefault, false);
|
||||
}
|
||||
/**
|
||||
* Find the user option label
|
||||
*
|
||||
* @param string $sUserOption possible values : disabled|cout|percent
|
||||
* @param string $sDefault
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetUserOptionFormat($sUserOption, $sDefault = null)
|
||||
{
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/'.$sUserOption, null, true /*user lang*/);
|
||||
if (is_null($sLabel)) {
|
||||
// If no default value is specified, let's define the most relevant one for developping purposes
|
||||
if (is_null($sDefault)) {
|
||||
$sDefault = str_replace('_', ' ', $this->m_sCode.':'.$sUserOption.'(%1$s)');
|
||||
}
|
||||
// Browse the hierarchy again, accepting default (english) translations
|
||||
$sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/'.$sUserOption, $sDefault, false);
|
||||
}
|
||||
|
||||
return $sLabel;
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to display the value in the GUI
|
||||
*
|
||||
* @param string $sValue
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sCurrentOption = $this->GetCurrentOption($sValue);
|
||||
$sClass = $oHostObject ? get_class($oHostObject) : $this->m_sHostClass;
|
||||
/**
|
||||
* Override to display the value in the GUI
|
||||
*
|
||||
* @param string $sValue
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string
|
||||
* @throws CoreException
|
||||
* @throws DictExceptionMissingString
|
||||
*/
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sCurrentOption = $this->GetCurrentOption($sValue);
|
||||
$sClass = $oHostObject ? get_class($oHostObject) : $this->m_sHostClass;
|
||||
|
||||
return sprintf($this->GetUserOptionFormat($sCurrentOption), $this->GetMinUpValue($sValue),
|
||||
MetaModel::GetName($sClass));
|
||||
}
|
||||
return sprintf($this->GetUserOptionFormat($sCurrentOption), $this->GetMinUpValue($sValue),
|
||||
MetaModel::GetName($sClass));
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
|
||||
return $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
}
|
||||
return $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to interpret the value, given the current settings and string representation of the attribute
|
||||
*/
|
||||
public function IsEnabled($sValue)
|
||||
{
|
||||
if ($this->get('enabled_mode') == 'fixed') {
|
||||
$bRet = $this->get('enabled');
|
||||
} else {
|
||||
$bRet = ($sValue != 'disabled');
|
||||
}
|
||||
/**
|
||||
* Helper to interpret the value, given the current settings and string representation of the attribute
|
||||
*/
|
||||
public function IsEnabled($sValue)
|
||||
{
|
||||
if ($this->get('enabled_mode') == 'fixed') {
|
||||
$bRet = $this->get('enabled');
|
||||
} else {
|
||||
$bRet = ($sValue != 'disabled');
|
||||
}
|
||||
|
||||
return $bRet;
|
||||
}
|
||||
return $bRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to interpret the value, given the current settings and string representation of the attribute
|
||||
*/
|
||||
public function GetMinUpType($sValue)
|
||||
{
|
||||
if ($this->get('min_up_mode') == 'fixed') {
|
||||
$sRet = $this->get('min_up_type');
|
||||
} else {
|
||||
$sRet = 'count';
|
||||
if (substr(trim($sValue), -1, 1) == '%') {
|
||||
$sRet = 'percent';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Helper to interpret the value, given the current settings and string representation of the attribute
|
||||
*/
|
||||
public function GetMinUpType($sValue)
|
||||
{
|
||||
if ($this->get('min_up_mode') == 'fixed') {
|
||||
$sRet = $this->get('min_up_type');
|
||||
} else {
|
||||
$sRet = 'count';
|
||||
if (substr(trim($sValue), -1, 1) == '%') {
|
||||
$sRet = 'percent';
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to interpret the value, given the current settings and string representation of the attribute
|
||||
*/
|
||||
public function GetMinUpValue($sValue)
|
||||
{
|
||||
if ($this->get('min_up_mode') == 'fixed') {
|
||||
$iRet = (int)$this->Get('min_up');
|
||||
} else {
|
||||
$sRefValue = $sValue;
|
||||
if (substr(trim($sValue), -1, 1) == '%') {
|
||||
$sRefValue = substr(trim($sValue), 0, -1);
|
||||
}
|
||||
$iRet = (int)trim($sRefValue);
|
||||
}
|
||||
/**
|
||||
* Helper to interpret the value, given the current settings and string representation of the attribute
|
||||
*/
|
||||
public function GetMinUpValue($sValue)
|
||||
{
|
||||
if ($this->get('min_up_mode') == 'fixed') {
|
||||
$iRet = (int)$this->Get('min_up');
|
||||
} else {
|
||||
$sRefValue = $sValue;
|
||||
if (substr(trim($sValue), -1, 1) == '%') {
|
||||
$sRefValue = substr(trim($sValue), 0, -1);
|
||||
}
|
||||
$iRet = (int)trim($sRefValue);
|
||||
}
|
||||
|
||||
return $iRet;
|
||||
}
|
||||
return $iRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to determine if the redundancy can be viewed/edited by the end-user
|
||||
*/
|
||||
public function IsVisible()
|
||||
{
|
||||
$bRet = false;
|
||||
if ($this->Get('enabled_mode') == 'fixed') {
|
||||
$bRet = $this->Get('enabled');
|
||||
} elseif ($this->Get('enabled_mode') == 'user') {
|
||||
$bRet = true;
|
||||
}
|
||||
/**
|
||||
* Helper to determine if the redundancy can be viewed/edited by the end-user
|
||||
*/
|
||||
public function IsVisible()
|
||||
{
|
||||
$bRet = false;
|
||||
if ($this->Get('enabled_mode') == 'fixed') {
|
||||
$bRet = $this->Get('enabled');
|
||||
} elseif ($this->Get('enabled_mode') == 'user') {
|
||||
$bRet = true;
|
||||
}
|
||||
|
||||
return $bRet;
|
||||
}
|
||||
return $bRet;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
if (($this->Get('enabled_mode') == 'fixed') && ($this->Get('min_up_mode') == 'fixed')) {
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
if (($this->Get('enabled_mode') == 'fixed') && ($this->Get('min_up_mode') == 'fixed')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an HTML form that can be read by ReadValueFromPostedForm
|
||||
*/
|
||||
public function GetDisplayForm($sCurrentValue, $oPage, $bEditMode = false, $sFormPrefix = '')
|
||||
{
|
||||
$sRet = '';
|
||||
$aUserOptions = $this->GetUserOptions($sCurrentValue);
|
||||
if (count($aUserOptions) < 2) {
|
||||
$bEditOption = false;
|
||||
} else {
|
||||
$bEditOption = $bEditMode;
|
||||
}
|
||||
$sCurrentOption = $this->GetCurrentOption($sCurrentValue);
|
||||
foreach ($aUserOptions as $sUserOption) {
|
||||
$bSelected = ($sUserOption == $sCurrentOption);
|
||||
$sRet .= '<div>';
|
||||
$sRet .= $this->GetDisplayOption($sCurrentValue, $oPage, $sFormPrefix, $bEditOption, $sUserOption,
|
||||
$bSelected);
|
||||
$sRet .= '</div>';
|
||||
}
|
||||
/**
|
||||
* Returns an HTML form that can be read by ReadValueFromPostedForm
|
||||
*/
|
||||
public function GetDisplayForm($sCurrentValue, $oPage, $bEditMode = false, $sFormPrefix = '')
|
||||
{
|
||||
$sRet = '';
|
||||
$aUserOptions = $this->GetUserOptions($sCurrentValue);
|
||||
if (count($aUserOptions) < 2) {
|
||||
$bEditOption = false;
|
||||
} else {
|
||||
$bEditOption = $bEditMode;
|
||||
}
|
||||
$sCurrentOption = $this->GetCurrentOption($sCurrentValue);
|
||||
foreach ($aUserOptions as $sUserOption) {
|
||||
$bSelected = ($sUserOption == $sCurrentOption);
|
||||
$sRet .= '<div>';
|
||||
$sRet .= $this->GetDisplayOption($sCurrentValue, $oPage, $sFormPrefix, $bEditOption, $sUserOption,
|
||||
$bSelected);
|
||||
$sRet .= '</div>';
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
const USER_OPTION_DISABLED = 'disabled';
|
||||
const USER_OPTION_ENABLED_COUNT = 'count';
|
||||
const USER_OPTION_ENABLED_PERCENT = 'percent';
|
||||
const USER_OPTION_DISABLED = 'disabled';
|
||||
const USER_OPTION_ENABLED_COUNT = 'count';
|
||||
const USER_OPTION_ENABLED_PERCENT = 'percent';
|
||||
|
||||
/**
|
||||
* Depending on the xxx_mode parameters, build the list of options that are allowed to the end-user
|
||||
*/
|
||||
protected function GetUserOptions($sValue)
|
||||
{
|
||||
$aRet = array();
|
||||
if ($this->Get('enabled_mode') == 'user') {
|
||||
$aRet[] = self::USER_OPTION_DISABLED;
|
||||
}
|
||||
/**
|
||||
* Depending on the xxx_mode parameters, build the list of options that are allowed to the end-user
|
||||
*/
|
||||
protected function GetUserOptions($sValue)
|
||||
{
|
||||
$aRet = array();
|
||||
if ($this->Get('enabled_mode') == 'user') {
|
||||
$aRet[] = self::USER_OPTION_DISABLED;
|
||||
}
|
||||
|
||||
if ($this->Get('min_up_mode') == 'user') {
|
||||
$aRet[] = self::USER_OPTION_ENABLED_COUNT;
|
||||
$aRet[] = self::USER_OPTION_ENABLED_PERCENT;
|
||||
} else {
|
||||
if ($this->GetMinUpType($sValue) == 'count') {
|
||||
$aRet[] = self::USER_OPTION_ENABLED_COUNT;
|
||||
} else {
|
||||
$aRet[] = self::USER_OPTION_ENABLED_PERCENT;
|
||||
}
|
||||
}
|
||||
if ($this->Get('min_up_mode') == 'user') {
|
||||
$aRet[] = self::USER_OPTION_ENABLED_COUNT;
|
||||
$aRet[] = self::USER_OPTION_ENABLED_PERCENT;
|
||||
} else {
|
||||
if ($this->GetMinUpType($sValue) == 'count') {
|
||||
$aRet[] = self::USER_OPTION_ENABLED_COUNT;
|
||||
} else {
|
||||
$aRet[] = self::USER_OPTION_ENABLED_PERCENT;
|
||||
}
|
||||
}
|
||||
|
||||
return $aRet;
|
||||
}
|
||||
return $aRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the string representation into one of the existing options
|
||||
*/
|
||||
protected function GetCurrentOption($sValue)
|
||||
{
|
||||
$sRet = self::USER_OPTION_DISABLED;
|
||||
if ($this->IsEnabled($sValue)) {
|
||||
if ($this->GetMinUpType($sValue) == 'count') {
|
||||
$sRet = self::USER_OPTION_ENABLED_COUNT;
|
||||
} else {
|
||||
$sRet = self::USER_OPTION_ENABLED_PERCENT;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Convert the string representation into one of the existing options
|
||||
*/
|
||||
protected function GetCurrentOption($sValue)
|
||||
{
|
||||
$sRet = self::USER_OPTION_DISABLED;
|
||||
if ($this->IsEnabled($sValue)) {
|
||||
if ($this->GetMinUpType($sValue) == 'count') {
|
||||
$sRet = self::USER_OPTION_ENABLED_COUNT;
|
||||
} else {
|
||||
$sRet = self::USER_OPTION_ENABLED_PERCENT;
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an option (form, or current value)
|
||||
*
|
||||
* @param string $sCurrentValue
|
||||
* @param \Combodo\iTop\Application\WebPage\WebPage $oPage
|
||||
* @param string $sFormPrefix
|
||||
* @param bool $bEditMode
|
||||
* @param string $sUserOption
|
||||
* @param bool $bSelected
|
||||
*
|
||||
* @return string
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function GetDisplayOption(
|
||||
$sCurrentValue, $oPage, $sFormPrefix, $bEditMode, $sUserOption, $bSelected = true
|
||||
)
|
||||
{
|
||||
$sRet = '';
|
||||
/**
|
||||
* Display an option (form, or current value)
|
||||
*
|
||||
* @param string $sCurrentValue
|
||||
* @param WebPage $oPage
|
||||
* @param string $sFormPrefix
|
||||
* @param bool $bEditMode
|
||||
* @param string $sUserOption
|
||||
* @param bool $bSelected
|
||||
*
|
||||
* @return string
|
||||
* @throws CoreException
|
||||
* @throws DictExceptionMissingString
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function GetDisplayOption(
|
||||
$sCurrentValue, $oPage, $sFormPrefix, $bEditMode, $sUserOption, $bSelected = true
|
||||
)
|
||||
{
|
||||
$sRet = '';
|
||||
|
||||
$iCurrentValue = $this->GetMinUpValue($sCurrentValue);
|
||||
if ($bEditMode) {
|
||||
$sValue = null;
|
||||
$sHtmlNamesPrefix = 'rddcy_' . $this->Get('relation_code') . '_' . $this->Get('from_class') . '_' . $this->Get('neighbour_id');
|
||||
switch ($sUserOption) {
|
||||
case self::USER_OPTION_DISABLED:
|
||||
$sValue = ''; // Empty placeholder
|
||||
break;
|
||||
$iCurrentValue = $this->GetMinUpValue($sCurrentValue);
|
||||
if ($bEditMode) {
|
||||
$sValue = null;
|
||||
$sHtmlNamesPrefix = 'rddcy_'.$this->Get('relation_code').'_'.$this->Get('from_class').'_'.$this->Get('neighbour_id');
|
||||
switch ($sUserOption) {
|
||||
case self::USER_OPTION_DISABLED:
|
||||
$sValue = ''; // Empty placeholder
|
||||
break;
|
||||
|
||||
case self::USER_OPTION_ENABLED_COUNT:
|
||||
if ($bEditMode) {
|
||||
$sName = $sHtmlNamesPrefix . '_min_up_count';
|
||||
$sEditValue = $bSelected ? $iCurrentValue : '';
|
||||
$sValue = '<input class="redundancy-min-up-count" type="string" size="3" name="' . $sName . '" value="' . $sEditValue . '">';
|
||||
// To fix an issue on Firefox: focus set to the option (because the input is within the label for the option)
|
||||
$oPage->add_ready_script("\$('[name=\"$sName\"]').on('click', function(){var me=this; setTimeout(function(){\$(me).trigger('focus');}, 100);});");
|
||||
} else {
|
||||
$sValue = $iCurrentValue;
|
||||
}
|
||||
break;
|
||||
case self::USER_OPTION_ENABLED_COUNT:
|
||||
if ($bEditMode) {
|
||||
$sName = $sHtmlNamesPrefix.'_min_up_count';
|
||||
$sEditValue = $bSelected ? $iCurrentValue : '';
|
||||
$sValue = '<input class="redundancy-min-up-count" type="string" size="3" name="'.$sName.'" value="'.$sEditValue.'">';
|
||||
// To fix an issue on Firefox: focus set to the option (because the input is within the label for the option)
|
||||
$oPage->add_ready_script("\$('[name=\"$sName\"]').on('click', function(){var me=this; setTimeout(function(){\$(me).trigger('focus');}, 100);});");
|
||||
} else {
|
||||
$sValue = $iCurrentValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::USER_OPTION_ENABLED_PERCENT:
|
||||
if ($bEditMode) {
|
||||
$sName = $sHtmlNamesPrefix . '_min_up_percent';
|
||||
$sEditValue = $bSelected ? $iCurrentValue : '';
|
||||
$sValue = '<input class="redundancy-min-up-percent" type="string" size="3" name="' . $sName . '" value="' . $sEditValue . '">';
|
||||
// To fix an issue on Firefox: focus set to the option (because the input is within the label for the option)
|
||||
$oPage->add_ready_script("\$('[name=\"$sName\"]').on('click', function(){var me=this; setTimeout(function(){\$(me).trigger('focus');}, 100);});");
|
||||
} else {
|
||||
$sValue = $iCurrentValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$sLabel = sprintf($this->GetUserOptionFormat($sUserOption), $sValue,
|
||||
MetaModel::GetName($this->GetHostClass()));
|
||||
case self::USER_OPTION_ENABLED_PERCENT:
|
||||
if ($bEditMode) {
|
||||
$sName = $sHtmlNamesPrefix.'_min_up_percent';
|
||||
$sEditValue = $bSelected ? $iCurrentValue : '';
|
||||
$sValue = '<input class="redundancy-min-up-percent" type="string" size="3" name="'.$sName.'" value="'.$sEditValue.'">';
|
||||
// To fix an issue on Firefox: focus set to the option (because the input is within the label for the option)
|
||||
$oPage->add_ready_script("\$('[name=\"$sName\"]').on('click', function(){var me=this; setTimeout(function(){\$(me).trigger('focus');}, 100);});");
|
||||
} else {
|
||||
$sValue = $iCurrentValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$sLabel = sprintf($this->GetUserOptionFormat($sUserOption), $sValue,
|
||||
MetaModel::GetName($this->GetHostClass()));
|
||||
|
||||
$sOptionName = $sHtmlNamesPrefix . '_user_option';
|
||||
$sOptionId = $sOptionName . '_' . $sUserOption;
|
||||
$sChecked = $bSelected ? 'checked' : '';
|
||||
$sRet = '<input type="radio" name="' . $sOptionName . '" id="' . $sOptionId . '" value="' . $sUserOption . '" ' . $sChecked . '> <label for="' . $sOptionId . '">' . $sLabel . '</label>';
|
||||
} else {
|
||||
// Read-only: display only the currently selected option
|
||||
if ($bSelected) {
|
||||
$sRet = sprintf($this->GetUserOptionFormat($sUserOption), $iCurrentValue,
|
||||
MetaModel::GetName($this->GetHostClass()));
|
||||
}
|
||||
}
|
||||
$sOptionName = $sHtmlNamesPrefix.'_user_option';
|
||||
$sOptionId = $sOptionName.'_'.$sUserOption;
|
||||
$sChecked = $bSelected ? 'checked' : '';
|
||||
$sRet = '<input type="radio" name="'.$sOptionName.'" id="'.$sOptionId.'" value="'.$sUserOption.'" '.$sChecked.'> <label for="'.$sOptionId.'">'.$sLabel.'</label>';
|
||||
} else {
|
||||
// Read-only: display only the currently selected option
|
||||
if ($bSelected) {
|
||||
$sRet = sprintf($this->GetUserOptionFormat($sUserOption), $iCurrentValue,
|
||||
MetaModel::GetName($this->GetHostClass()));
|
||||
}
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the string representation out of the values given by the form defined in GetDisplayForm
|
||||
*/
|
||||
public function ReadValueFromPostedForm($sFormPrefix)
|
||||
{
|
||||
$sHtmlNamesPrefix = 'rddcy_' . $this->Get('relation_code') . '_' . $this->Get('from_class') . '_' . $this->Get('neighbour_id');
|
||||
/**
|
||||
* Makes the string representation out of the values given by the form defined in GetDisplayForm
|
||||
*/
|
||||
public function ReadValueFromPostedForm($sFormPrefix)
|
||||
{
|
||||
$sHtmlNamesPrefix = 'rddcy_'.$this->Get('relation_code').'_'.$this->Get('from_class').'_'.$this->Get('neighbour_id');
|
||||
|
||||
$iMinUpCount = (int)utils::ReadPostedParam($sHtmlNamesPrefix . '_min_up_count', null, 'raw_data');
|
||||
$iMinUpPercent = (int)utils::ReadPostedParam($sHtmlNamesPrefix . '_min_up_percent', null, 'raw_data');
|
||||
$sSelectedOption = utils::ReadPostedParam($sHtmlNamesPrefix . '_user_option', null, 'raw_data');
|
||||
switch ($sSelectedOption) {
|
||||
case self::USER_OPTION_ENABLED_COUNT:
|
||||
$sRet = $iMinUpCount;
|
||||
break;
|
||||
$iMinUpCount = (int)utils::ReadPostedParam($sHtmlNamesPrefix.'_min_up_count', null, 'raw_data');
|
||||
$iMinUpPercent = (int)utils::ReadPostedParam($sHtmlNamesPrefix.'_min_up_percent', null, 'raw_data');
|
||||
$sSelectedOption = utils::ReadPostedParam($sHtmlNamesPrefix.'_user_option', null, 'raw_data');
|
||||
switch ($sSelectedOption) {
|
||||
case self::USER_OPTION_ENABLED_COUNT:
|
||||
$sRet = $iMinUpCount;
|
||||
break;
|
||||
|
||||
case self::USER_OPTION_ENABLED_PERCENT:
|
||||
$sRet = $iMinUpPercent . '%';
|
||||
break;
|
||||
case self::USER_OPTION_ENABLED_PERCENT:
|
||||
$sRet = $iMinUpPercent.'%';
|
||||
break;
|
||||
|
||||
case self::USER_OPTION_DISABLED:
|
||||
default:
|
||||
$sRet = 'disabled';
|
||||
break;
|
||||
}
|
||||
case self::USER_OPTION_DISABLED:
|
||||
default:
|
||||
$sRet = 'disabled';
|
||||
break;
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use ApplicationContext;
|
||||
use cmdbAbstractObject;
|
||||
use CMDBChangeOpSetAttributeTagSet;
|
||||
use CMDBSource;
|
||||
use CoreException;
|
||||
use CoreUnexpectedValue;
|
||||
use DBObject;
|
||||
use DBSearch;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use ormSet;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* An unordered multi values attribute
|
||||
@@ -8,446 +27,453 @@
|
||||
*/
|
||||
abstract class AttributeSet extends AttributeDBFieldVoid
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const EDITABLE_INPUT_ID_SUFFIX = '-setwidget-values'; // used client side, see js/jquery.itop-set-widget.js
|
||||
protected $bDisplayLink; // Display search link in readonly mode
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const EDITABLE_INPUT_ID_SUFFIX = '-setwidget-values'; // used client side, see js/jquery.itop-set-widget.js
|
||||
protected $bDisplayLink; // Display search link in readonly mode
|
||||
|
||||
public function __construct($sCode, array $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
$this->aCSSClasses[] = 'attribute-set';
|
||||
$this->bDisplayLink = true;
|
||||
}
|
||||
public function __construct($sCode, array $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
$this->aCSSClasses[] = 'attribute-set';
|
||||
$this->bDisplayLink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bDisplayLink
|
||||
*/
|
||||
public function setDisplayLink($bDisplayLink)
|
||||
{
|
||||
$this->bDisplayLink = $bDisplayLink;
|
||||
}
|
||||
/**
|
||||
* @param bool $bDisplayLink
|
||||
*/
|
||||
public function setDisplayLink($bDisplayLink)
|
||||
{
|
||||
$this->bDisplayLink = $bDisplayLink;
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('is_null_allowed', 'max_items'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('is_null_allowed', 'max_items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed different values for the set values are mandatory for this attribute to be modified
|
||||
*
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function GetPossibleValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
return $this->GetAllowedValues($aArgs, $sContains);
|
||||
}
|
||||
/**
|
||||
* Allowed different values for the set values are mandatory for this attribute to be modified
|
||||
*
|
||||
* @param array $aArgs
|
||||
* @param string $sContains
|
||||
*
|
||||
* @return array|null
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function GetPossibleValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
return $this->GetAllowedValues($aArgs, $sContains);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ormSet $oValue
|
||||
*
|
||||
* @param $aArgs
|
||||
*
|
||||
* @return string JSON to be used in the itop.set_widget JQuery widget
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function GetJsonForWidget($oValue, $aArgs = array())
|
||||
{
|
||||
$aJson = array();
|
||||
/**
|
||||
* @param \ormSet $oValue
|
||||
*
|
||||
* @param $aArgs
|
||||
*
|
||||
* @return string JSON to be used in the itop.set_widget JQuery widget
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function GetJsonForWidget($oValue, $aArgs = array())
|
||||
{
|
||||
$aJson = array();
|
||||
|
||||
// possible_values
|
||||
$aAllowedValues = $this->GetPossibleValues($aArgs);
|
||||
$aSetKeyValData = array();
|
||||
foreach ($aAllowedValues as $sCode => $sLabel) {
|
||||
$aSetKeyValData[] = [
|
||||
'code' => $sCode,
|
||||
'label' => $sLabel,
|
||||
];
|
||||
}
|
||||
$aJson['possible_values'] = $aSetKeyValData;
|
||||
$aRemoved = array();
|
||||
if (is_null($oValue)) {
|
||||
$aJson['partial_values'] = array();
|
||||
$aJson['orig_value'] = array();
|
||||
} else {
|
||||
$aPartialValues = $oValue->GetModified();
|
||||
foreach ($aPartialValues as $key => $value) {
|
||||
if (!isset($aAllowedValues[$value])) {
|
||||
unset($aPartialValues[$key]);
|
||||
}
|
||||
}
|
||||
$aJson['partial_values'] = array_values($aPartialValues);
|
||||
$aOrigValues = array_merge($oValue->GetValues(), $oValue->GetModified());
|
||||
foreach ($aOrigValues as $key => $value) {
|
||||
if (!isset($aAllowedValues[$value])) {
|
||||
// Remove unwanted values
|
||||
$aRemoved[] = $value;
|
||||
unset($aOrigValues[$key]);
|
||||
}
|
||||
}
|
||||
$aJson['orig_value'] = array_values($aOrigValues);
|
||||
}
|
||||
$aJson['added'] = array();
|
||||
$aJson['removed'] = $aRemoved;
|
||||
// possible_values
|
||||
$aAllowedValues = $this->GetPossibleValues($aArgs);
|
||||
$aSetKeyValData = array();
|
||||
foreach ($aAllowedValues as $sCode => $sLabel) {
|
||||
$aSetKeyValData[] = [
|
||||
'code' => $sCode,
|
||||
'label' => $sLabel,
|
||||
];
|
||||
}
|
||||
$aJson['possible_values'] = $aSetKeyValData;
|
||||
$aRemoved = array();
|
||||
if (is_null($oValue)) {
|
||||
$aJson['partial_values'] = array();
|
||||
$aJson['orig_value'] = array();
|
||||
} else {
|
||||
$aPartialValues = $oValue->GetModified();
|
||||
foreach ($aPartialValues as $key => $value) {
|
||||
if (!isset($aAllowedValues[$value])) {
|
||||
unset($aPartialValues[$key]);
|
||||
}
|
||||
}
|
||||
$aJson['partial_values'] = array_values($aPartialValues);
|
||||
$aOrigValues = array_merge($oValue->GetValues(), $oValue->GetModified());
|
||||
foreach ($aOrigValues as $key => $value) {
|
||||
if (!isset($aAllowedValues[$value])) {
|
||||
// Remove unwanted values
|
||||
$aRemoved[] = $value;
|
||||
unset($aOrigValues[$key]);
|
||||
}
|
||||
}
|
||||
$aJson['orig_value'] = array_values($aOrigValues);
|
||||
}
|
||||
$aJson['added'] = array();
|
||||
$aJson['removed'] = $aRemoved;
|
||||
|
||||
$iMaxTags = $this->GetMaxItems();
|
||||
$aJson['max_items_allowed'] = $iMaxTags;
|
||||
$iMaxTags = $this->GetMaxItems();
|
||||
$aJson['max_items_allowed'] = $iMaxTags;
|
||||
|
||||
return json_encode($aJson);
|
||||
}
|
||||
return json_encode($aJson);
|
||||
}
|
||||
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function RequiresFullTextIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function RequiresFullTextIndex()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
return $this->Get("is_null_allowed");
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Set";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Set";
|
||||
}
|
||||
|
||||
public function GetEditValue($value, $oHostObj = null)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
return implode(', ', $value);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
public function GetEditValue($value, $oHostObj = null)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
return implode(', ', $value);
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
$iLen = $this->GetMaxSize();
|
||||
return "VARCHAR($iLen)"
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
$iLen = $this->GetMaxSize();
|
||||
|
||||
public function FromStringToArray($proposedValue, $sDefaultSepItem = ',')
|
||||
{
|
||||
$aValues = array();
|
||||
if (!empty($proposedValue)) {
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
// convert also , separated strings
|
||||
if ($sSepItem !== $sDefaultSepItem) {
|
||||
$proposedValue = str_replace($sDefaultSepItem, $sSepItem, $proposedValue);
|
||||
}
|
||||
foreach (explode($sSepItem, $proposedValue) as $sCode) {
|
||||
$sValue = trim($sCode);
|
||||
if ($sValue !== '') {
|
||||
$aValues[] = $sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
return "VARCHAR($iLen)"
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$sValue = $aCols["$sPrefix"];
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
return $this->MakeRealValue($sValue, null, true);
|
||||
}
|
||||
public function FromStringToArray($proposedValue, $sDefaultSepItem = ',')
|
||||
{
|
||||
$aValues = array();
|
||||
if (!empty($proposedValue)) {
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
// convert also , separated strings
|
||||
if ($sSepItem !== $sDefaultSepItem) {
|
||||
$proposedValue = str_replace($sDefaultSepItem, $sSepItem, $proposedValue);
|
||||
}
|
||||
foreach (explode($sSepItem, $proposedValue) as $sCode) {
|
||||
$sValue = trim($sCode);
|
||||
if ($sValue !== '') {
|
||||
$aValues[] = $sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @param bool $bIgnoreErrors
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||
{
|
||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
$aAllowedValues = $this->GetPossibleValues();
|
||||
if (is_string($proposedValue) && !empty($proposedValue)) {
|
||||
$proposedValue = trim("$proposedValue");
|
||||
$aValues = $this->FromStringToArray($proposedValue);
|
||||
foreach ($aValues as $i => $sValue) {
|
||||
if (!isset($aAllowedValues[$sValue])) {
|
||||
unset($aValues[$i]);
|
||||
}
|
||||
}
|
||||
$oSet->SetValues($aValues);
|
||||
} elseif ($proposedValue instanceof ormSet) {
|
||||
$oSet = $proposedValue;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
return $oSet;
|
||||
}
|
||||
/**
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$sValue = $aCols["$sPrefix"];
|
||||
|
||||
/**
|
||||
* Get the value from a given string (plain text, CSV import)
|
||||
*
|
||||
* @param string $sProposedValue
|
||||
* @param bool $bLocalizedValue
|
||||
* @param string $sSepItem
|
||||
* @param string $sSepAttribute
|
||||
* @param string $sSepValue
|
||||
* @param string $sAttributeQualifier
|
||||
*
|
||||
* @return mixed null if no match could be found
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function MakeValueFromString($sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null, $sAttributeQualifier = null)
|
||||
{
|
||||
return $this->MakeRealValue($sProposedValue, null);
|
||||
}
|
||||
return $this->MakeRealValue($sValue, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|\ormSet
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetNullValue()
|
||||
{
|
||||
return new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
}
|
||||
/**
|
||||
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
|
||||
*
|
||||
* @param $proposedValue
|
||||
* @param DBObject $oHostObj
|
||||
*
|
||||
* @param bool $bIgnoreErrors
|
||||
*
|
||||
* @return mixed
|
||||
* @throws CoreException
|
||||
* @throws CoreUnexpectedValue
|
||||
*/
|
||||
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||
{
|
||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
$aAllowedValues = $this->GetPossibleValues();
|
||||
if (is_string($proposedValue) && !empty($proposedValue)) {
|
||||
$proposedValue = trim("$proposedValue");
|
||||
$aValues = $this->FromStringToArray($proposedValue);
|
||||
foreach ($aValues as $i => $sValue) {
|
||||
if (!isset($aAllowedValues[$sValue])) {
|
||||
unset($aValues[$i]);
|
||||
}
|
||||
}
|
||||
$oSet->SetValues($aValues);
|
||||
} elseif ($proposedValue instanceof ormSet) {
|
||||
$oSet = $proposedValue;
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
if (empty($proposedValue)) {
|
||||
return true;
|
||||
}
|
||||
return $oSet;
|
||||
}
|
||||
|
||||
/** @var \ormSet $proposedValue */
|
||||
return $proposedValue->Count() == 0;
|
||||
}
|
||||
/**
|
||||
* Get the value from a given string (plain text, CSV import)
|
||||
*
|
||||
* @param string $sProposedValue
|
||||
* @param bool $bLocalizedValue
|
||||
* @param string $sSepItem
|
||||
* @param string $sSepAttribute
|
||||
* @param string $sSepValue
|
||||
* @param string $sAttributeQualifier
|
||||
*
|
||||
* @return mixed null if no match could be found
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MakeValueFromString($sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null, $sAttributeQualifier = null)
|
||||
{
|
||||
return $this->MakeRealValue($sProposedValue, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
if (false === ($proposedValue instanceof ormSet)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @return null|ormSet
|
||||
* @throws CoreException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetNullValue()
|
||||
{
|
||||
return new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||
}
|
||||
|
||||
return $proposedValue->Count() > 0;
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
if (empty($proposedValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be overloaded for localized enums
|
||||
*
|
||||
* @param $sValue
|
||||
*
|
||||
* @return string label corresponding to the given value (in plain text)
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if ($sValue instanceof ormSet) {
|
||||
$sValue = $sValue->GetValues();
|
||||
}
|
||||
if (is_array($sValue)) {
|
||||
return implode(', ', $sValue);
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
/** @var ormSet $proposedValue */
|
||||
return $proposedValue->Count() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
* @param null $oHostObj
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetAsPlainText($sValue, $oHostObj = null)
|
||||
{
|
||||
return $this->GetValueLabel($sValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
if (false === ($proposedValue instanceof ormSet)) {
|
||||
return parent::HasAValue($proposedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
$sRes = implode($sSepItem, $value);
|
||||
if (!empty($sRes)) {
|
||||
$value = "{$sSepItem}{$sRes}{$sSepItem}";
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
return $proposedValue->Count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormSet) {
|
||||
$aValues = $value->GetValues();
|
||||
return $this->GenerateViewHtmlForValues($aValues);
|
||||
}
|
||||
if (is_array($value)) {
|
||||
return implode(', ', $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* To be overloaded for localized enums
|
||||
*
|
||||
* @param $sValue
|
||||
*
|
||||
* @return string label corresponding to the given value (in plain text)
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetValueLabel($sValue)
|
||||
{
|
||||
if ($sValue instanceof ormSet) {
|
||||
$sValue = $sValue->GetValues();
|
||||
}
|
||||
if (is_array($sValue)) {
|
||||
return implode(', ', $sValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML representation of a list of values (read-only)
|
||||
* accept a list of strings
|
||||
*
|
||||
* @param array $aValues
|
||||
* @param string $sCssClass
|
||||
* @param bool $bWithLink if true will generate a link, otherwise just a "a" tag without href
|
||||
*
|
||||
* @return string
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink = true)
|
||||
{
|
||||
if (empty($aValues)) {
|
||||
return '';
|
||||
}
|
||||
$sHtml = '<span class="' . $sCssClass . ' ' . implode(' ', $this->aCSSClasses) . '">';
|
||||
foreach ($aValues as $sValue) {
|
||||
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode());
|
||||
$sAttCode = $this->GetCode();
|
||||
$sLabel = utils::EscapeHtml($this->GetValueLabel($sValue));
|
||||
$sDescription = utils::EscapeHtml($this->GetValueDescription($sValue));
|
||||
$oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sValue'");
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sContext = $oAppContext->GetForLink(true);
|
||||
$sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass());
|
||||
$sFilter = rawurlencode($oFilter->serialize());
|
||||
$sLink = '';
|
||||
if ($bWithLink && $this->bDisplayLink) {
|
||||
$sUrl = utils::GetAbsoluteUrlAppRoot() . "pages/$sUIPage?operation=search&filter=" . $sFilter . $sContext;
|
||||
$sLink = ' href="' . $sUrl . '"';
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
// Prepare tooltip
|
||||
if (empty($sDescription)) {
|
||||
$sTooltipContent = $sLabel;
|
||||
$sTooltipHtmlEnabled = 'false';
|
||||
} else {
|
||||
$sTooltipContent = <<<HTML
|
||||
/**
|
||||
* @param string $sValue
|
||||
* @param null $oHostObj
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetAsPlainText($sValue, $oHostObj = null)
|
||||
{
|
||||
return $this->GetValueLabel($sValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
if ($value instanceof ormSet) {
|
||||
$value = $value->GetValues();
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
$sRes = implode($sSepItem, $value);
|
||||
if (!empty($sRes)) {
|
||||
$value = "{$sSepItem}{$sRes}{$sSepItem}";
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if ($value instanceof ormSet) {
|
||||
$aValues = $value->GetValues();
|
||||
|
||||
return $this->GenerateViewHtmlForValues($aValues);
|
||||
}
|
||||
if (is_array($value)) {
|
||||
return implode(', ', $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML representation of a list of values (read-only)
|
||||
* accept a list of strings
|
||||
*
|
||||
* @param array $aValues
|
||||
* @param string $sCssClass
|
||||
* @param bool $bWithLink if true will generate a link, otherwise just a "a" tag without href
|
||||
*
|
||||
* @return string
|
||||
* @throws CoreException
|
||||
* @throws OQLException
|
||||
*/
|
||||
public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink = true)
|
||||
{
|
||||
if (empty($aValues)) {
|
||||
return '';
|
||||
}
|
||||
$sHtml = '<span class="'.$sCssClass.' '.implode(' ', $this->aCSSClasses).'">';
|
||||
foreach ($aValues as $sValue) {
|
||||
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode());
|
||||
$sAttCode = $this->GetCode();
|
||||
$sLabel = utils::EscapeHtml($this->GetValueLabel($sValue));
|
||||
$sDescription = utils::EscapeHtml($this->GetValueDescription($sValue));
|
||||
$oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sValue'");
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sContext = $oAppContext->GetForLink(true);
|
||||
$sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass());
|
||||
$sFilter = rawurlencode($oFilter->serialize());
|
||||
$sLink = '';
|
||||
if ($bWithLink && $this->bDisplayLink) {
|
||||
$sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter.$sContext;
|
||||
$sLink = ' href="'.$sUrl.'"';
|
||||
}
|
||||
|
||||
// Prepare tooltip
|
||||
if (empty($sDescription)) {
|
||||
$sTooltipContent = $sLabel;
|
||||
$sTooltipHtmlEnabled = 'false';
|
||||
} else {
|
||||
$sTooltipContent = <<<HTML
|
||||
<h4>$sLabel</h4>
|
||||
<div>$sDescription</div>
|
||||
HTML;
|
||||
$sTooltipHtmlEnabled = 'true';
|
||||
}
|
||||
$sTooltipContent = utils::EscapeHtml($sTooltipContent);
|
||||
$sTooltipHtmlEnabled = 'true';
|
||||
}
|
||||
$sTooltipContent = utils::EscapeHtml($sTooltipContent);
|
||||
|
||||
$sHtml .= '<a' . $sLink . ' class="attribute-set-item attribute-set-item-' . $sValue . '" data-code="' . $sValue . '" data-label="' . $sLabel . '" data-description="' . $sDescription . '" data-tooltip-content="' . $sTooltipContent . '" data-tooltip-html-enabled="' . $sTooltipHtmlEnabled . '">' . $sLabel . '</a>';
|
||||
}
|
||||
$sHtml .= '</span>';
|
||||
$sHtml .= '<a'.$sLink.' class="attribute-set-item attribute-set-item-'.$sValue.'" data-code="'.$sValue.'" data-label="'.$sLabel.'" data-description="'.$sDescription.'" data-tooltip-content="'.$sTooltipContent.'" data-tooltip-html-enabled="'.$sTooltipHtmlEnabled.'">'.$sLabel.'</a>';
|
||||
}
|
||||
$sHtml .= '</span>';
|
||||
|
||||
return $sHtml;
|
||||
}
|
||||
return $sHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param \DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true, $bConvertToPlainText = false)
|
||||
{
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
if (is_object($value) && ($value instanceof ormSet)) {
|
||||
if ($bLocalize) {
|
||||
$aValues = $value->GetLabels();
|
||||
} else {
|
||||
$aValues = $value->GetValues();
|
||||
}
|
||||
$sRes = implode($sSepItem, $aValues);
|
||||
} else {
|
||||
$sRes = '';
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $sSeparator
|
||||
* @param string $sTextQualifier
|
||||
* @param DBObject $oHostObject
|
||||
* @param bool $bLocalize
|
||||
* @param bool $bConvertToPlainText
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true, $bConvertToPlainText = false)
|
||||
{
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
if (is_object($value) && ($value instanceof ormSet)) {
|
||||
if ($bLocalize) {
|
||||
$aValues = $value->GetLabels();
|
||||
} else {
|
||||
$aValues = $value->GetValues();
|
||||
}
|
||||
$sRes = implode($sSepItem, $aValues);
|
||||
} else {
|
||||
$sRes = '';
|
||||
}
|
||||
|
||||
return "{$sTextQualifier}{$sRes}{$sTextQualifier}";
|
||||
}
|
||||
return "{$sTextQualifier}{$sRes}{$sTextQualifier}";
|
||||
}
|
||||
|
||||
public function GetMaxItems()
|
||||
{
|
||||
return $this->Get('max_items');
|
||||
}
|
||||
public function GetMaxItems()
|
||||
{
|
||||
return $this->Get('max_items');
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SetField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\SetField';
|
||||
}
|
||||
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
/** @var \ormSet $original */
|
||||
/** @var \ormSet $value */
|
||||
parent::RecordAttChange($oObject,
|
||||
implode(' ', $original->GetValues()),
|
||||
implode(' ', $value->GetValues())
|
||||
);
|
||||
}
|
||||
public function RecordAttChange(DBObject $oObject, $original, $value): void
|
||||
{
|
||||
/** @var \ormSet $original */
|
||||
/** @var \ormSet $value */
|
||||
parent::RecordAttChange($oObject,
|
||||
implode(' ', $original->GetValues()),
|
||||
implode(' ', $value->GetValues())
|
||||
);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeTagSet::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeTagSet::class;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,16 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use CoreWarning;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Map a varchar column (size < ?) to an attribute
|
||||
@@ -7,181 +19,181 @@
|
||||
*/
|
||||
class AttributeString extends AttributeDBField
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return parent::ListExpectedParams();
|
||||
//return array_merge(parent::ListExpectedParams(), array());
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return 'VARCHAR(255)'
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return 'VARCHAR(255)'
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
$sPattern = $this->GetOptional('validation_pattern', '');
|
||||
if (empty($sPattern)) {
|
||||
return parent::GetValidationPattern();
|
||||
} else {
|
||||
return $sPattern;
|
||||
}
|
||||
}
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
$sPattern = $this->GetOptional('validation_pattern', '');
|
||||
if (empty($sPattern)) {
|
||||
return parent::GetValidationPattern();
|
||||
} else {
|
||||
return $sPattern;
|
||||
}
|
||||
}
|
||||
|
||||
public function CheckFormat($value)
|
||||
{
|
||||
$sRegExp = $this->GetValidationPattern();
|
||||
if (empty($sRegExp)) {
|
||||
return true;
|
||||
} else {
|
||||
$sRegExp = str_replace('/', '\\/', $sRegExp);
|
||||
public function CheckFormat($value)
|
||||
{
|
||||
$sRegExp = $this->GetValidationPattern();
|
||||
if (empty($sRegExp)) {
|
||||
return true;
|
||||
} else {
|
||||
$sRegExp = str_replace('/', '\\/', $sRegExp);
|
||||
|
||||
return preg_match("/$sRegExp/", $value);
|
||||
}
|
||||
}
|
||||
return preg_match("/$sRegExp/", $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"=" => "equals",
|
||||
"!=" => "differs from",
|
||||
"Like" => "equals (no case)",
|
||||
"NotLike" => "differs from (no case)",
|
||||
"Contains" => "contains",
|
||||
"Begins with" => "begins with",
|
||||
"Finishes with" => "finishes with"
|
||||
);
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array(
|
||||
"=" => "equals",
|
||||
"!=" => "differs from",
|
||||
"Like" => "equals (no case)",
|
||||
"NotLike" => "differs from (no case)",
|
||||
"Contains" => "contains",
|
||||
"Begins with" => "begins with",
|
||||
"Finishes with" => "finishes with",
|
||||
);
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "Contains";
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "Contains";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '=':
|
||||
case '!=':
|
||||
return $this->GetSQLExpr() . " $sOpCode $sQValue";
|
||||
case 'Begins with':
|
||||
return $this->GetSQLExpr() . " LIKE " . CMDBSource::Quote("$value%");
|
||||
case 'Finishes with':
|
||||
return $this->GetSQLExpr() . " LIKE " . CMDBSource::Quote("%$value");
|
||||
case 'Contains':
|
||||
return $this->GetSQLExpr() . " LIKE " . CMDBSource::Quote("%$value%");
|
||||
case 'NotLike':
|
||||
return $this->GetSQLExpr() . " NOT LIKE $sQValue";
|
||||
case 'Like':
|
||||
default:
|
||||
return $this->GetSQLExpr() . " LIKE $sQValue";
|
||||
}
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '=':
|
||||
case '!=':
|
||||
return $this->GetSQLExpr()." $sOpCode $sQValue";
|
||||
case 'Begins with':
|
||||
return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("$value%");
|
||||
case 'Finishes with':
|
||||
return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("%$value");
|
||||
case 'Contains':
|
||||
return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("%$value%");
|
||||
case 'NotLike':
|
||||
return $this->GetSQLExpr()." NOT LIKE $sQValue";
|
||||
case 'Like':
|
||||
default:
|
||||
return $this->GetSQLExpr()." LIKE $sQValue";
|
||||
}
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == '');
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return ($proposedValue == '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return utils::IsNotNullOrEmptyString($proposedValue);
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return '';
|
||||
}
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (string)$proposedValue;
|
||||
}
|
||||
return (string)$proposedValue;
|
||||
}
|
||||
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (!is_string($value) && !is_null($value)) {
|
||||
throw new CoreWarning('Expected the attribute value to be a string', array(
|
||||
'found_type' => gettype($value),
|
||||
'value' => $value,
|
||||
'class' => $this->GetHostClass(),
|
||||
'attribute' => $this->GetCode()
|
||||
));
|
||||
}
|
||||
public function ScalarToSQL($value)
|
||||
{
|
||||
if (!is_string($value) && !is_null($value)) {
|
||||
throw new CoreWarning('Expected the attribute value to be a string', array(
|
||||
'found_type' => gettype($value),
|
||||
'value' => $value,
|
||||
'class' => $this->GetHostClass(),
|
||||
'attribute' => $this->GetCode(),
|
||||
));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
|
||||
return $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
}
|
||||
return $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
}
|
||||
|
||||
public function GetDisplayStyle()
|
||||
{
|
||||
return $this->GetOptional('display_style', 'select');
|
||||
}
|
||||
public function GetDisplayStyle()
|
||||
{
|
||||
return $this->GetOptional('display_style', 'select');
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\StringField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\StringField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* View of a subvalue of another attribute
|
||||
@@ -10,253 +21,253 @@
|
||||
*/
|
||||
class AttributeSubItem extends AttributeDefinition
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the search widget type corresponding to this attribute
|
||||
* the computation is made by AttributeStopWatch::GetSubItemSearchType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetSearchType()
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
/**
|
||||
* Return the search widget type corresponding to this attribute
|
||||
* the computation is made by AttributeStopWatch::GetSubItemSearchType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetSearchType()
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
|
||||
return $oParent->GetSubItemSearchType($this->Get('item_code'));
|
||||
}
|
||||
return $oParent->GetSubItemSearchType($this->Get('item_code'));
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
|
||||
return $oParent->GetSubItemAllowedValues($this->Get('item_code'), $aArgs, $sContains);
|
||||
}
|
||||
return $oParent->GetSubItemAllowedValues($this->Get('item_code'), $aArgs, $sContains);
|
||||
}
|
||||
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
public function IsNullAllowed()
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
|
||||
$bDefaultValue = parent::IsNullAllowed();
|
||||
$bDefaultValue = parent::IsNullAllowed();
|
||||
|
||||
return $oParent->IsSubItemNullAllowed($this->Get('item_code'), $bDefaultValue);
|
||||
}
|
||||
return $oParent->IsSubItemNullAllowed($this->Get('item_code'), $bDefaultValue);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('target_attcode', 'item_code'));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array('target_attcode', 'item_code'));
|
||||
}
|
||||
|
||||
public function GetParentAttCode()
|
||||
{
|
||||
return $this->Get("target_attcode");
|
||||
}
|
||||
public function GetParentAttCode()
|
||||
{
|
||||
return $this->Get("target_attcode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper : get the attribute definition to which the execution will be forwarded
|
||||
*/
|
||||
public function GetTargetAttDef()
|
||||
{
|
||||
$sClass = $this->GetHostClass();
|
||||
$oParentAttDef = MetaModel::GetAttributeDef($sClass, $this->Get('target_attcode'));
|
||||
/**
|
||||
* Helper : get the attribute definition to which the execution will be forwarded
|
||||
*/
|
||||
public function GetTargetAttDef()
|
||||
{
|
||||
$sClass = $this->GetHostClass();
|
||||
$oParentAttDef = MetaModel::GetAttributeDef($sClass, $this->Get('target_attcode'));
|
||||
|
||||
return $oParentAttDef;
|
||||
}
|
||||
return $oParentAttDef;
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetValuesDef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsBasedOnDBColumns()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static function IsScalar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// public function IsNullAllowed() {return false;}
|
||||
|
||||
public static function LoadInObject()
|
||||
{
|
||||
return false;
|
||||
} // if this verb returns false, then GetValues must be implemented
|
||||
public static function LoadInObject()
|
||||
{
|
||||
return false;
|
||||
} // if this verb returns false, then GetValues must be implemented
|
||||
|
||||
/**
|
||||
* Used by DBOBject::Get()
|
||||
*
|
||||
* @param \DBObject $oHostObject
|
||||
*
|
||||
* @return \AttributeSubItem
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GetValue($oHostObject)
|
||||
{
|
||||
/** @var \AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$parentValue = $oHostObject->GetStrict($oParent->GetCode());
|
||||
$res = $oParent->GetSubItemValue($this->Get('item_code'), $parentValue, $oHostObject);
|
||||
/**
|
||||
* Used by DBOBject::Get()
|
||||
*
|
||||
* @param DBObject $oHostObject
|
||||
*
|
||||
* @return AttributeSubItem
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function GetValue($oHostObject)
|
||||
{
|
||||
/** @var AttributeStopWatch $oParent */
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$parentValue = $oHostObject->GetStrict($oParent->GetCode());
|
||||
$res = $oParent->GetSubItemValue($this->Get('item_code'), $parentValue, $oHostObject);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected function ScalarToSQL($value) {return $value;} // format value as a valuable SQL literal (quoted outside)
|
||||
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
}
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetBasicFilterOperators()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "=";
|
||||
}
|
||||
public function GetBasicFilterLooseOperator()
|
||||
{
|
||||
return "=";
|
||||
}
|
||||
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr() . " != $sQValue";
|
||||
break;
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr() . " = $sQValue";
|
||||
}
|
||||
}
|
||||
public function GetBasicFilterSQLExpr($sOpCode, $value)
|
||||
{
|
||||
$sQValue = CMDBSource::Quote($value);
|
||||
switch ($sOpCode) {
|
||||
case '!=':
|
||||
return $this->GetSQLExpr()." != $sQValue";
|
||||
break;
|
||||
case '=':
|
||||
default:
|
||||
return $this->GetSQLExpr()." = $sQValue";
|
||||
}
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemSQLExpression($this->Get('item_code'));
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemSQLExpression($this->Get('item_code'));
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function GetAsPlainText($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsPlainText($this->Get('item_code'), $value);
|
||||
public function GetAsPlainText($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsPlainText($this->Get('item_code'), $value);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsHTML($this->Get('item_code'), $value);
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsHTML($this->Get('item_code'), $value);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function GetAsHTMLForHistory($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsHTMLForHistory($this->Get('item_code'), $value);
|
||||
public function GetAsHTMLForHistory($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsHTMLForHistory($this->Get('item_code'), $value);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsCSV($this->Get('item_code'), $value, $sSeparator, $sTextQualifier,
|
||||
$bConvertToPlainText);
|
||||
public function GetAsCSV(
|
||||
$value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsCSV($this->Get('item_code'), $value, $sSeparator, $sTextQualifier,
|
||||
$bConvertToPlainText);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsXML($this->Get('item_code'), $value);
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsXML($this->Get('item_code'), $value);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* As of now, this function must be implemented to have the value in spreadsheet format
|
||||
*/
|
||||
public function GetEditValue($value, $oHostObj = null)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsEditValue($this->Get('item_code'), $value);
|
||||
/**
|
||||
* As of now, this function must be implemented to have the value in spreadsheet format
|
||||
*/
|
||||
public function GetEditValue($value, $oHostObj = null)
|
||||
{
|
||||
$oParent = $this->GetTargetAttDef();
|
||||
$res = $oParent->GetSubItemAsEditValue($this->Get('item_code'), $value);
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function IsPartOfFingerprint()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function IsPartOfFingerprint()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\LabelField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\LabelField';
|
||||
}
|
||||
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
// Note : As of today, this attribute is -by nature- only supported in readonly mode, not edition
|
||||
$sAttCode = $this->GetCode();
|
||||
$oFormField->SetCurrentValue(html_entity_decode($oObject->GetAsHTML($sAttCode), ENT_QUOTES, 'UTF-8'));
|
||||
$oFormField->SetReadOnly(true);
|
||||
// Note : As of today, this attribute is -by nature- only supported in readonly mode, not edition
|
||||
$sAttCode = $this->GetCode();
|
||||
$oFormField->SetCurrentValue(html_entity_decode($oObject->GetAsHTML($sAttCode), ENT_QUOTES, 'UTF-8'));
|
||||
$oFormField->SetReadOnly(true);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,164 +1,176 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBSource;
|
||||
use CoreException;
|
||||
use Exception;
|
||||
|
||||
class AttributeTable extends AttributeDBField
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Table";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "Table";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "LONGTEXT" . CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "LONGTEXT".CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetNullValue()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
public function GetNullValue()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return (count($proposedValue) == 0);
|
||||
}
|
||||
public function IsNull($proposedValue)
|
||||
{
|
||||
return (count($proposedValue) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return count($proposedValue) > 0;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasAValue($proposedValue): bool
|
||||
{
|
||||
return count($proposedValue) > 0;
|
||||
}
|
||||
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// Facilitate things: allow the user to Set the value from a string
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return array();
|
||||
} else {
|
||||
if (!is_array($proposedValue)) {
|
||||
return array(0 => array(0 => $proposedValue));
|
||||
}
|
||||
}
|
||||
// Facilitate things: allow the user to Set the value from a string
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
if (is_null($proposedValue)) {
|
||||
return array();
|
||||
} else {
|
||||
if (!is_array($proposedValue)) {
|
||||
return array(0 => array(0 => $proposedValue));
|
||||
}
|
||||
}
|
||||
|
||||
return $proposedValue;
|
||||
}
|
||||
return $proposedValue;
|
||||
}
|
||||
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
try {
|
||||
$value = @unserialize($aCols[$sPrefix . '']);
|
||||
if ($value === false) {
|
||||
$value = @json_decode($aCols[$sPrefix . ''], true);
|
||||
if (is_null($value)) {
|
||||
$value = false;
|
||||
}
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = $this->MakeRealValue($aCols[$sPrefix . ''], null);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$value = $this->MakeRealValue($aCols[$sPrefix . ''], null);
|
||||
}
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
try {
|
||||
$value = @unserialize($aCols[$sPrefix.'']);
|
||||
if ($value === false) {
|
||||
$value = @json_decode($aCols[$sPrefix.''], true);
|
||||
if (is_null($value)) {
|
||||
$value = false;
|
||||
}
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = $this->MakeRealValue($aCols[$sPrefix.''], null);
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$value = $this->MakeRealValue($aCols[$sPrefix.''], null);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$aValues = array();
|
||||
try {
|
||||
$sSerializedValue = serialize($value);
|
||||
} catch (Exception $e) {
|
||||
$sSerializedValue = json_encode($value);
|
||||
}
|
||||
$aValues[$this->Get("sql")] = $sSerializedValue;
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$aValues = array();
|
||||
try {
|
||||
$sSerializedValue = serialize($value);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$sSerializedValue = json_encode($value);
|
||||
}
|
||||
$aValues[$this->Get("sql")] = $sSerializedValue;
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException('Expecting an array', array('found' => get_class($value)));
|
||||
}
|
||||
if (count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
throw new CoreException('Expecting an array', array('found' => get_class($value)));
|
||||
}
|
||||
if (count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$sRes = "<TABLE class=\"listResults\">";
|
||||
$sRes .= "<TBODY>";
|
||||
foreach ($value as $iRow => $aRawData) {
|
||||
$sRes .= "<TR>";
|
||||
foreach ($aRawData as $iCol => $cell) {
|
||||
// Note: avoid the warning in case the cell is made of an array
|
||||
$sCell = @Str::pure2html((string)$cell);
|
||||
$sCell = str_replace("\n", "<br>\n", $sCell);
|
||||
$sRes .= "<TD>$sCell</TD>";
|
||||
}
|
||||
$sRes .= "</TR>";
|
||||
}
|
||||
$sRes .= "</TBODY>";
|
||||
$sRes .= "</TABLE>";
|
||||
$sRes = "<TABLE class=\"listResults\">";
|
||||
$sRes .= "<TBODY>";
|
||||
foreach ($value as $iRow => $aRawData) {
|
||||
$sRes .= "<TR>";
|
||||
foreach ($aRawData as $iCol => $cell) {
|
||||
// Note: avoid the warning in case the cell is made of an array
|
||||
$sCell = @Str::pure2html((string)$cell);
|
||||
$sCell = str_replace("\n", "<br>\n", $sCell);
|
||||
$sRes .= "<TD>$sCell</TD>";
|
||||
}
|
||||
$sRes .= "</TR>";
|
||||
}
|
||||
$sRes .= "</TBODY>";
|
||||
$sRes .= "</TABLE>";
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
// Not implemented
|
||||
return '';
|
||||
}
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
// Not implemented
|
||||
return '';
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value) || count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (!is_array($value) || count($value) == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$sRes = "";
|
||||
foreach ($value as $iRow => $aRawData) {
|
||||
$sRes .= "<row>";
|
||||
foreach ($aRawData as $iCol => $cell) {
|
||||
$sCell = Str::pure2xml((string)$cell);
|
||||
$sRes .= "<cell icol=\"$iCol\">$sCell</cell>";
|
||||
}
|
||||
$sRes .= "</row>";
|
||||
}
|
||||
$sRes = "";
|
||||
foreach ($value as $iRow => $aRawData) {
|
||||
$sRes .= "<row>";
|
||||
foreach ($aRawData as $iCol => $cell) {
|
||||
$sCell = Str::pure2xml((string)$cell);
|
||||
$sRes .= "<cell icol=\"$iCol\">$sCell</cell>";
|
||||
}
|
||||
$sRes .= "</row>";
|
||||
}
|
||||
|
||||
return $sRes;
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Specialization of a HTML: template (contains iTop placeholders like $current_contact_id$ or $this->name$)
|
||||
@@ -7,47 +15,47 @@
|
||||
*/
|
||||
class AttributeTemplateHTML extends AttributeText
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get('sql')] = $this->GetSQLCol();
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns[$this->Get('sql') . '_format'] = "ENUM('text','html')";
|
||||
if ($bFullSpec) {
|
||||
$aColumns[$this->Get('sql') . '_format'] .= " DEFAULT 'html'"; // default 'html' is for migrating old records
|
||||
}
|
||||
}
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get('sql')] = $this->GetSQLCol();
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns[$this->Get('sql').'_format'] = "ENUM('text','html')";
|
||||
if ($bFullSpec) {
|
||||
$aColumns[$this->Get('sql').'_format'] .= " DEFAULT 'html'"; // default 'html' is for migrating old records
|
||||
}
|
||||
}
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual formatting of the text: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'html'); // Defaults to HTML
|
||||
}
|
||||
/**
|
||||
* The actual formatting of the text: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'html'); // Defaults to HTML
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Specialization of a string: template (contains iTop placeholders like $current_contact_id$ or $this->name$)
|
||||
@@ -7,22 +15,22 @@
|
||||
*/
|
||||
class AttributeTemplateString extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Specialization of a text: template (contains iTop placeholders like $current_contact_id$ or $this->name$)
|
||||
@@ -7,22 +15,22 @@
|
||||
*/
|
||||
class AttributeTemplateText extends AttributeText
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOp;
|
||||
use CMDBChangeOpSetAttributeHTML;
|
||||
use CMDBChangeOpSetAttributeText;
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\Form\Field\TextAreaField;
|
||||
use CoreException;
|
||||
use DBObject;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use HTMLSanitizer;
|
||||
use InlineImage;
|
||||
use MetaModel;
|
||||
use ormCaseLog;
|
||||
use Str;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Map a text column (size > ?) to an attribute
|
||||
@@ -7,379 +29,380 @@
|
||||
*/
|
||||
class AttributeText extends AttributeString
|
||||
{
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return ($this->GetFormat() == 'text') ? 'Text' : "HTML";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return ($this->GetFormat() == 'text') ? 'Text' : "HTML";
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TEXT" . CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "TEXT".CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get('sql')] = $this->GetSQLCol($bFullSpec);
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns[$this->Get('sql') . '_format'] = "ENUM('text','html')" . CMDBSource::GetSqlStringColumnDefinition();
|
||||
if ($bFullSpec) {
|
||||
$aColumns[$this->Get('sql') . '_format'] .= " DEFAULT 'text'"; // default 'text' is for migrating old records
|
||||
}
|
||||
}
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = array();
|
||||
$aColumns[$this->Get('sql')] = $this->GetSQLCol($bFullSpec);
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns[$this->Get('sql').'_format'] = "ENUM('text','html')".CMDBSource::GetSqlStringColumnDefinition();
|
||||
if ($bFullSpec) {
|
||||
$aColumns[$this->Get('sql').'_format'] .= " DEFAULT 'text'"; // default 'text' is for migrating old records
|
||||
}
|
||||
}
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->Get('sql');
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix;
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns['_format'] = $sPrefix . '_format';
|
||||
}
|
||||
public function GetSQLExpressions($sPrefix = '')
|
||||
{
|
||||
if ($sPrefix == '') {
|
||||
$sPrefix = $this->Get('sql');
|
||||
}
|
||||
$aColumns = array();
|
||||
// Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
|
||||
$aColumns[''] = $sPrefix;
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aColumns['_format'] = $sPrefix.'_format';
|
||||
}
|
||||
|
||||
return $aColumns;
|
||||
}
|
||||
return $aColumns;
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
// Is there a way to know the current limitation for mysql?
|
||||
// See mysql_field_len()
|
||||
return 65535;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
// Is there a way to know the current limitation for mysql?
|
||||
// See mysql_field_len()
|
||||
return 65535;
|
||||
}
|
||||
|
||||
public static function RenderWikiHtml($sText, $bWikiOnly = false)
|
||||
{
|
||||
if (!$bWikiOnly) {
|
||||
$sPattern = '/' . str_replace('/', '\/', utils::GetConfig()->Get('url_validation_pattern')) . '/i';
|
||||
if (preg_match_all($sPattern, $sText, $aAllMatches,
|
||||
PREG_SET_ORDER /* important !*/ | PREG_OFFSET_CAPTURE /* important ! */)) {
|
||||
$i = count($aAllMatches);
|
||||
// Replace the URLs by an actual hyperlink <a href="...">...</a>
|
||||
// Let's do it backwards so that the initial positions are not modified by the replacement
|
||||
// This works if the matches are captured: in the order they occur in the string AND
|
||||
// with their offset (i.e. position) inside the string
|
||||
while ($i > 0) {
|
||||
$i--;
|
||||
$sUrl = $aAllMatches[$i][0][0]; // String corresponding to the main pattern
|
||||
$iPos = $aAllMatches[$i][0][1]; // Position of the main pattern
|
||||
$sText = substr_replace($sText, "<a href=\"$sUrl\">$sUrl</a>", $iPos, strlen($sUrl));
|
||||
public static function RenderWikiHtml($sText, $bWikiOnly = false)
|
||||
{
|
||||
if (!$bWikiOnly) {
|
||||
$sPattern = '/'.str_replace('/', '\/', utils::GetConfig()->Get('url_validation_pattern')).'/i';
|
||||
if (preg_match_all($sPattern, $sText, $aAllMatches,
|
||||
PREG_SET_ORDER /* important !*/ | PREG_OFFSET_CAPTURE /* important ! */)) {
|
||||
$i = count($aAllMatches);
|
||||
// Replace the URLs by an actual hyperlink <a href="...">...</a>
|
||||
// Let's do it backwards so that the initial positions are not modified by the replacement
|
||||
// This works if the matches are captured: in the order they occur in the string AND
|
||||
// with their offset (i.e. position) inside the string
|
||||
while ($i > 0) {
|
||||
$i--;
|
||||
$sUrl = $aAllMatches[$i][0][0]; // String corresponding to the main pattern
|
||||
$iPos = $aAllMatches[$i][0][1]; // Position of the main pattern
|
||||
$sText = substr_replace($sText, "<a href=\"$sUrl\">$sUrl</a>", $iPos, strlen($sUrl));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (preg_match_all(WIKI_OBJECT_REGEXP, $sText, $aAllMatches, PREG_SET_ORDER)) {
|
||||
foreach ($aAllMatches as $iPos => $aMatches) {
|
||||
$sClass = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (preg_match_all(WIKI_OBJECT_REGEXP, $sText, $aAllMatches, PREG_SET_ORDER)) {
|
||||
foreach ($aAllMatches as $iPos => $aMatches) {
|
||||
$sClass = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
|
||||
if (MetaModel::IsValidClass($sClass)) {
|
||||
$bFound = false;
|
||||
if (MetaModel::IsValidClass($sClass)) {
|
||||
$bFound = false;
|
||||
|
||||
// Try to find by name, then by id
|
||||
if (is_object($oObj = MetaModel::GetObjectByName($sClass, $sName, false /* MustBeFound */))) {
|
||||
$bFound = true;
|
||||
} elseif (is_object($oObj = MetaModel::GetObject($sClass, (int)$sName, false /* MustBeFound */, true))) {
|
||||
$bFound = true;
|
||||
}
|
||||
// Try to find by name, then by id
|
||||
if (is_object($oObj = MetaModel::GetObjectByName($sClass, $sName, false /* MustBeFound */))) {
|
||||
$bFound = true;
|
||||
} elseif (is_object($oObj = MetaModel::GetObject($sClass, (int)$sName, false /* MustBeFound */, true))) {
|
||||
$bFound = true;
|
||||
}
|
||||
|
||||
if ($bFound === true) {
|
||||
// Propose a std link to the object
|
||||
$sHyperlinkLabel = (empty($sLabel)) ? $oObj->GetName() : $sLabel;
|
||||
$sText = str_replace($aMatches[0], $oObj->GetHyperlink(null, true, $sHyperlinkLabel), $sText);
|
||||
} else {
|
||||
// Propose a std link to the object
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$sToolTipForHtml = utils::EscapeHtml(Dict::Format('Core:UnknownObjectLabel', $sClass, $sName));
|
||||
$sReplacement = "<span class=\"wiki_broken_link ibo-is-broken-hyperlink\" data-tooltip-content=\"$sToolTipForHtml\">$sClassLabel:$sName" . (!empty($sLabel) ? " ($sLabel)" : "") . "</span>";
|
||||
$sText = str_replace($aMatches[0], $sReplacement, $sText);
|
||||
// Later: propose a link to create a new object
|
||||
// Anyhow... there is no easy way to suggest default values based on the given FRIENDLY name
|
||||
//$sText = preg_replace('/\[\[(.+):(.+)\]\]/', '<a href="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&default[att1]=xxx&default[att2]=yyy">'.$sName.'</a>', $sText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($bFound === true) {
|
||||
// Propose a std link to the object
|
||||
$sHyperlinkLabel = (empty($sLabel)) ? $oObj->GetName() : $sLabel;
|
||||
$sText = str_replace($aMatches[0], $oObj->GetHyperlink(null, true, $sHyperlinkLabel), $sText);
|
||||
} else {
|
||||
// Propose a std link to the object
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$sToolTipForHtml = utils::EscapeHtml(Dict::Format('Core:UnknownObjectLabel', $sClass, $sName));
|
||||
$sReplacement = "<span class=\"wiki_broken_link ibo-is-broken-hyperlink\" data-tooltip-content=\"$sToolTipForHtml\">$sClassLabel:$sName".(!empty($sLabel) ? " ($sLabel)" : "")."</span>";
|
||||
$sText = str_replace($aMatches[0], $sReplacement, $sText);
|
||||
// Later: propose a link to create a new object
|
||||
// Anyhow... there is no easy way to suggest default values based on the given FRIENDLY name
|
||||
//$sText = preg_replace('/\[\[(.+):(.+)\]\]/', '<a href="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&default[att1]=xxx&default[att2]=yyy">'.$sName.'</a>', $sText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sText;
|
||||
}
|
||||
return $sText;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$aStyles = array();
|
||||
if ($this->GetWidth() != '') {
|
||||
$aStyles[] = 'width:' . $this->GetWidth();
|
||||
}
|
||||
if ($this->GetHeight() != '') {
|
||||
$aStyles[] = 'height:' . $this->GetHeight();
|
||||
}
|
||||
$sStyle = '';
|
||||
if (count($aStyles) > 0) {
|
||||
$sStyle = 'style="' . implode(';', $aStyles) . '"';
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$aStyles = array();
|
||||
if ($this->GetWidth() != '') {
|
||||
$aStyles[] = 'width:'.$this->GetWidth();
|
||||
}
|
||||
if ($this->GetHeight() != '') {
|
||||
$aStyles[] = 'height:'.$this->GetHeight();
|
||||
}
|
||||
$sStyle = '';
|
||||
if (count($aStyles) > 0) {
|
||||
$sStyle = 'style="'.implode(';', $aStyles).'"';
|
||||
}
|
||||
|
||||
if ($this->GetFormat() == 'text') {
|
||||
$sValue = parent::GetAsHTML($sValue, $oHostObject, $bLocalize);
|
||||
$sValue = self::RenderWikiHtml($sValue);
|
||||
$sValue = nl2br($sValue);
|
||||
if ($this->GetFormat() == 'text') {
|
||||
$sValue = parent::GetAsHTML($sValue, $oHostObject, $bLocalize);
|
||||
$sValue = self::RenderWikiHtml($sValue);
|
||||
$sValue = nl2br($sValue);
|
||||
|
||||
return "<div $sStyle>$sValue</div>";
|
||||
} else {
|
||||
$sValue = self::RenderWikiHtml($sValue, true /* wiki only */);
|
||||
return "<div $sStyle>$sValue</div>";
|
||||
} else {
|
||||
$sValue = self::RenderWikiHtml($sValue, true /* wiki only */);
|
||||
|
||||
return "<div class=\"HTML ibo-is-html-content\" $sStyle>" . InlineImage::FixUrls($sValue) . '</div>';
|
||||
}
|
||||
return "<div class=\"HTML ibo-is-html-content\" $sStyle>".InlineImage::FixUrls($sValue).'</div>';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
// N°4517 - PHP 8.1 compatibility: str_replace call with null cause deprecated message
|
||||
if ($sValue == null) {
|
||||
return '';
|
||||
}
|
||||
public function GetEditValue($sValue, $oHostObj = null)
|
||||
{
|
||||
// N°4517 - PHP 8.1 compatibility: str_replace call with null cause deprecated message
|
||||
if ($sValue == null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($this->GetFormat() == 'text') {
|
||||
if (preg_match_all(WIKI_OBJECT_REGEXP, $sValue, $aAllMatches, PREG_SET_ORDER)) {
|
||||
foreach ($aAllMatches as $iPos => $aMatches) {
|
||||
$sClass = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
if ($this->GetFormat() == 'text') {
|
||||
if (preg_match_all(WIKI_OBJECT_REGEXP, $sValue, $aAllMatches, PREG_SET_ORDER)) {
|
||||
foreach ($aAllMatches as $iPos => $aMatches) {
|
||||
$sClass = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
|
||||
if (MetaModel::IsValidClass($sClass)) {
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$sReplacement = "[[$sClassLabel:$sName" . (!empty($sLabel) ? " | $sLabel" : "") . "]]";
|
||||
$sValue = str_replace($aMatches[0], $sReplacement, $sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MetaModel::IsValidClass($sClass)) {
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$sReplacement = "[[$sClassLabel:$sName".(!empty($sLabel) ? " | $sLabel" : "")."]]";
|
||||
$sValue = str_replace($aMatches[0], $sReplacement, $sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* For fields containing a potential markup, return the value without this markup
|
||||
*
|
||||
* @param string $sValue
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetAsPlainText($sValue, $oHostObj = null)
|
||||
{
|
||||
if ($this->GetFormat() == 'html') {
|
||||
return (string)utils::HtmlToText($this->GetEditValue($sValue, $oHostObj));
|
||||
} else {
|
||||
return parent::GetAsPlainText($sValue, $oHostObj);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* For fields containing a potential markup, return the value without this markup
|
||||
*
|
||||
* @param string $sValue
|
||||
* @param DBObject $oHostObj
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetAsPlainText($sValue, $oHostObj = null)
|
||||
{
|
||||
if ($this->GetFormat() == 'html') {
|
||||
return (string)utils::HtmlToText($this->GetEditValue($sValue, $oHostObj));
|
||||
} else {
|
||||
return parent::GetAsPlainText($sValue, $oHostObj);
|
||||
}
|
||||
}
|
||||
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
$sValue = $proposedValue;
|
||||
public function MakeRealValue($proposedValue, $oHostObj)
|
||||
{
|
||||
$sValue = $proposedValue;
|
||||
|
||||
// N°4517 - PHP 8.1 compatibility: str_replace call with null cause deprecated message
|
||||
if ($sValue == null) {
|
||||
return '';
|
||||
}
|
||||
// N°4517 - PHP 8.1 compatibility: str_replace call with null cause deprecated message
|
||||
if ($sValue == null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
switch ($this->GetFormat()) {
|
||||
case 'html':
|
||||
if (($sValue !== null) && ($sValue !== '')) {
|
||||
$sValue = HTMLSanitizer::Sanitize($sValue);
|
||||
}
|
||||
break;
|
||||
switch ($this->GetFormat()) {
|
||||
case 'html':
|
||||
if (($sValue !== null) && ($sValue !== '')) {
|
||||
$sValue = HTMLSanitizer::Sanitize($sValue);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
default:
|
||||
if (preg_match_all(WIKI_OBJECT_REGEXP, $sValue, $aAllMatches, PREG_SET_ORDER)) {
|
||||
foreach ($aAllMatches as $iPos => $aMatches) {
|
||||
$sClassLabel = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
case 'text':
|
||||
default:
|
||||
if (preg_match_all(WIKI_OBJECT_REGEXP, $sValue, $aAllMatches, PREG_SET_ORDER)) {
|
||||
foreach ($aAllMatches as $iPos => $aMatches) {
|
||||
$sClassLabel = trim($aMatches[1]);
|
||||
$sName = trim($aMatches[2]);
|
||||
$sLabel = (!empty($aMatches[4])) ? trim($aMatches[4]) : null;
|
||||
|
||||
if (!MetaModel::IsValidClass($sClassLabel)) {
|
||||
$sClass = MetaModel::GetClassFromLabel($sClassLabel);
|
||||
if ($sClass) {
|
||||
$sReplacement = "[[$sClassLabel:$sName" . (!empty($sLabel) ? " | $sLabel" : "") . "]]";
|
||||
$sValue = str_replace($aMatches[0], $sReplacement, $sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!MetaModel::IsValidClass($sClassLabel)) {
|
||||
$sClass = MetaModel::GetClassFromLabel($sClassLabel);
|
||||
if ($sClass) {
|
||||
$sReplacement = "[[$sClassLabel:$sName".(!empty($sLabel) ? " | $sLabel" : "")."]]";
|
||||
$sValue = str_replace($aMatches[0], $sReplacement, $sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2xml($value);
|
||||
}
|
||||
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
return Str::pure2xml($value);
|
||||
}
|
||||
|
||||
public function GetWidth()
|
||||
{
|
||||
return $this->GetOptional('width', '');
|
||||
}
|
||||
public function GetWidth()
|
||||
{
|
||||
return $this->GetOptional('width', '');
|
||||
}
|
||||
|
||||
public function GetHeight()
|
||||
{
|
||||
return $this->GetOptional('height', '');
|
||||
}
|
||||
public function GetHeight()
|
||||
{
|
||||
return $this->GetOptional('height', '');
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\TextAreaField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\TextAreaField';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DBObject $oObject
|
||||
* @param \Combodo\iTop\Form\Field\TextAreaField $oFormField
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\TextAreaField
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
/** @var \Combodo\iTop\Form\Field\TextAreaField $oFormField */
|
||||
$oFormField = new $sFormFieldClass($this->GetCode(), null, $oObject);
|
||||
$oFormField->SetFormat($this->GetFormat());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
/**
|
||||
* @param DBObject $oObject
|
||||
* @param TextAreaField $oFormField
|
||||
*
|
||||
* @return TextAreaField
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
/** @var TextAreaField $oFormField */
|
||||
$oFormField = new $sFormFieldClass($this->GetCode(), null, $oObject);
|
||||
$oFormField->SetFormat($this->GetFormat());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual formatting of the field: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'text');
|
||||
}
|
||||
/**
|
||||
* The actual formatting of the field: either text (=plain text) or html (= text with HTML markup)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->GetOptional('format', 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the value from the row returned by the SQL query and transorms it to the appropriate
|
||||
* internal format (either text or html)
|
||||
*
|
||||
* @param array $aCols
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @return string
|
||||
* @see AttributeDBFieldVoid::FromSQLToValue()
|
||||
*
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$value = $aCols[$sPrefix . ''];
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Read from the extra column only if the property 'format' is specified for the attribute
|
||||
$sFormat = $aCols[$sPrefix . '_format'];
|
||||
} else {
|
||||
$sFormat = $this->GetFormat();
|
||||
}
|
||||
/**
|
||||
* Read the value from the row returned by the SQL query and transorms it to the appropriate
|
||||
* internal format (either text or html)
|
||||
*
|
||||
* @see AttributeDBFieldVoid::FromSQLToValue()
|
||||
*
|
||||
* @param string $sPrefix
|
||||
*
|
||||
* @param array $aCols
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||
{
|
||||
$value = $aCols[$sPrefix.''];
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Read from the extra column only if the property 'format' is specified for the attribute
|
||||
$sFormat = $aCols[$sPrefix.'_format'];
|
||||
} else {
|
||||
$sFormat = $this->GetFormat();
|
||||
}
|
||||
|
||||
switch ($sFormat) {
|
||||
case 'text':
|
||||
if ($this->GetFormat() == 'html') {
|
||||
$value = utils::TextToHtml($value);
|
||||
}
|
||||
break;
|
||||
switch ($sFormat) {
|
||||
case 'text':
|
||||
if ($this->GetFormat() == 'html') {
|
||||
$value = utils::TextToHtml($value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'html':
|
||||
if ($this->GetFormat() == 'text') {
|
||||
$value = utils::HtmlToText($value);
|
||||
} else {
|
||||
$value = InlineImage::FixUrls((string)$value);
|
||||
}
|
||||
break;
|
||||
case 'html':
|
||||
if ($this->GetFormat() == 'text') {
|
||||
$value = utils::HtmlToText($value);
|
||||
} else {
|
||||
$value = InlineImage::FixUrls((string)$value);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// unknown format ??
|
||||
}
|
||||
default:
|
||||
// unknown format ??
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$aValues = array();
|
||||
$aValues[$this->Get("sql")] = $this->ScalarToSQL($value);
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aValues[$this->Get("sql") . '_format'] = $this->GetFormat();
|
||||
}
|
||||
public function GetSQLValues($value)
|
||||
{
|
||||
$aValues = array();
|
||||
$aValues[$this->Get("sql")] = $this->ScalarToSQL($value);
|
||||
if ($this->GetOptional('format', null) != null) {
|
||||
// Add the extra column only if the property 'format' is specified for the attribute
|
||||
$aValues[$this->Get("sql").'_format'] = $this->GetFormat();
|
||||
}
|
||||
|
||||
return $aValues;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
switch ($this->GetFormat()) {
|
||||
case 'html':
|
||||
if ($bConvertToPlainText) {
|
||||
$sValue = utils::HtmlToText((string)$sValue);
|
||||
}
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier . $sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
public function GetAsCSV(
|
||||
$sValue, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true,
|
||||
$bConvertToPlainText = false
|
||||
)
|
||||
{
|
||||
switch ($this->GetFormat()) {
|
||||
case 'html':
|
||||
if ($bConvertToPlainText) {
|
||||
$sValue = utils::HtmlToText((string)$sValue);
|
||||
}
|
||||
$sFrom = array("\r\n", $sTextQualifier);
|
||||
$sTo = array("\n", $sTextQualifier.$sTextQualifier);
|
||||
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
|
||||
|
||||
return $sTextQualifier . $sEscaped . $sTextQualifier;
|
||||
break;
|
||||
return $sTextQualifier.$sEscaped.$sTextQualifier;
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
default:
|
||||
return parent::GetAsCSV($sValue, $sSeparator, $sTextQualifier, $oHostObject, $bLocalize,
|
||||
$bConvertToPlainText);
|
||||
}
|
||||
}
|
||||
case 'text':
|
||||
default:
|
||||
return parent::GetAsCSV($sValue, $sSeparator, $sTextQualifier, $oHostObject, $bLocalize,
|
||||
$bConvertToPlainText);
|
||||
}
|
||||
}
|
||||
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
/** @noinspection PhpConditionCheckedByNextConditionInspection */
|
||||
if (false === is_null($original) && ($original instanceof ormCaseLog)) {
|
||||
$original = $original->GetText();
|
||||
}
|
||||
$oMyChangeOp->Set("prevdata", $original);
|
||||
}
|
||||
protected function GetChangeRecordAdditionalData(CMDBChangeOp $oMyChangeOp, DBObject $oObject, $original, $value): void
|
||||
{
|
||||
/** @noinspection PhpConditionCheckedByNextConditionInspection */
|
||||
if (false === is_null($original) && ($original instanceof ormCaseLog)) {
|
||||
$original = $original->GetText();
|
||||
}
|
||||
$oMyChangeOp->Set("prevdata", $original);
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return ($this->GetFormat() === 'html')
|
||||
? CMDBChangeOpSetAttributeHTML::class
|
||||
: CMDBChangeOpSetAttributeText::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return ($this->GetFormat() === 'html')
|
||||
? CMDBChangeOpSetAttributeHTML::class
|
||||
: CMDBChangeOpSetAttributeText::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use CMDBChangeOpSetAttributeURL;
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\Form\Field\UrlField;
|
||||
use CoreException;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use Str;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Map a varchar column to an URL (formats the ouput in HMTL)
|
||||
@@ -7,104 +22,104 @@
|
||||
*/
|
||||
class AttributeURL extends AttributeString
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* SCHEME....... USER....................... PASSWORD.......................... HOST/IP........... PORT.......... PATH......................... GET............................................ ANCHOR..........................
|
||||
* Example: http://User:passWord@127.0.0.1:8888/patH/Page.php?arrayArgument[2]=something:blah20#myAnchor
|
||||
* @link http://www.php.net/manual/fr/function.preg-match.php#93824 regexp source
|
||||
* @since 3.0.1 N°4515 handle Alfresco and Sharepoint URLs
|
||||
* @since 3.0.3 moved from Config to AttributeURL constant
|
||||
*/
|
||||
public const DEFAULT_VALIDATION_PATTERN = /** @lang RegExp */
|
||||
'(https?|ftp)\://([a-zA-Z0-9+!*(),;?&=\$_.-]+(\:[a-zA-Z0-9+!*(),;?&=\$_.-]+)?@)?([a-zA-Z0-9-.]{3,})(\:[0-9]{2,5})?(/([a-zA-Z0-9:%+\$_-]\.?)+)*/?(\?[a-zA-Z+&\$_.-][a-zA-Z0-9;:[\]@&%=+/\$_.,-]*)?(#[a-zA-Z0-9_.-][a-zA-Z0-9+\$_.-]*)?';
|
||||
/**
|
||||
* @var string
|
||||
* SCHEME....... USER....................... PASSWORD.......................... HOST/IP........... PORT.......... PATH......................... GET............................................ ANCHOR..........................
|
||||
* Example: http://User:passWord@127.0.0.1:8888/patH/Page.php?arrayArgument[2]=something:blah20#myAnchor
|
||||
* @link http://www.php.net/manual/fr/function.preg-match.php#93824 regexp source
|
||||
* @since 3.0.1 N°4515 handle Alfresco and Sharepoint URLs
|
||||
* @since 3.0.3 moved from Config to AttributeURL constant
|
||||
*/
|
||||
public const DEFAULT_VALIDATION_PATTERN = /** @lang RegExp */
|
||||
'(https?|ftp)\://([a-zA-Z0-9+!*(),;?&=\$_.-]+(\:[a-zA-Z0-9+!*(),;?&=\$_.-]+)?@)?([a-zA-Z0-9-.]{3,})(\:[0-9]{2,5})?(/([a-zA-Z0-9:%@+\$_-]\.?)+)*/?(\?[a-zA-Z+&\$_.-][a-zA-Z0-9;:[\]@&%=+/\$_.,-]*)?(#[a-zA-Z0-9_.-][a-zA-Z0-9+\$_.-]*)?';
|
||||
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws \Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
/**
|
||||
* Useless constructor, but if not present PHP 7.4.0/7.4.1 is crashing :( (N°2329)
|
||||
*
|
||||
* @see https://www.php.net/manual/fr/language.oop5.decon.php states that child constructor can be ommited
|
||||
* @see https://bugs.php.net/bug.php?id=79010 bug solved in PHP 7.4.9
|
||||
*
|
||||
* @param string $sCode
|
||||
* @param array $aParams
|
||||
*
|
||||
* @throws Exception
|
||||
* @noinspection SenselessProxyMethodInspection
|
||||
*/
|
||||
public function __construct($sCode, $aParams)
|
||||
{
|
||||
parent::__construct($sCode, $aParams);
|
||||
}
|
||||
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
//return parent::ListExpectedParams();
|
||||
return array_merge(parent::ListExpectedParams(), array("target"));
|
||||
}
|
||||
public static function ListExpectedParams()
|
||||
{
|
||||
//return parent::ListExpectedParams();
|
||||
return array_merge(parent::ListExpectedParams(), array("target"));
|
||||
}
|
||||
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "VARCHAR(2048)"
|
||||
. CMDBSource::GetSqlStringColumnDefinition()
|
||||
. ($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
protected function GetSQLCol($bFullSpec = false)
|
||||
{
|
||||
return "VARCHAR(2048)"
|
||||
.CMDBSource::GetSqlStringColumnDefinition()
|
||||
.($bFullSpec ? $this->GetSQLColSpec() : '');
|
||||
}
|
||||
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
public function GetMaxSize()
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
public function GetEditClass()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sTarget = $this->Get("target");
|
||||
if (empty($sTarget)) {
|
||||
$sTarget = "_blank";
|
||||
}
|
||||
$sLabel = Str::pure2html($sValue);
|
||||
if (strlen($sLabel) > 128) {
|
||||
// Truncate the length to 128 characters, by removing the middle
|
||||
$sLabel = substr($sLabel, 0, 100) . '.....' . substr($sLabel, -20);
|
||||
}
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
$sTarget = $this->Get("target");
|
||||
if (empty($sTarget)) {
|
||||
$sTarget = "_blank";
|
||||
}
|
||||
$sLabel = Str::pure2html($sValue);
|
||||
if (strlen($sLabel) > 128) {
|
||||
// Truncate the length to 128 characters, by removing the middle
|
||||
$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);
|
||||
}
|
||||
|
||||
return "<a target=\"$sTarget\" href=\"$sValue\">$sLabel</a>";
|
||||
}
|
||||
return "<a target=\"$sTarget\" href=\"$sValue\">$sLabel</a>";
|
||||
}
|
||||
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return $this->GetOptional('validation_pattern', '^' . utils::GetConfig()->Get('url_validation_pattern') . '$');
|
||||
}
|
||||
public function GetValidationPattern()
|
||||
{
|
||||
return $this->GetOptional('validation_pattern', '^'.utils::GetConfig()->Get('url_validation_pattern').'$');
|
||||
}
|
||||
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\UrlField';
|
||||
}
|
||||
public static function GetFormFieldClass()
|
||||
{
|
||||
return '\\Combodo\\iTop\\Form\\Field\\UrlField';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DBObject $oObject
|
||||
* @param \Combodo\iTop\Form\Field\UrlField $oFormField
|
||||
*
|
||||
* @return null
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
/**
|
||||
* @param DBObject $oObject
|
||||
* @param UrlField $oFormField
|
||||
*
|
||||
* @return null
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function MakeFormField(DBObject $oObject, $oFormField = null)
|
||||
{
|
||||
if ($oFormField === null) {
|
||||
$sFormFieldClass = static::GetFormFieldClass();
|
||||
$oFormField = new $sFormFieldClass($this->GetCode());
|
||||
}
|
||||
parent::MakeFormField($oObject, $oFormField);
|
||||
|
||||
$oFormField->SetTarget($this->Get('target'));
|
||||
$oFormField->SetTarget($this->Get('target'));
|
||||
|
||||
return $oFormField;
|
||||
}
|
||||
return $oFormField;
|
||||
}
|
||||
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeURL::class;
|
||||
}
|
||||
protected function GetChangeRecordClassName(): string
|
||||
{
|
||||
return CMDBChangeOpSetAttributeURL::class;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* MissingColumnException - sent if an attribute is being created but the column is missing in the row
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Core\AttributeDefinition;
|
||||
|
||||
/**
|
||||
* Attributes implementing this interface won't be accepted as `group by` field
|
||||
@@ -7,5 +13,5 @@
|
||||
*/
|
||||
interface iAttributeNoGroupBy
|
||||
{
|
||||
//no method, just a contract on implement
|
||||
//no method, just a contract on implement
|
||||
}
|
||||
Reference in New Issue
Block a user