Sidebar

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

šŸ”™ Back

DBObject

abstract api overwritable-hook

A persistent object, as defined by the metamodel

Implements

\iDisplay

API synthesis

List of the public API methods. When manipulating DBObject, You can call those methods:

  • AddValue() ā€” Helper to add a value to the given attribute
  • ApplyStimulus() ā€” Apply a stimulus (workflow)
  • Copy() ā€” Helper to copy the value of an attribute to another oneSuitable for use as a lifecycle action
  • DBDelete() ā€” Delete an object
  • DBInsert() ā€” Persist an object to the DB, for the first time
  • DBUpdate() ā€” Update an object in DB
  • DBWrite() ā€” Make the current changes persistent - clever wrapper for Insert or Update
  • Get() ā€” Getter : get a value from the current object of from a related object
  • GetAsCSV() ā€” Get $sAttCode formatted as CSV
  • GetAsXML() ā€” Get $sAttCode formatted as XML
  • GetClassName() ā€” Get the label of a class
  • GetHyperlink() ā€” Return an hyperlink pointing to the current DBObject
  • GetIcon() ā€” Get the icon representing this object
  • GetKey() ā€” Primary key Getter
  • GetLabel() ā€” Get the label of an attribute.
  • GetState() ā€” Helper to get the state
  • GetStateDescription() ā€” Get the description of the state
  • GetStateLabel() ā€” Get the label (raw text) of the current statehelper for MetaModel::GetStateLabel()
  • IsArchived() ā€” Is the object archived
  • IsModified() ā€” Whether or not an object was modified since last read from the DB(ie: does it differ from the DB ?)
  • IsNew() ā€” Whether the object is already persisted in DB or not.
  • Reset() ā€” Helper to recover the default value (aka when an object is being created)Suitable for use as a lifecycle action
  • ResetStopWatch() ā€” Helper to reset a stop-watchSuitable for use as a lifecycle action
  • Set() ā€” Attributes setter
  • SetComputedDate() ā€” Helper to set a date computed from another date with extra logic
  • SetComputedDateIfNull() ā€” Helper to set a date computed from another date with extra logicCall SetComputedDate() only of the internal representation of the attribute is null.
  • SetCurrentDate() ā€” Helper to set the current date/time for the given attributeSuitable for use as a lifecycle action
  • SetCurrentDateIfNull() ā€” Helper to set a value only if it is currently undefined
  • SetCurrentPerson() ā€” Helper to set the current logged in CONTACT for the given attributeSuitable for use as a lifecycle action
  • SetCurrentUser() ā€” Helper to set the current logged in user for the given attributeSuitable for use as a lifecycle action
  • SetElapsedTime() ā€” Helper to set the time elapsed since a reference pointSuitable for use as a lifecycle action
  • SetIfNull() ā€” Helper to set a value only if it is currently undefined
  • SetTrim() ā€” Helper to set a value that fits the attribute max size

Advanced API synthesis

List of advanced API methods Beware they usage is recommended to advanced users only.

overwritable-hook synthesis

When inheriting from DBObject, you can overwrite those methods in order to add custom logic:

Public methods

AddValue

api public

Helper to add a value to the given attribute

Suitable for use as a lifecycle action

public AddValue($sAttCode, $iValue = 1)

Parameters

types name default description
string $sAttCode
integer|float $iValue 1

Returns

boolean

Throws

  • \CoreException
  • \CoreUnexpectedValue

Tags

since 3.0.0

ApplyStimulus

api public

Apply a stimulus (workflow)
public ApplyStimulus($sStimulusCode, $bDoNotWrite = false)

Parameters

types name default description
string $sStimulusCode
boolean $bDoNotWrite false if true we won't save the object !

Returns

boolean

Throws

  • \CoreException
  • \CoreUnexpectedValue

Uses

  • \AttributeStopWatch::Start : \AttributeStopWatch::Start
  • \AttributeStopWatch::Stop : \AttributeStopWatch::Stop
  • \DBObject::DBWrite : \DBObject::DBWrite
  • \TriggerOnStateLeave::DoActivate : \TriggerOnStateLeave::DoActivate
  • \TriggerOnStateEnter::DoActivate : \TriggerOnStateEnter::DoActivate

CheckConsistency

overwritable-hook public

check attributes together
public CheckConsistency()

Parameters

none

Returns

