mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
N°2847 - ActivityPanel: Fix entry's author info for CMDBChangeOp
This commit is contained in:
@@ -25,6 +25,7 @@ use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry;
|
||||
use DateTime;
|
||||
use iCMDBChangeOp;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpFactory
|
||||
@@ -52,13 +53,42 @@ class CMDBChangeOpFactory
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date'));
|
||||
$sAuthorFriendlyname = $oChangeOp->Get('userinfo');
|
||||
$sContent = $oChangeOp->GetDescription();
|
||||
|
||||
$oEntry = new ActivityEntry($oDateTime, $sAuthorFriendlyname, $sContent);
|
||||
// Retrieve author login
|
||||
$sAuthorLogin = static::GetUserLoginFromChangeOp($oChangeOp);
|
||||
|
||||
$oEntry = new ActivityEntry($oDateTime, $sAuthorLogin, $sContent);
|
||||
$oEntry->SetType(static::DEFAULT_TYPE)
|
||||
->SetDecorationClasses(static::DEFAULT_DECORATION_CLASSES);
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the login of the $oChangeOp author or its friendlyname if the user cannot be retrieved.
|
||||
*
|
||||
* @param \iCMDBChangeOp $oChangeOp
|
||||
*
|
||||
* @return string|null
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public static function GetUserLoginFromChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$iAuthorId = $oChangeOp->Get('user_id');
|
||||
// - Set login in the friendlyname as a fallback
|
||||
$sAuthorLogin = $oChangeOp->Get('userinfo');
|
||||
// - Try to find user login from its ID if present (since iTop 2.8.0)
|
||||
if(empty($iAuthorId) === false)
|
||||
{
|
||||
$oAuthor = MetaModel::GetObject('User', $iAuthorId, false, true);
|
||||
if(empty($oAuthor) === false)
|
||||
{
|
||||
$sAuthorLogin = $oAuthor->Get('login');
|
||||
}
|
||||
}
|
||||
|
||||
return $sAuthorLogin;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBCha
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry;
|
||||
use DateTime;
|
||||
use iCMDBChangeOpSetAttribute;
|
||||
use iCMDBChangeOp;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpSetAttributeFactory
|
||||
@@ -33,25 +33,27 @@ use iCMDBChangeOpSetAttribute;
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpSetAttributeFactory
|
||||
class CMDBChangeOpSetAttributeFactory extends CMDBChangeOpFactory
|
||||
{
|
||||
/**
|
||||
* Make an EditsEntry from the iCMDBChangeOpSetAttribute $oChangeOp
|
||||
*
|
||||
* @param \iCMDBChangeOpSetAttribute $oChangeOp
|
||||
* @param \iCMDBChangeOp $oChangeOp
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry
|
||||
* @throws \OQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOpSetAttribute $oChangeOp)
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$sHostObjectClass = $oChangeOp->Get('objclass');
|
||||
$sAttCode = $oChangeOp->Get('attcode');
|
||||
$oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date'));
|
||||
$sAuthorFriendlyname = $oChangeOp->Get('userinfo');
|
||||
|
||||
$oEntry = new EditsEntry($oDateTime, $sAuthorFriendlyname, $sHostObjectClass);
|
||||
// Retrieve author login
|
||||
$sAuthorLogin = static::GetUserLoginFromChangeOp($oChangeOp);
|
||||
|
||||
$oEntry = new EditsEntry($oDateTime, $sAuthorLogin, $sHostObjectClass);
|
||||
$oEntry->AddAttribute($sAttCode, $oChangeOp->GetDescription());
|
||||
|
||||
return $oEntry;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBCha
|
||||
|
||||
|
||||
use AttributeDateTime;
|
||||
use iCMDBChangeOpSetAttribute;
|
||||
use iCMDBChangeOp;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\TransitionEntry;
|
||||
use DateTime;
|
||||
use MetaModel;
|
||||
@@ -39,7 +39,7 @@ class CMDBChangeOpSetAttributeScalarFactory extends CMDBChangeOpSetAttributeFact
|
||||
* @inheritDoc
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOpSetAttribute $oChangeOp)
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$sHostObjectClass = $oChangeOp->Get('objclass');
|
||||
$sAttCode = $oChangeOp->Get('attcode');
|
||||
@@ -48,12 +48,14 @@ class CMDBChangeOpSetAttributeScalarFactory extends CMDBChangeOpSetAttributeFact
|
||||
if($sAttCode === MetaModel::GetStateAttributeCode($sHostObjectClass))
|
||||
{
|
||||
$oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date'));
|
||||
$sAuthorFriendlyname = $oChangeOp->Get('userinfo');
|
||||
|
||||
// Retrieve author login
|
||||
$sAuthorLogin = static::GetUserLoginFromChangeOp($oChangeOp);
|
||||
|
||||
$sOriginStateLabel = MetaModel::GetStateLabel($sHostObjectClass, $oChangeOp->Get('oldvalue'));
|
||||
$sTargetStateLabel = MetaModel::GetStateLabel($sHostObjectClass, $oChangeOp->Get('newvalue'));
|
||||
|
||||
$oEntry = new TransitionEntry($oDateTime, $sAuthorFriendlyname, $sHostObjectClass, $sOriginStateLabel, $sTargetStateLabel);
|
||||
$oEntry = new TransitionEntry($oDateTime, $sAuthorLogin, $sHostObjectClass, $sOriginStateLabel, $sTargetStateLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user