Kernel::System::DynamicField::Value

NAME

Kernel::System::DynamicField::Value

DESCRIPTION

Dynamic field value database interface module.

Get()

Get a list of values for the given dynamic field and object.

    my $Records = $DynamicFieldValueDB->Get(
        FieldID  => '...', # required
        ObjectID => '...', # required
    );

Returns

    C<undef> - in case any error occurs
    []       - in case no data was found
    [
        {
            ID       => '...',
            FieldID  => '...',
            ObjectID => '...',
            Text     => '...',
            Date     => '...',
            Int      => '...',
            Double   => '...',
        },
        ...
    ]

List()

Get a list of values.

    my $Values = $DynamicFieldValueDB->List(
        Filters => {
            FieldID  => '...' # optional
            ObjectID => '...' # optional
            Text     => '...' # optional
            Int      => '...' # optional
            Double   => '...',# optional
            Date     => '...',# optional
        },
    );

Returns

    C<undef> - in case any error occurs
    []       - in case no data was found
    [
        {
            ID       => '...',
            FieldID  => '...',
            ObjectID => '...',
            Text     => '...',
            Date     => '...',
            Int      => '...',
            Double   => '...',
        },
        ...
    ]

History()

Get a list of the distinct values.

    my $History = $DynamicFieldValueDB->History(
        ValueColumn => '...' # required (Text, Date, Int or Double)
        Filters => {
            FieldID  => '...' # optional
            ObjectID => '...' # optional
        },
    );

Returns

    C<undef> - in case any error occurs
    []       - in case no data was found
    [
        {
            [Text|Date|Int|Double|] => '...',
        },
        ...
    ]

Delete()

Delete values from the database.

    # delete all values.
    my $Result = $DynamicFieldValueDB->Delete();

    # delete all values for the dynamic field.
    my $Result = $DynamicFieldValueDB->Delete(
        Filters => {
            FieldID => '...',
        },
    );

    # delete all dynamic field values for the object.
    my $Result = $DynamicFieldValueDB->Delete(
        Filters => {
            ObjectID => '...',
        },
    );

    # delete dynamic field value for the object.
    my $Result = $DynamicFieldValueDB->Delete(
        Filters => {
            FieldID  => '...',
            ObjectID => '...',
        },
    );

Returns

    1 - in case of success.
    C<undef> - in case any error occurs.

Create()

Creates/adds a new dynamic field / object value to the database.

    my $Result = $DynamicFieldValueDB->Create(
        FieldID  => '...',
        ObjectID => '...',
        Text     => '...',
        Date     => '...',
        Int      => '...',
        Double   => '...',
    );

Returns

    1 - in case of success.
    C<undef> - in case any error occurs.

ValueColumns()

Return a list of the possible value columns/parameters.

    my $List = $DynamicFieldValue->ValueColumns();

ValueDBColumn()

Given the parameter name, returns the proper database column name.

    my $DBColumnName = $DynamicFieldValueDB->ValueDBColumn(
        Name => '...' # Text, Date, Int or Double.
    );

CacheDelete()

Deletes the dynamic field values caches. It detects if the operation was only for a dynamic-field / object relation, dynamic-field or object, and deletes the affected keys, otherwise deletes everything.

    $DynamicFieldValueDB->CacheDelete(
        Filters => {...} # the filters passed to the delete operation.
    );

PRIVATE INTERFACE

_GetDBColumnMapForParams()

Get the mapping of params to database columns.

    # mapping for all params
    my $Map = $Self->_GetDBColumnMapForParams();

    # mapping only for the needed params
    my $Map = $Self->_GetDBColumnMapForParams(
        Want => [qw( FieldID ObjectID )],
    );

Returns

    a map/dictionary with the param and respective column name.

_FiltersSQLAndBinds()

Builds the SQL 'WHERE' clause and value binds based on the filters.

    # something like:
    my ($SQLWhere, $Binds) = $Self->_FiltersSQLAndBinds(
        Filters => {
            ObjectID => 999,
            Date     => '2018-02-18',
        },
    );
    # generates:
    $SQLWhere = (object_id = ?) AND (value_date = ?)
    $Binds    = [999, '2018-02-18']

    # it's possible to indicate which operator to use:
    my ($SQLWhere, $Binds) = $Self->_FiltersSQLAndBinds(
        Filters => {
            Date => { '>=' => '2018-02-18'},
        },
    );
    # generates:
    $SQLWhere = (value_date >= ?)
    $Binds    = ['2018-02-18']

Returns

    (string, arrayref)

_CacheType()

Returns the cache type.

_CacheGet()

Returns the cache data given the key.

    my $Cache = $DynamicFieldValue->_CacheGet( Key => 'SomeKey', );

_CacheSet()

Caches the given data.

    $DynamicFieldValue->_CacheSet(
        Key  => 'SomeKey',
        Data => {...},
    );
Scroll to Top