boolean

overwritable-hook

You can extend this method in order to provide your own logic.

CheckToWrite

api-advanced final public

final public CheckToWrite()

Parameters

none

Returns

array containing :

  • $m_bCheckStatus
  • $m_aCheckIssues
  • $m_bSecurityIssue

Throws

  • \ArchivedObjectException
  • \CoreException
  • \OQLException

See also

CheckValue

api-advanced public

Check if the given (or current) value is suitable for the attribute
public CheckValue($sAttCode, $value = null)

Parameters

types name default description
string $sAttCode
mixed $value null if not passed, then will get value using Get method

Returns

boolean|string true if successful, the error description otherwise

Throws

  • \ArchivedObjectException
  • \CoreException
  • \OQLException

Copy

api public

Helper to copy the value of an attribute to another oneSuitable for use as a lifecycle action
public Copy($sDestAttCode, $sSourceAttCode)

Parameters

types name default description
$sDestAttCode
$sSourceAttCode

DBDelete

api public

Delete an object

First, checks if the object can be deleted regarding database integrity. If the answer is yes, it performs any required cleanup (delete other objects or reset external keys) in addition to the object deletion.

public DBDelete($oDeletionPlan = null)

Parameters

types name default description
\DeletionPlan $oDeletionPlan null Do not use: aims at dealing with recursion

Returns

\DeletionPlan The detailed description of cleanup operation that have been performed

Throws

  • \ArchivedObjectException
  • \CoreCannotSaveObjectException
  • \CoreException
  • \CoreUnexpectedValue
  • \DeleteException
  • \MySQLException
  • \MySQLHasGoneAwayException
  • \OQLException

DBInsert

api public

Persist an object to the DB, for the first time
public DBInsert()

Parameters

none

Returns

integer|null inserted object key

Throws

  • \ArchivedObjectException
  • \CoreCannotSaveObjectException
  • \CoreException
  • \CoreUnexpectedValue
  • \CoreWarning
  • \MySQLException
  • \OQLException

See also

DBWrite

DBUpdate

api public

Update an object in DB
public DBUpdate()

Parameters

none

Returns

integer object key

Throws

  • \CoreException
  • \CoreCannotSaveObjectException if CheckToWrite() returns issues
  • \Exception

See also

DBObject::DBWrite()

DBWrite

api public

Make the current changes persistent - clever wrapper for Insert or Update
public DBWrite()

Parameters

none

Returns

integer

Throws

  • \CoreCannotSaveObjectException
  • \CoreException

DoCheckToWrite

overwritable-hook public

Check integrity rules (before inserting or updating the object)

This method is not meant to be called directly, use DBObject::CheckToWrite()! Errors should be inserted in $m_aCheckIssues and $m_aCheckWarnings arrays

public DoCheckToWrite()

Parameters

none

Throws

  • \ArchivedObjectException
  • \CoreException
  • \OQLException

See also

overwritable-hook

You can extend this method in order to provide your own logic.

Get

api public

Get the value of the attribute $sAttCode This call may involve an object reload if the object was not completely loaded (lazy loading)

public Get($sAttCode)

Parameters

types name default description
string $sAttCode Could be an extended attribute code in the form extkey_idā†’anotherkey_idā†’remote_attr

Returns

mixed|string

Throws

  • \ArchivedObjectException
  • \CoreException
  • \Exception

GetAsCSV

api public

Get $sAttCode formatted as CSV
public GetAsCSV($sAttCode, $sSeparator = ',', $sTextQualifier = '"', $bLocalize = true, $bConvertToPlainText = false)

Parameters

types name default description
string $sAttCode
string $sSeparator ','
string $sTextQualifier '"'
boolean $bLocalize true
boolean $bConvertToPlainText false

Returns

string

Throws

  • \ArchivedObjectException
  • \CoreException

GetAsHTML

api public

public GetAsHTML($sAttCode, $bLocalize = true)

Parameters

types name default description
string $sAttCode
boolean $bLocalize true

Returns

string $sAttCode formatted as HTML for the console details forms (when viewing, not when editing !) The returned string is already escaped, and as such is protected against XSS The markup relies on a few assumptions (CSS) that could change without notice

Throws

  • \ArchivedObjectException
  • \CoreException
  • \DictExceptionMissingString

See also

Combodo\iTop\Form\Field\Field : for rendering in portal forms

