
##########
LinkObject
##########


****
NAME
****


Kernel::System::LinkObject - to link objects like tickets, faq entries, ...


***********
DESCRIPTION
***********


All functions to link objects like tickets, faq entries, ...


****************
PUBLIC INTERFACE
****************


new()
=====


Don't use the constructor directly, use the ObjectManager instead:


.. code-block:: perl

     my $LinkObject = $Kernel::OM->Get('Kernel::System::LinkObject');



PossibleTypesList()
===================


return a hash of all possible types


.. code-block:: perl

     my %PossibleTypesList = $LinkObject->PossibleTypesList(
         Object1 => 'Ticket',
         Object2 => 'FAQ',
     );


Return:


.. code-block:: perl

     %PossibleTypesList = (
         'Normal'      => 1,
         'ParentChild' => 1,
     );



PossibleObjectsList()
=====================


return a hash of all possible objects


.. code-block:: perl

     my %PossibleObjectsList = $LinkObject->PossibleObjectsList(
         Object => 'Ticket',
     );


Return:


.. code-block:: perl

     %PossibleObjectsList = (
         'Ticket' => 1,
         'FAQ'    => 1,
     );



PossibleLinkList()
==================


return a 2 dimensional hash list of all possible links


.. code-block:: perl

     my %PossibleLinkList = $LinkObject->PossibleLinkList();


Return:


.. code-block:: perl

     %PossibleLinkList = (
         001 => {
             Object1 => 'Ticket',
             Object2 => 'Ticket',
             Type    => 'Normal',
         },
         002 => {
             Object1 => 'Ticket',
             Object2 => 'Ticket',
             Type    => 'ParentChild',
         },
     );



LinkAdd()
=========


add a new link between two elements


.. code-block:: perl

     $True = $LinkObject->LinkAdd(
         SourceObject => 'Ticket',
         SourceKey    => '321',
         TargetObject => 'FAQ',
         TargetKey    => '5',
         Type         => 'ParentChild',
         State        => 'Valid',
         UserID       => 1,
     );



LinkCleanup()
=============


deletes old links from database

return true


.. code-block:: perl

     $True = $LinkObject->LinkCleanup(
         State => 'Temporary',
         Age   => ( 60 * 60 * 24 ),
     );



LinkDelete()
============


deletes a link

return true


.. code-block:: perl

     $True = $LinkObject->LinkDelete(
         Object1 => 'Ticket',
         Key1    => '321',
         Object2 => 'FAQ',
         Key2    => '5',
         Type    => 'Normal',
         UserID  => 1,
     );



LinkDeleteAll()
===============


delete all links of an object


.. code-block:: perl

     $True = $LinkObject->LinkDeleteAll(
         Object => 'Ticket',
         Key    => '321',
         UserID => 1,
     );



LinkList()
==========


get all existing links for a given object


.. code-block:: perl

     my $LinkList = $LinkObject->LinkList(
         Object    => 'Ticket',
         Key       => '321',
         Object2   => 'FAQ',         # (optional)
         State     => 'Valid',
         Type      => 'ParentChild', # (optional)
         Direction => 'Target',      # (optional) default Both (Source|Target|Both)
         UserID    => 1,
     );


Return:


.. code-block:: perl

     $LinkList = {
         Ticket => {
             Normal => {
                 Source => {
                     12  => 1,
                     212 => 1,
                     332 => 1,
                 },
             },
             ParentChild => {
                 Source => {
                     5 => 1,
                     9 => 1,
                 },
                 Target => {
                     4  => 1,
                     8  => 1,
                     15 => 1,
                 },
             },
         },
         FAQ => {
             ParentChild => {
                 Source => {
                     5 => 1,
                 },
             },
         },
     };



LinkListWithData()
==================


get all existing links for a given object with data of the other objects


.. code-block:: perl

     my $LinkList = $LinkObject->LinkListWithData(
         Object           => 'Ticket',
         Key              => '321',
         Object2          => 'FAQ',         # (optional)
         State            => 'Valid',
         Type             => 'ParentChild', # (optional)
         Direction        => 'Target',      # (optional) default Both (Source|Target|Both)
         UserID           => 1,
         ObjectParameters => {              # (optional) backend specific flags
             Ticket => {
                 IgnoreLinkedTicketStateTypes => 0|1,
             },
         },
     );


Return:


.. code-block:: perl

     $LinkList = {
         Ticket => {
             Normal => {
                 Source => {
                     12  => $DataOfItem12,
                     212 => $DataOfItem212,
                     332 => $DataOfItem332,
                 },
             },
             ParentChild => {
                 Source => {
                     5 => $DataOfItem5,
                     9 => $DataOfItem9,
                 },
                 Target => {
                     4  => $DataOfItem4,
                     8  => $DataOfItem8,
                     15 => $DataOfItem15,
                 },
             },
         },
         FAQ => {
             ParentChild => {
                 Source => {
                     5 => $DataOfItem5,
                 },
             },
         },
     };



LinkKeyList()
=============


return a hash with all existing links of a given object


