mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°962: TagSet - Attribute definition (continued)
SVN:b931[6032]
This commit is contained in:
committed by
Pierre Goiffon
parent
1953c05b33
commit
f458a77449
@@ -284,6 +284,11 @@ abstract class AttributeDefinition
|
||||
}
|
||||
|
||||
// table, key field, name field
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated never used
|
||||
*/
|
||||
public function ListDBJoins()
|
||||
{
|
||||
return "";
|
||||
@@ -710,7 +715,11 @@ abstract class AttributeDefinition
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
* @deprecated never used
|
||||
*/
|
||||
public function MakeValue()
|
||||
{
|
||||
$sComputeFunc = $this->Get("compute_func");
|
||||
@@ -5898,9 +5907,15 @@ class AttributeExternalField extends AttributeDefinition
|
||||
* @see TagSetFieldData
|
||||
* @since 2.6 N°931 tag fields
|
||||
*/
|
||||
class AttributeTagSet extends AttributeDBField
|
||||
class AttributeTagSet extends AttributeDBFieldVoid
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING;
|
||||
static public function ListExpectedParams()
|
||||
{
|
||||
return array_merge(parent::ListExpectedParams(), array("is_null_allowed"));
|
||||
}
|
||||
public function GetDefaultValue(DBObject $oHostObject = null) {return null;}
|
||||
public function IsNullAllowed() {return $this->Get("is_null_allowed");}
|
||||
|
||||
public function GetEditClass() {
|
||||
return "String";
|
||||
@@ -5968,6 +5983,24 @@ class AttributeTagSet extends AttributeDBField
|
||||
return $oTagSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// TODO $bLocalizedValue
|
||||
return $this->MakeRealValue($sProposedValue, null);
|
||||
}
|
||||
|
||||
public function GetNullValue() {
|
||||
return new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode());
|
||||
@@ -6023,7 +6056,7 @@ class AttributeTagSet extends AttributeDBField
|
||||
*/
|
||||
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (is_object($value) && ($value instanceof ormTagSet))
|
||||
if ($value instanceof ormTagSet)
|
||||
{
|
||||
if ($bLocalize)
|
||||
{
|
||||
@@ -6033,9 +6066,19 @@ class AttributeTagSet extends AttributeDBField
|
||||
{
|
||||
$aValues = $value->GetValue();
|
||||
}
|
||||
return implode(' ', $aValues);
|
||||
if (empty($aValues))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return '<span class="attribute-tagset">'.implode('</span><span class="attribute-tagset">', $aValues).'</span>';
|
||||
}
|
||||
return null;
|
||||
if (is_string($value))
|
||||
{
|
||||
$oValue = $this->MakeRealValue($value, $oHostObject);
|
||||
return $this->GetAsHTML($oValue, $oHostObject, $bLocalize);
|
||||
}
|
||||
return parent::GetAsHTML($value, $oHostObject, $bLocalize);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6094,7 +6137,7 @@ class AttributeTagSet extends AttributeDBField
|
||||
{
|
||||
$aValues = $value->GetValue();
|
||||
}
|
||||
$sRes = implode(' ', $aValues);
|
||||
$sRes = implode('|', $aValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -242,6 +242,64 @@ class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
|
||||
return $sResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the modification of a tag set attribute
|
||||
*
|
||||
* @package iTopORM
|
||||
*/
|
||||
class CMDBChangeOpSetAttributeTagSet extends CMDBChangeOpSetAttribute
|
||||
{
|
||||
public static function Init()
|
||||
{
|
||||
$aParams = array
|
||||
(
|
||||
"category" => "core/cmdb",
|
||||
"key_type" => "",
|
||||
"name_attcode" => "change",
|
||||
"state_attcode" => "",
|
||||
"reconc_keys" => array(),
|
||||
"db_table" => "priv_changeop_setatt_tagset",
|
||||
"db_key_field" => "id",
|
||||
"db_finalclass_field" => "",
|
||||
);
|
||||
MetaModel::Init_Params($aParams);
|
||||
MetaModel::Init_InheritAttributes();
|
||||
MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
|
||||
|
||||
// Display lists
|
||||
MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
|
||||
MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe (as a text string) the modifications corresponding to this change
|
||||
*/
|
||||
public function GetDescription()
|
||||
{
|
||||
$sResult = '';
|
||||
$sTargetObjectClass = $this->Get('objclass');
|
||||
$oTargetObjectKey = $this->Get('objkey');
|
||||
$sAttCode = $this->Get('attcode');
|
||||
$oTargetSearch = new DBObjectSearch($sTargetObjectClass);
|
||||
$oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
|
||||
|
||||
$oMonoObjectSet = new DBObjectSet($oTargetSearch);
|
||||
if (UserRights::IsActionAllowedOnAttribute($sTargetObjectClass, $sAttCode, UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
|
||||
{
|
||||
if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
|
||||
|
||||
$oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
|
||||
$sAttName = $oAttDef->GetLabel();
|
||||
$sNewValue = $this->Get('newvalue');
|
||||
$sOldValue = $this->Get('oldvalue');
|
||||
$sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue);
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the modification of an URL
|
||||
*
|
||||
|
||||
@@ -409,7 +409,19 @@ abstract class CMDBObject extends DBObject
|
||||
$oMyChangeOp->Set("newvalue", $value);
|
||||
$iId = $oMyChangeOp->DBInsertNoReload();
|
||||
}
|
||||
else
|
||||
elseif ($oAttDef instanceOf AttributeTagSet)
|
||||
{
|
||||
// Tag Set
|
||||
//
|
||||
$oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeTagSet");
|
||||
$oMyChangeOp->Set("objclass", get_class($this));
|
||||
$oMyChangeOp->Set("objkey", $this->GetKey());
|
||||
$oMyChangeOp->Set("attcode", $sAttCode);
|
||||
$oMyChangeOp->Set("oldvalue", implode(' ', $original->GetValue()));
|
||||
$oMyChangeOp->Set("newvalue", implode(' ', $value->GetValue()));
|
||||
$iId = $oMyChangeOp->DBInsertNoReload();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scalars
|
||||
//
|
||||
|
||||
@@ -188,11 +188,16 @@ EOF
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
|
||||
$sRet = $oAttDef->GetAsCSV($value, '', '', $oObj);
|
||||
}
|
||||
else if ($value instanceOf ormDocument)
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
|
||||
$sRet = $oAttDef->GetAsCSV($value, '', '', $oObj);
|
||||
}
|
||||
else if ($value instanceOf ormDocument)
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
|
||||
$sRet = $oAttDef->GetAsCSV($value, '', '', $oObj);
|
||||
}
|
||||
else if ($value instanceOf ormTagSet)
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
|
||||
$sRet = $oAttDef->GetAsCSV($value, '', '', $oObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
|
||||
|
||||
@@ -1024,7 +1024,7 @@ abstract class MetaModel
|
||||
/**
|
||||
* array of ("classname" => array of attributes)
|
||||
*
|
||||
* @var array
|
||||
* @var \AttributeDefinition[]
|
||||
*/
|
||||
private static $m_aAttribDefs = array();
|
||||
/**
|
||||
|
||||
@@ -83,12 +83,12 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
"allowed_values" => null,
|
||||
"sql" => "is_default",
|
||||
"default_value" => false,
|
||||
"is_null_allowed" => false,
|
||||
"is_null_allowed" => true,
|
||||
"depends_on" => array()
|
||||
)));
|
||||
|
||||
|
||||
MetaModel::Init_SetZListItems('details', array('tag_code', 'tag_label', 'tag_description', 'is_default'));
|
||||
MetaModel::Init_SetZListItems('details', array('tag_code', 'tag_label', 'tag_description', 'tag_class', 'tag_attcode'));
|
||||
MetaModel::Init_SetZListItems('standard_search', array('tag_code', 'tag_label', 'tag_description', 'is_default'));
|
||||
MetaModel::Init_SetZListItems('list', array('tag_code', 'tag_label', 'tag_description', 'is_default'));
|
||||
}
|
||||
|
||||
@@ -2862,3 +2862,11 @@ table.listResults .originColor {
|
||||
.menu-icon-select > .ui-menu-item {
|
||||
padding: 0.3em 3%;
|
||||
}
|
||||
.attribute-tagset {
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
background-color: grey;
|
||||
color: white;
|
||||
margin-right: 3px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
@@ -3259,4 +3259,13 @@ table.listResults .originColor{
|
||||
}
|
||||
.menu-icon-select > .ui-menu-item{
|
||||
padding: .3em 3%;
|
||||
}
|
||||
|
||||
.attribute-tagset{
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
background-color: grey;
|
||||
color: white;
|
||||
margin-right: 3px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
@@ -1395,7 +1395,6 @@ EOF
|
||||
$aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql');
|
||||
$aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
|
||||
$aParameters['depends_on'] = $sDependencies;
|
||||
$aParameters['default_value'] = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -273,6 +273,10 @@ class XMLDataLoader
|
||||
$oDoc = new ormDocument($data, $sMimeType, $sFileName);
|
||||
$oTargetObj->Set($sAttCode, $oDoc);
|
||||
}
|
||||
elseif ($oAttDef instanceof AttributeTagSet)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = (string)$oSubNode;
|
||||
|
||||
Reference in New Issue
Block a user