GetAsXML

api public

Get $sAttCode formatted as XML

The returned value is a text that is suitable for insertion into an XML node. Depending on the type of attribute, the returned text is either:

  • A literal, with XML entities already escaped,
  • XML
public GetAsXML($sAttCode, $bLocalize = true)

Parameters

types name default description
string $sAttCode
boolean $bLocalize true

Returns

mixed

Throws

  • \ArchivedObjectException
  • \CoreException

GetAttributeFlags

overwritable-hook public

Get the flags for the given state
public GetAttributeFlags($sAttCode, $aReasons = array(), $sTargetState = '')

Parameters

types name default description
string $sAttCode $sAttCode The code of the attribute
array $aReasons array() To store the reasons why the attribute is read-only (info about the synchro replicas)
string $sTargetState '' The target state in which to evalutate the flags, if empty the current state will be used

Returns

integer the binary combination of flags for the given attribute in the given state of the object. Values can be one of the OPT_ATT_HIDDEN, OPT_ATT_READONLY, OPT_ATT_MANDATORY, ... (see define in metamodel.class.php) Combine multiple values using the "|" operator, for example OPT_ATT_READONLY | OPT_ATT_HIDDEN.

Throws

\CoreException

See also

GetInitialStateAttributeFlags : for creation

overwritable-hook

You can extend this method in order to provide your own logic. If you do so, rely on the parent as a fallback if you have uncovered $sAttCode

GetClassName

api public static

Get the label of a class

Returns the label as defined in the dictionary for the language of the current user

public static GetClassName($sClass)

Parameters

types name default description
$sClass

Returns

string (empty for default name scheme)

api public

public GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true, $sLabel = null)

Parameters

types name default description
string $sUrlMakerClass null
boolean $bWithNavigationContext true
string $sLabel null

Returns

string

Throws

  • \ArchivedObjectException
  • \CoreException
  • \DictExceptionMissingString

GetIcon

api public

Get the icon representing this object
public GetIcon($bImgTag = true)

Parameters

types name default description
boolean $bImgTag true If true the result is a full IMG tag (or an empty string if no icon is defined)

Returns

string Either the full IMG tag ($bImgTag == true) or just the URL to the icon file

Throws

  • \ArchivedObjectException
  • \CoreException

GetInitialStateAttributeFlags

overwritable-hook public

public GetInitialStateAttributeFlags($sAttCode, $aReasons = array())

Parameters

types name default description
string $sAttCode The code of the attribute
array $aReasons array()

Returns

integer The binary combination of the flags for the given attribute for the current state of the object considered as an INITIAL state. Values can be one of the OPT_ATT_HIDDEN, OPT_ATT_READONLY, OPT_ATT_MANDATORY, ... (see define in metamodel.class.php)

Throws

\CoreException

See also

GetAttributeFlags : when modifying the object

overwritable-hook

You can extend this method in order to provide your own logic

GetKey

api public

Primary key Getter

Get the id

public GetKey()

Parameters

none

Returns

integer|null

GetLabel

api public

Get the label of an attribute.

Shortcut to the field's AttributeDefinition->GetLabel()

public GetLabel($sAttCode)

Parameters

types name default description
string $sAttCode

Returns

string

Throws

\Exception

GetState

api public

Helper to get the state
public GetState()

Parameters

none

Returns

mixed|string '' if no state attribute, object representing its value otherwise

Throws

\CoreException

GetStateDescription

api public

Get the description of the state
public GetStateDescription()

Parameters

none

Returns

mixed|string

Throws

  • \ArchivedObjectException
  • \CoreException

GetStateLabel

api public

Get the label (raw text) of the current statehelper for MetaModel::GetStateLabel()
public GetStateLabel()

Parameters

none

Returns

mixed|string

Throws

  • \ArchivedObjectException
  • \CoreException

IsArchived

api public

Is the object archived
public IsArchived($sKeyAttCode = null)

Parameters

types name default description
string|null $sKeyAttCode null

Returns

boolean

Throws

  • \ArchivedObjectException
  • \CoreException

IsModified

api public

Whether or not an object was modified since last read from the DB(ie: does it differ from the DB ?)
public IsModified()

Parameters

none

Returns

boolean

IsNew

api public

Whether the object is already persisted in DB or not.
public IsNew()

Parameters

none

Returns