.. code-block:: perl

     my %LinkKeyList = $LinkObject->LinkKeyList(
         Object1   => 'Ticket',
         Key1      => '321',
         Object2   => 'FAQ',
         State     => 'Valid',
         Type      => 'ParentChild', # (optional)
         Direction => 'Target',      # (optional) default Both (Source|Target|Both)
         UserID    => 1,
     );


Return


.. code-block:: perl

     %LinkKeyList = (
         5   => 1,
         9   => 1,
         12  => 1,
         212 => 1,
         332 => 1,
     );



LinkKeyListWithData()
=====================


return a hash with all existing links of a given object


.. code-block:: perl

     my %LinkKeyList = $LinkObject->LinkKeyListWithData(
         Object1   => 'Ticket',
         Key1      => '321',
         Object2   => 'FAQ',
         State     => 'Valid',
         Type      => 'ParentChild', # (optional)
         Direction => 'Target',      # (optional) default Both (Source|Target|Both)
         UserID    => 1,
     );


Return:


.. code-block:: perl

     %LinkKeyList = (
         5   => $DataOfItem5,
         9   => $DataOfItem9,
         12  => $DataOfItem12,
         212 => $DataOfItem212,
         332 => $DataOfItem332,
     );



ObjectLookup()
==============


lookup a link object


.. code-block:: perl

     $ObjectID = $LinkObject->ObjectLookup(
         Name => 'Ticket',
     );
 
     or
 
     $Name = $LinkObject->ObjectLookup(
         ObjectID => 12,
     );



TypeLookup()
============


lookup a link type


.. code-block:: perl

     $TypeID = $LinkObject->TypeLookup(
         Name   => 'Normal',
         UserID => 1,
     );
 
     or
 
     $Name = $LinkObject->TypeLookup(
         TypeID => 56,
         UserID => 1,
     );



TypeGet()
=========


get a link type


.. code-block:: perl

     %TypeData = $LinkObject->TypeGet(
         TypeID => 444,
     );


Return:


.. code-block:: perl

     $TypeData{TypeID}
     $TypeData{Name}
     $TypeData{SourceName}
     $TypeData{TargetName}
     $TypeData{Pointed}
     $TypeData{CreateTime}
     $TypeData{CreateBy}
     $TypeData{ChangeTime}
     $TypeData{ChangeBy}



TypeList()
==========


return a 2 dimensional hash list of all valid link types


.. code-block:: perl

     my %TypeList = $LinkObject->TypeList();


Return:


.. code-block:: perl

     $TypeList{
         Normal => {
             SourceName => 'Normal',
             TargetName => 'Normal',
         },
         ParentChild => {
             SourceName => 'Parent',
             TargetName => 'Child',
         },
     }



TypeGroupList()
===============


return a 2 dimensional hash list of all type groups


.. code-block:: perl

     my %TypeGroupList = $LinkObject->TypeGroupList();


Return:


.. code-block:: perl

     %TypeGroupList = (
         001 => [
             'Normal',
             'ParentChild',
         ],
         002 => [
             'Normal',
             'DependsOn',
         ],
         003 => [
             'ParentChild',
             'RelevantTo',
         ],
     );



PossibleType()
==============


return true if both types are NOT together in a type group


.. code-block:: perl

     my $True = $LinkObject->PossibleType(
         Type1 => 'Normal',
         Type2 => 'ParentChild',
     );



StateLookup()
=============


lookup a link state


.. code-block:: perl

     $StateID = $LinkObject->StateLookup(
         Name => 'Valid',
     );
 
     or
 
     $Name = $LinkObject->StateLookup(
         StateID => 56,
     );



StateList()
===========


return a hash list of all valid link states


.. code-block:: perl

     my %StateList = $LinkObject->StateList(
         Valid => 0,   # (optional) default 1 (0|1)
     );


Return:


.. code-block:: perl

     $StateList{
         4 => 'Valid',
         8 => 'Temporary',
     }



ObjectPermission()
==================


checks read permission for a given object and UserID.


.. code-block:: perl

     $Permission = $LinkObject->ObjectPermission(
         Object => 'Ticket',
         Key    => 123,
         UserID => 1,
     );



ObjectDescriptionGet()
======================


return a hash of object descriptions


.. code-block:: perl

     %Description = $LinkObject->ObjectDescriptionGet(
         Object => 'Ticket',
         Key    => 123,
         UserID => 1,
     );


Return:


.. code-block:: perl

     %Description = (
         Normal => '',
         Long   => '',
     );



ObjectSearch()
==============


return a hash reference of the search results.


.. code-block:: perl

     $ObjectList = $LinkObject->ObjectSearch(
         Object       => 'ITSMConfigItem',
         SubObject    => 'Computer',        # (optional)
         SearchParams => $HashRef,          # (optional)
         UserID       => 1,
     );


Returns:


.. code-block:: perl

     $ObjectList = {
         Ticket => {
             NOTLINKED => {
                 Source => {
                     12  => $DataOfItem12,
                     212 => $DataOfItem212,
                     332 => $DataOfItem332,
                 },
             },
         },
     };