boolean

ListChanges

api-advanced public

public ListChanges()

Parameters

none

Returns

array attname => currentvalue List the attributes that have been changed using {@see DBObject::Set()}. Reset during {@see DBObject::DBUpdate()}

Throws

\Exception

See also

Uses

\m_aCurrValues : \m_aCurrValues

ListPreviousValuesForUpdatedAttributes

api-advanced public

public ListPreviousValuesForUpdatedAttributes()

Parameters

none

Returns

array attname => value : value that was present before the last {@see DBObject::Set()} call. This array is set at the beginning of {@see DBObject::DBpdate()} using {@see DBObject::InitPreviousValuesForUpdatedAttributes()}.

See also

DBObject::ListChanges() : old method, but using data that are reset during DBObject::DBUpdate

Uses

\m_aPreviousValuesForUpdatedAttributes : \m_aPreviousValuesForUpdatedAttributes

api-advanced

To be used during the {@link \DBObject::DBUpdate()} call stack.

To get values that were set to the changed fields, simply use {@link \DBObject::Get()}

Tags

since 2.7.0 NĀ°2293

PrefillCreationForm

overwritable-hook public

Complete a new object with data from context
public PrefillCreationForm($aContextParam)

Parameters

types name default description
array $aContextParam Context used for creation form prefilling. Contains those keys : <ul> <li>string 'dest_class' <li>string 'origin' either console or portal <li>DBObject 'source_obj' fixed only when creating an external key object </ul>

See also

https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Aform_prefill : wiki tutorial

overwritable-hook

You can extend this method in order to provide your own logic.

Tags

since 2.5.0 NĀ°729

PrefillSearchForm

overwritable-hook public

Complete a filter data from context (Called on source object)
public PrefillSearchForm($aContextParam)

Parameters

types name default description
array $aContextParam Context used for creation form prefilling. Contains : <ul> <li>string 'dest_class' <li>DBObjectSearch 'filter' <li>string 'user' login string of the connected user <li>string 'origin' either 'console' or 'portal' </ul>

See also

https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Aform_prefill : wiki tutorial

overwritable-hook

You can extend this method in order to provide your own logic.

Tags

since 2.5.0 NĀ°729

PrefillTransitionForm

overwritable-hook public

Complete an object after a state transition with data from context
public PrefillTransitionForm($aContextParam)

Parameters

types name default description
array $aContextParam Context used for creation form prefilling. Contains those keys : <ul> <li>array 'expected_attributes' provides display flags on attributes in the form <li>string 'origin' either console or portal <li>string 'stimulus' provide the applied stimulus </ul>

See also

https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Aform_prefill : wiki tutorial

overwritable-hook

You can extend this method in order to provide your own logic.

Tags

since 2.5.0 NĀ°729

Reset

api public

Helper to recover the default value (aka when an object is being created)Suitable for use as a lifecycle action
public Reset($sAttCode)

Parameters

types name default description
$sAttCode

ResetStopWatch

api public

Helper to reset a stop-watchSuitable for use as a lifecycle action
public ResetStopWatch($sAttCode)

Parameters

types name default description
string $sAttCode

Returns

boolean

Throws

  • \ArchivedObjectException
  • \CoreException
  • \CoreUnexpectedValue

Set

api public

Attributes setter

Set $sAttCode to $value. The value must be valid according to the type of attribute. The value will not be recorded into the DB until DBObject::DBWrite() is called.

public Set($sAttCode, $value)

Parameters

types name default description
string $sAttCode
mixed $value

Returns

boolean

Throws

  • \CoreException
  • \CoreUnexpectedValue

See also

DBObject::DBWrite()

SetComputedDate

api public

Helper to set a date computed from another date with extra logic
public SetComputedDate($sAttCode, $sModifier = '', $sAttCodeSource = '')

Parameters

types name default description
string $sAttCode attribute code of a date or date-time which will be set
string $sModifier '' string specifying how to modify the date time
string $sAttCodeSource '' attribute code of a date or date-time used as source

Throws

  • \CoreException
  • \CoreUnexpectedValue

Tags

since 3.0.0

SetComputedDateIfNull

api public

Helper to set a date computed from another date with extra logicCall SetComputedDate() only of the internal representation of the attribute is null.
public SetComputedDateIfNull($sAttCode, $sModifier = '', $sAttCodeSource = '')

Parameters

types name default description
string $sAttCode attribute code which will be set
string $sModifier '' string specifying how to modify the date time
string $sAttCodeSource '' attribute code used as source

Throws

  • \CoreException
  • \CoreUnexpectedValue

See also

DBObject::SetComputedDate()

Tags

since 3.0.0

SetCurrentDate

api public

Helper to set the current date/time for the given attributeSuitable for use as a lifecycle action
public SetCurrentDate($sAttCode)

Parameters

types name default description
string $sAttCode

Returns

boolean

Throws

  • \CoreException
  • \CoreUnexpectedValue

SetCurrentDateIfNull

api public

Helper to set a value only if it is currently undefined

Call SetCurrentDate() only of the internal representation of the attribute is null.

public SetCurrentDateIfNull($sAttCode)

Parameters

types name default description
string $sAttCode

Throws

  • \CoreException
  • \CoreUnexpectedValue

See also

DBObject::SetCurrentDate()

Tags

since 3.0.0

SetCurrentPerson

api public

Helper to set the current logged in CONTACT for the given attributeSuitable for use as a lifecycle action
public SetCurrentPerson($sAttCode)

Parameters

types name default description
string $sAttCode

Returns

boolean

Throws

  • \ArchivedObjectException
  • \CoreException
  • \CoreUnexpectedValue

SetCurrentUser

api public

Helper to set the current logged in user for the given attributeSuitable for use as a lifecycle action
public SetCurrentUser($sAttCode)

Parameters

types name default description
string $sAttCode

Returns

boolean

Throws

  • \CoreException
  • \CoreUnexpectedValue

SetElapsedTime

api public

Helper to set the time elapsed since a reference pointSuitable for use as a lifecycle action
public SetElapsedTime($sAttCode, $sRefAttCode, $sWorkingTimeComputer = null)

Parameters

types name default description
string $sAttCode
string $sRefAttCode
string|null $sWorkingTimeComputer null

Returns

boolean

Throws

  • \ArchivedObjectException
  • \CoreException
  • \CoreUnexpectedValue

SetIfNull

api public

Helper to set a value only if it is currently undefined

Call Set() only of the internal representation of the attribute is null.

public SetIfNull($sAttCode, $value)

Parameters

types name default description
string $sAttCode
mixed $value

Throws

  • \CoreException
  • \CoreUnexpectedValue
  • \Exception

See also

DBObject::Set()

Tags

since 2.6.0

SetTrim

api public

Helper to set a value that fits the attribute max size

compare $sValue against the field's max size in the database, and truncate it's ending in order to make it fit. If $sValue is short enough, nothing is done.

public SetTrim($sAttCode, $sValue)

Parameters

types name default description
string $sAttCode
string $sValue

Throws

  • \CoreException
  • \CoreUnexpectedValue

Protected methods

AfterDelete

overwritable-hook protected

this method is called after the object is deleted into DB.
protected AfterDelete()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

AfterInsert

overwritable-hook protected

this method is called after the object is inserted into DB.
protected AfterInsert()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

AfterUpdate

overwritable-hook protected

protected AfterUpdate()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

This method is called after the object is updated into DB, and just before the {@see DBObject::Reload()} call.

Warning : do not use {@see DBObject::ListChanges()} as it will return an empty array ! Use instead {@see DBObject::ListPreviousValuesForUpdatedAttributes()} to get modified fields and their previous values, and {@see DBObject::Get()} to get the persisted value for a given attribute.

Tags

since 2.7.0 NĀ°2293 can access object changes by calling {@see DBObject::ListPreviousValuesForUpdatedAttributes()}

OnDelete

overwritable-hook protected

this method is called before the object is deleted into DB.
protected OnDelete()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

OnInsert

overwritable-hook protected

this method is called before the object is inserted into DB.
protected OnInsert()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

OnObjectKeyReady

overwritable-hook protected

Used only by insert, Meant to be overloaded
protected OnObjectKeyReady()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

OnUpdate

overwritable-hook protected

this method is called before the object is updated into DB.
protected OnUpdate()

Parameters

none

overwritable-hook

You can extend this method in order to provide your own logic.

šŸ”™ Back

latest/customization/api/objects-manipulation/dbobject.txt Ā· Last modified: 2024/09/10 10:25 by 127.0.0.1
Back to top
Contact us